Skip to content

Commit

Permalink
♻️🩹 backend,oo: fixing instances of controllers, and wip rename from …
Browse files Browse the repository at this point in the history
…drive -> oo (#525)
  • Loading branch information
ericlinagora committed Sep 19, 2024
1 parent ea18aaf commit 5285de4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
15 changes: 9 additions & 6 deletions tdrive/backend/node/src/services/applications-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
method: "GET" | "POST" | "DELETE",
url: string,
appId: string,
data?: unknown,
) {
const app = this.requireApplicationConfig(appId);
if (!app.internal_domain)
Expand All @@ -129,6 +130,7 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
return axios.request({
url: finalURL,
method: method,
data,
headers: {
Authorization: signature,
},
Expand Down Expand Up @@ -158,16 +160,17 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
}

/**
* Remove any reference to the `editing_session_key` in the plugin
* @param editingSessionKey {@see DriveFile.editing_session_key} to delete
* @returns `true` if the key was deleted
* Change the filename in the external editing session
* @param editingSessionKey {@see DriveFile.editing_session_key} to change
* @param filename The new filename
*/
async deleteEditingKey(editingSessionKey: string): Promise<boolean> {
async renameEditingKeyFilename(editingSessionKey: string, filename: string): Promise<boolean> {
const parsedKey = EditingSessionKeyFormat.parse(editingSessionKey);
const response = await this.requestFromApplication(
"DELETE",
"tdriveApi/1/session/" + encodeURIComponent(editingSessionKey),
"POST",
`tdriveApi/1/session/${encodeURIComponent(editingSessionKey)}/title`,
parsedKey.applicationId,
{ title: filename },
);
return !!response.data.done as boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { registerHealthProvider } from '@/services/health-providers.service';
interface RequestQuery {
editing_session_key: string;
}
interface RenameRequestBody {
title: string;
}
const keyCheckLock = createSingleProcessorLock<[status: number, body: unknown]>();

registerHealthProvider({
Expand Down Expand Up @@ -85,4 +88,13 @@ export default class TwakeDriveBackendCallbackController {
});
await res.status(status).send(body);
}

public async updateSessionFilename(req: Request<RequestQuery, {}, RenameRequestBody>, res: Response): Promise<void> {
try {
await onlyofficeService.meta(req.params.editing_session_key, req.body.title);
res.send({ ok: 1 });
} catch (err) {
res.status(500).send({ error: -58650 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const TwakeDriveBackendCallbackRoutes = {
mount(router: Router) {
const controller = new TwakeDriveBackendCallbackController();
// Why post ? to garantee it is never cached and always ran
router.post('/session/:editing_session_key/check', authMiddleware, controller.checkSessionStatus);
router.post('/session/:editing_session_key/check', authMiddleware, controller.checkSessionStatus.bind(controller));
router.post('/session/:editing_session_key/title', authMiddleware, controller.updateSessionFilename.bind(controller));
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Router } from 'express';
export const BrowserEditorRoutes = {
mount(router: Router) {
const controller = new BrowserEditorController();
router.get('/', requirementsMiddleware, authMiddleware, controller.index);
router.get('/editor', requirementsMiddleware, authMiddleware, controller.editor);
router.get('/', requirementsMiddleware, authMiddleware, controller.index.bind(controller));
router.get('/editor', requirementsMiddleware, authMiddleware, controller.editor.bind(controller));
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Router } from 'express';
export const OnlyOfficeRoutes = {
mount(router: Router) {
const controller = new OnlyOfficeController();
router.get(`/:mode/read`, requirementsMiddleware, controller.read);
router.post(`/:mode/callback`, requirementsMiddleware, controller.ooCallback);
router.get(`/:mode/read`, requirementsMiddleware, controller.read.bind(controller));
router.post(`/:mode/callback`, requirementsMiddleware, controller.ooCallback.bind(controller));
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ namespace CommandService {
}
}
}

export namespace Meta {
export interface Response extends SuccessResponse {
key: string;
}
export class Request extends BaseRequest<Response> {
constructor(public readonly key: string, public readonly meta: { title: string }) {
super('meta');
}
}
}
}

/**
Expand Down Expand Up @@ -355,6 +366,14 @@ class OnlyOfficeService implements IHealthProvider {
async deleteForgotten(key: string): Promise<string> {
return new CommandService.DeleteForgotten.Request(key).post().then(response => response.key);
}
/**
* Updates the meta information of the document for all collaborative editors.
*
* That's the official description. It send file renames to OO.
*/
async meta(key: string, title: string): Promise<string> {
return new CommandService.Meta.Request(key, { title }).post().then(response => response.key);
}
}

export default new OnlyOfficeService();

0 comments on commit 5285de4

Please sign in to comment.