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 ddc34d853654bb5a5b097fff943ff4dc485a0cca..3eb3cfa303c647073d1e115ae8cca91e9407d1b4 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() {