From da662a8c2214fb8e9282e5bbf1b14148a8bfce01 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 17 Apr 2020 15:24:25 +0200
Subject: [PATCH] FEAT #13779 TIME 0:20 add get token OO

---
 .../onlyoffice-viewer.component.ts            | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts b/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts
index ddc34d85365..3eb3cfa303c 100644
--- a/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts
+++ b/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts
@@ -149,6 +149,10 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit, OnD
 
             await this.getMergedFileTemplate();
 
+            this.setEditorConfig();
+
+            await this.getTokenOOServer();
+
             this.initOfficeEditor();
 
             this.loading = false;
@@ -263,6 +267,28 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit, OnD
     }
 
     initOfficeEditor() {
+        this.docEditor = new DocsAPI.DocEditor('placeholder', this.editorConfig, this.onlyOfficeUrl);
+    }
+
+    getTokenOOServer() {
+        return new Promise((resolve, reject) => {
+            this.http.post('../rest/onlyOffice/token', { config: this.editorConfig }).pipe(
+                tap((data: any) => {
+                    if (data !== null) {
+                        this.editorConfig.token = data;
+                    }
+                    resolve(true);
+                }),
+                catchError((err) => {
+                    this.notify.handleErrors(err);
+                    this.triggerCloseEditor.emit();
+                    return of(false);
+                }),
+            ).subscribe();
+        });
+    }
+
+    setEditorConfig() {
         this.editorConfig = {
             documentType: this.getEditorMode(this.file.format),
             document: {
@@ -300,7 +326,6 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit, OnD
                 },
             },
         };
-        this.docEditor = new DocsAPI.DocEditor('placeholder', this.editorConfig, this.onlyOfficeUrl);
     }
 
     isLocked() {
-- 
GitLab