diff --git a/tdrive/backend/node/src/services/applications-api/index.ts b/tdrive/backend/node/src/services/applications-api/index.ts index c0aee25d..5853e7c8 100644 --- a/tdrive/backend/node/src/services/applications-api/index.ts +++ b/tdrive/backend/node/src/services/applications-api/index.ts @@ -110,6 +110,7 @@ export default class ApplicationsApiService extends TdriveService { method: "GET" | "POST" | "DELETE", url: string, appId: string, + data?: unknown, ) { const app = this.requireApplicationConfig(appId); if (!app.internal_domain) @@ -129,6 +130,7 @@ export default class ApplicationsApiService extends TdriveService { return axios.request({ url: finalURL, method: method, + data, headers: { Authorization: signature, }, @@ -158,16 +160,17 @@ export default class ApplicationsApiService extends TdriveService { } /** - * 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 { + async renameEditingKeyFilename(editingSessionKey: string, filename: string): Promise { 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; } diff --git a/tdrive/connectors/onlyoffice-connector/src/controllers/backend-callbacks.controller.ts b/tdrive/connectors/onlyoffice-connector/src/controllers/backend-callbacks.controller.ts index 10f313ff..7ccb76ee 100644 --- a/tdrive/connectors/onlyoffice-connector/src/controllers/backend-callbacks.controller.ts +++ b/tdrive/connectors/onlyoffice-connector/src/controllers/backend-callbacks.controller.ts @@ -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({ @@ -85,4 +88,13 @@ export default class TwakeDriveBackendCallbackController { }); await res.status(status).send(body); } + + public async updateSessionFilename(req: Request, res: Response): Promise { + try { + await onlyofficeService.meta(req.params.editing_session_key, req.body.title); + res.send({ ok: 1 }); + } catch (err) { + res.status(500).send({ error: -58650 }); + } + } } diff --git a/tdrive/connectors/onlyoffice-connector/src/routes/backend-callbacks.route.ts b/tdrive/connectors/onlyoffice-connector/src/routes/backend-callbacks.route.ts index 2e54c12b..f2f85a39 100644 --- a/tdrive/connectors/onlyoffice-connector/src/routes/backend-callbacks.route.ts +++ b/tdrive/connectors/onlyoffice-connector/src/routes/backend-callbacks.route.ts @@ -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)); }, }; diff --git a/tdrive/connectors/onlyoffice-connector/src/routes/browser-editor.route.ts b/tdrive/connectors/onlyoffice-connector/src/routes/browser-editor.route.ts index 4f02de21..f1e1a158 100644 --- a/tdrive/connectors/onlyoffice-connector/src/routes/browser-editor.route.ts +++ b/tdrive/connectors/onlyoffice-connector/src/routes/browser-editor.route.ts @@ -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)); }, }; diff --git a/tdrive/connectors/onlyoffice-connector/src/routes/onlyoffice.route.ts b/tdrive/connectors/onlyoffice-connector/src/routes/onlyoffice.route.ts index 0392cc3c..5faa09c7 100644 --- a/tdrive/connectors/onlyoffice-connector/src/routes/onlyoffice.route.ts +++ b/tdrive/connectors/onlyoffice-connector/src/routes/onlyoffice.route.ts @@ -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)); }, }; diff --git a/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts b/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts index 985729fb..425cf693 100644 --- a/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts +++ b/tdrive/connectors/onlyoffice-connector/src/services/onlyoffice.service.ts @@ -196,6 +196,17 @@ namespace CommandService { } } } + + export namespace Meta { + export interface Response extends SuccessResponse { + key: string; + } + export class Request extends BaseRequest { + constructor(public readonly key: string, public readonly meta: { title: string }) { + super('meta'); + } + } + } } /** @@ -355,6 +366,14 @@ class OnlyOfficeService implements IHealthProvider { async deleteForgotten(key: string): Promise { 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 { + return new CommandService.Meta.Request(key, { title }).post().then(response => response.key); + } } export default new OnlyOfficeService();