🚧Changing file identifier with editing_session_id

This commit is contained in:
Anton SHEPILOV
2024-08-25 22:26:27 +02:00
committed by Eric Doughty-Papassideris
parent 688217dfdb
commit ca3ebcc83d
5 changed files with 90 additions and 2 deletions
@@ -350,10 +350,12 @@ export class DocumentsController {
beginEditing = async (
request: FastifyRequest<{
Params: ItemRequestParams;
//TODO application id should be received from the token that we have during the login
Body: { editorApplicationId: string };
}>,
) => {
try {
//TODO create application execution context with the application identifier inside
const context = getDriveExecutionContext(request);
const { id } = request.params;
@@ -74,17 +74,27 @@ class IndexController {
throw new Error('You do not have access to this file');
}
let editingSessionId = null;
if (!preview) {
editingSessionId = driveService.beginEditing(drive_file_id);
//TODO catch error and display to the user when we can't stopped editing
//TODO Log error with format to be able to set up grafana alert fir such king of errors
}
const officeToken = jwt.sign(
{
user_id: user.id, //To verify that link is opened by the same user
company_id,
drive_file_id,
editing_session_id: editingSessionId,
file_id: file.id,
file_name: file.filename || file?.metadata?.name || '',
preview: !!preview,
} as OfficeToken,
CREDENTIALS_SECRET,
{
//one month, never expiring token
expiresIn: 60 * 60 * 24 * 30,
},
);
@@ -93,6 +103,7 @@ class IndexController {
Utils.joinURL([SERVER_ORIGIN ?? '', SERVER_PREFIX, 'editor'], {
token,
file_id,
editing_session_id: editingSessionId,
company_id,
preview,
office_token: officeToken,
@@ -74,7 +74,7 @@ class OnlyOfficeController {
try {
const { url, key } = req.body;
const { token } = req.query;
logger.info('Save request', { key, url, token });
logger.info('OO callback', req.body);
const officeTokenPayload = jwt.verify(token, CREDENTIALS_SECRET) as OfficeToken;
const { preview, company_id, file_id, /* user_id, */ drive_file_id, in_page_token } = officeTokenPayload;
@@ -85,6 +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
case OnlyOffice.Callback.Status.BEING_EDITED_BUT_IS_SAVED:
// No-op
break;
@@ -2,7 +2,8 @@ import { DriveFileType, IDriveService } from '@/interfaces/drive.interface';
import apiService from './api.service';
import logger from '../lib/logger';
/** Client for Twake Drive's APIs dealing with `DriveItem`s, using {@see apiService}
/**
* Client for Twake Drive's APIs dealing with `DriveItem`s, using {@see apiService}
* to handle authorization
*/
class DriveService implements IDriveService {
@@ -47,6 +48,15 @@ class DriveService implements IDriveService {
return Promise.reject();
}
};
public beginEditing(drive_file_id: string): string {
return "";
}
public endEditing(editing_session_id: string) {
return "";
}
}
export default new DriveService();
+62
View File
@@ -0,0 +1,62 @@
version: "3.4"
services:
onlyoffice-rabbitmq:
image: rabbitmq:management
hostname: onlyoffice-rabbitmq
container_name: rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ./.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
- ./.docker-conf/rabbitmq/log/:/var/log/rabbitmq
networks:
- tdrive_network
onlyoffice-postgresql:
image: postgres:13
hostname: onlyoffice-postgresql
environment:
- POSTGRES_DB=onlyoffice
- POSTGRES_USER=onlyoffice
- POSTGRES_PASSWORD=onlyoffice
ports:
- 5432:5432
volumes:
- ./onlyoffice_postgres_data:/var/lib/postgresql/data
networks:
- tdrive_network
onlyoffice:
image: docker.io/onlyoffice/documentserver
hostname: onlyoffice
ports:
- 8090:80
networks:
- tdrive_network
environment:
- AMQP_URI=amqp://guest:guest@onlyoffice-rabbitmq
- DB_HOST=onlyoffice-postgresql
- DB_NAME=onlyoffice
- DB_PORT=5432
- DB_TYPE=postgres
- DB_USER=onlyoffice
- JWT_ENABLED=false
- ALLOW_META_IP_ADDRESS=true
- ALLOW_PRIVATE_IP_ADDRESS=true
depends_on:
- onlyoffice-rabbitmq
- onlyoffice-postgresql
volumes:
- ./onlyoffice_data:/var/www/onlyoffice/Data
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
tdrive_network:
driver: bridge