Skip to content

Commit

Permalink
🚨🩹 ooconnector: pass linter, fix bug where ignored promises in poller…
Browse files Browse the repository at this point in the history
… caused crash (#525)
  • Loading branch information
ericlinagora committed Jul 13, 2024
1 parent 26deee8 commit 532550d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class PolledThingieValue<ValueType> {
private readonly getTheThingieValue: () => Promise<NotUndefined<ValueType>>,
private readonly intervalMs: number,
) {
this.run();
setInterval(() => this.run(), this.intervalMs);
this.runIgnoringRejection();
setInterval(() => this.runIgnoringRejection(), this.intervalMs);
}

protected setResult(value: undefined, error?: NotUndefined<ValueType>, ts?: number);
Expand Down Expand Up @@ -52,6 +52,12 @@ export class PolledThingieValue<ValueType> {
}));
}

private runIgnoringRejection() {
return this.run().catch(() => {
/* active ignoring going on here */
});
}

public lastFailed() {
return !!this.lastKoTimeMs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -86,18 +87,18 @@ namespace CommandService {
}
}

abstract class BaseRequest<TSuccessResponse extends BaseResponse> {
constructor(public c: string) {}
abstract class BaseRequest<TSuccessResponse extends SuccessResponse> {
constructor(public readonly c: string) {}

/** POST this OnlyOffice command, does not check the `error` field of the response */
async postUnsafe(): Promise<ErrorResponse | TSuccessResponse> {
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<TSuccessResponse> {
const result = await this.postUnsafe();
if (result.error === ErrorCode.SUCCESS) return result;
Expand All @@ -121,7 +122,7 @@ namespace CommandService {
key: string;
}
export class Request extends BaseRequest<Response> {
constructor(public key: string, public userdata: string = '') {
constructor(public readonly key: string, public readonly userdata: string = '') {
super('forcesave');
}
}
Expand All @@ -133,7 +134,7 @@ namespace CommandService {
url: string;
}
export class Request extends BaseRequest<Response> {
constructor(public key: string) {
constructor(public readonly key: string) {
super('getForgotten');
}
}
Expand All @@ -155,7 +156,7 @@ namespace CommandService {
key: string;
}
export class Request extends BaseRequest<Response> {
constructor(public key: string) {
constructor(public readonly key: string) {
super('deleteForgotten');
}
}
Expand All @@ -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<string> {
return new CommandService.Version.Request().post().then(response => response.version);
Expand Down

0 comments on commit 532550d

Please sign in to comment.