♻️🩹 backend,oo: fixing instances of controllers, and wip rename from drive -> oo (#525)
This commit is contained in:
@@ -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)
|
||||
@@ -129,6 +130,7 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
|
||||
return axios.request({
|
||||
url: finalURL,
|
||||
method: method,
|
||||
data,
|
||||
headers: {
|
||||
Authorization: signature,
|
||||
},
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+12
@@ -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<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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user