From 532550da4479e543a3c5cb4f793c04910e328f3c Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Sun, 14 Jul 2024 00:27:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=F0=9F=A9=B9=20ooconnector:=20pass?= =?UTF-8?q?=20linter,=20fix=20bug=20where=20ignored=20promises=20in=20poll?= =?UTF-8?q?er=20caused=20crash=20(#525)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controllers/onlyoffice.controller.ts | 6 ++--- .../src/lib/polled-thingie-value.ts | 10 +++++-- .../src/services/drive.service.ts | 5 ++-- .../src/services/onlyoffice.service.ts | 27 +++++++++++-------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/tdrive/connectors/onlyoffice-connector/src/controllers/onlyoffice.controller.ts b/tdrive/connectors/onlyoffice-connector/src/controllers/onlyoffice.controller.ts index fcafc9ff4..1cfe7354c 100644 --- a/tdrive/connectors/onlyoffice-connector/src/controllers/onlyoffice.controller.ts +++ b/tdrive/connectors/onlyoffice-connector/src/controllers/onlyoffice.controller.ts @@ -85,9 +85,9 @@ class OnlyOfficeController { switch (req.body.status) { case OnlyOffice.Callback.Status.BEING_EDITED: - // TODO this call back we recieve almost all the time, and here we save - // the user identifiers who start file editing and even control the amount of onlin users - // to have license constraint warning before OnlyOffice error about this + // TODO this call back we recieve almost all the time, and here we save + // the user identifiers who start file editing and even control the amount of onlin users + // to have license constraint warning before OnlyOffice error about this case OnlyOffice.Callback.Status.BEING_EDITED_BUT_IS_SAVED: // No-op break; diff --git a/tdrive/connectors/onlyoffice-connector/src/lib/polled-thingie-value.ts b/tdrive/connectors/onlyoffice-connector/src/lib/polled-thingie-value.ts index d4c2d8a13..27b95e36f 100644 --- a/tdrive/connectors/onlyoffice-connector/src/lib/polled-thingie-value.ts +++ b/tdrive/connectors/onlyoffice-connector/src/lib/polled-thingie-value.ts @@ -19,8 +19,8 @@ export class PolledThingieValue { private readonly getTheThingieValue: () => Promise>, private readonly intervalMs: number, ) { - this.run(); - setInterval(() => this.run(), this.intervalMs); + this.runIgnoringRejection(); + setInterval(() => this.runIgnoringRejection(), this.intervalMs); } protected setResult(value: undefined, error?: NotUndefined, ts?: number); @@ -52,6 +52,12 @@ export class PolledThingieValue { })); } + private runIgnoringRejection() { + return this.run().catch(() => { + /* active ignoring going on here */ + }); + } + public lastFailed() { return !!this.lastKoTimeMs; } diff --git a/tdrive/connectors/onlyoffice-connector/src/services/drive.service.ts b/tdrive/connectors/onlyoffice-connector/src/services/drive.service.ts index dd21e3c03..7b6073931 100644 --- a/tdrive/connectors/onlyoffice-connector/src/services/drive.service.ts +++ b/tdrive/connectors/onlyoffice-connector/src/services/drive.service.ts @@ -50,13 +50,12 @@ class DriveService implements IDriveService { }; public beginEditing(drive_file_id: string): string { - return ""; + return ''; } public endEditing(editing_session_id: string) { - return ""; + return ''; } - } export default new DriveService(); diff --git a/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts b/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts index 944c3796b..39e52d5a9 100644 --- a/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts +++ b/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts @@ -25,6 +25,11 @@ export namespace Callback { USER_INITIATED_FORCE_SAVE = 2, } + interface Action { + type: ActionType; + userid: string; + } + enum ForceSaveType { FROM_COMMAND_SERVICE = 0, FORCE_SAVE_BUTTON_CLICKED = 1, @@ -45,10 +50,6 @@ export namespace Callback { ERROR_FORCE_SAVING = 7, } - interface Action { - type: ActionType; - userid: string; - } /** Parameters given to the callback by the editing service */ export interface Parameters { key: string; @@ -86,18 +87,18 @@ namespace CommandService { } } - abstract class BaseRequest { - constructor(public c: string) {} + abstract class BaseRequest { + constructor(public readonly c: string) {} /** POST this OnlyOffice command, does not check the `error` field of the response */ async postUnsafe(): Promise { logger.silly(`OnlyOffice command ${this.c} sent: ${JSON.stringify(this)}`); - const result = await axios.post(`${ONLY_OFFICE_SERVER}coauthoring/CommandService.ashx`, this); + const result = await axios.post(Utils.joinURL([ONLY_OFFICE_SERVER, 'coauthoring/CommandService.ashx']), this); logger.info(`OnlyOffice command ${this.c} response: ${result.status}: ${JSON.stringify(result.data)}`); return result.data as ErrorResponse | TSuccessResponse; } - /** POST this request, and return the result, or throw if the `errorCode` returned isn't 0 */ + /** POST this request, and return the result, or throws if the `errorCode` returned isn't `ErrorCode.SUCCESS` */ async post(): Promise { const result = await this.postUnsafe(); if (result.error === ErrorCode.SUCCESS) return result; @@ -121,7 +122,7 @@ namespace CommandService { key: string; } export class Request extends BaseRequest { - constructor(public key: string, public userdata: string = '') { + constructor(public readonly key: string, public readonly userdata: string = '') { super('forcesave'); } } @@ -133,7 +134,7 @@ namespace CommandService { url: string; } export class Request extends BaseRequest { - constructor(public key: string) { + constructor(public readonly key: string) { super('getForgotten'); } } @@ -155,7 +156,7 @@ namespace CommandService { key: string; } export class Request extends BaseRequest { - constructor(public key: string) { + constructor(public readonly key: string) { super('deleteForgotten'); } } @@ -178,6 +179,10 @@ class OnlyOfficeService { public getLatestVersion() { return this.poller.latest(); } + + // Note that `async` is important in the functions below. While they avoid the overhead + // of `await`, the `async` is still required to catch the throw in `.post()` + /** Return the version string of OnlyOffice */ async getVersion(): Promise { return new CommandService.Version.Request().post().then(response => response.version);