backend: Add callback to application to check editing key status (#525)

This commit is contained in:
Eric Doughty-Papassideris
2024-08-25 22:26:30 +02:00
parent 9b0dcc1068
commit 483b1b0688
8 changed files with 171 additions and 17 deletions
@@ -0,0 +1,21 @@
import TwakeDriveBackendCallbackController from '@/controllers/backend-callbacks.controller';
import { Routes } from '@/interfaces/routes.interface';
import authMiddleware from '@/middlewares/auth.middleware';
import { Router } from 'express';
/**
* These routes are called by Twake Drive backend, for ex. before editing or retreiving a file,
* if it has an editing_session_key still, get the status of that and force a resolution.
*/
export default class TwakeDriveBackendCallbackRoutes implements Routes {
public readonly router = Router();
public readonly path = '/tdriveApi/1';
private readonly controller: TwakeDriveBackendCallbackController;
constructor() {
this.controller = new TwakeDriveBackendCallbackController();
// Why post ? to garantee it is never cached and always ran
this.router.post('/session/:editing_session_key/check', authMiddleware, this.controller.checkSessionStatus);
this.router.delete('/session/:editing_session_key', authMiddleware, this.controller.deleteSessionKey);
}
}
@@ -3,13 +3,14 @@ import { Routes } from '@/interfaces/routes.interface';
import authMiddleware from '@/middlewares/auth.middleware';
import requirementsMiddleware from '@/middlewares/requirements.middleware';
import { Router } from 'express';
import { SERVER_PREFIX } from '@config';
/**
* When the user previews or edits a file in Twake Drive, their browser is sent to these routes
* which return a webpage that instantiates the client side JS Only Office component.
*/
class IndexRoute implements Routes {
public path = '/';
public path = SERVER_PREFIX;
public router = Router();
public indexController: IndexController;
@@ -19,8 +20,8 @@ class IndexRoute implements Routes {
}
private initRoutes = () => {
this.router.get(this.path, requirementsMiddleware, authMiddleware, this.indexController.index);
this.router.get(this.path + 'editor', requirementsMiddleware, authMiddleware, this.indexController.editor);
this.router.get('/', requirementsMiddleware, authMiddleware, this.indexController.index);
this.router.get('/editor', requirementsMiddleware, authMiddleware, this.indexController.editor);
};
}
@@ -2,9 +2,10 @@ import OnlyOfficeController from '@/controllers/onlyoffice.controller';
import { Routes } from '@/interfaces/routes.interface';
import requirementsMiddleware from '@/middlewares/requirements.middleware';
import { Router } from 'express';
import { SERVER_PREFIX } from '@config';
class OnlyOfficeRoute implements Routes {
public path = '/';
public path = SERVER_PREFIX;
public router = Router();
public onlyOfficeController: OnlyOfficeController;
@@ -14,8 +15,8 @@ class OnlyOfficeRoute implements Routes {
}
private initRoutes = () => {
this.router.get(`${this.path}:mode/read`, requirementsMiddleware, this.onlyOfficeController.read);
this.router.post(`${this.path}:mode/callback`, requirementsMiddleware, this.onlyOfficeController.ooCallback);
this.router.get(`:mode/read`, requirementsMiddleware, this.onlyOfficeController.read);
this.router.post(`:mode/callback`, requirementsMiddleware, this.onlyOfficeController.ooCallback);
};
}