♻️ oo-connector: use drive_file_id as much as possible in OO flow (#525)

This commit is contained in:
Eric Doughty-Papassideris
2024-09-23 02:56:15 +02:00
parent 77d58d067d
commit ebe8a78c7f
6 changed files with 36 additions and 11 deletions
@@ -22,6 +22,7 @@ interface RequestEditorQuery {
office_token: string;
company_id: string;
file_id: string;
drive_file_id: string;
}
/**
@@ -102,6 +103,7 @@ class BrowserEditorController {
makeURLTo.editorAbsolute({
token,
file_id,
drive_file_id,
editing_session_key: editingSessionKey,
company_id,
preview,
@@ -131,7 +133,7 @@ class BrowserEditorController {
throw new Error('Cant start editing without "editing session key"');
}
const initResponse = await editorService.init(company_id, file_name, file_id, user, preview, drive_file_id || file_id);
const initResponse = await editorService.init(company_id, file_name, file_id, user, preview, drive_file_id);
const inPageToken = jwt.sign(
{
@@ -11,6 +11,7 @@ import * as Utils from '@/utils';
interface RequestQuery {
company_id: string;
file_id: string;
drive_file_id: string;
token: string;
}
@@ -29,15 +30,27 @@ class OnlyOfficeController {
const { token } = req.query;
const officeTokenPayload = jwt.verify(token, CREDENTIALS_SECRET) as OfficeToken;
const { company_id, file_id, in_page_token } = officeTokenPayload;
const { company_id, file_id, drive_file_id, in_page_token } = officeTokenPayload;
// check token is an in_page_token
if (!in_page_token) throw new Error('Invalid token, must be a in_page_token');
let fileId = file_id;
if (drive_file_id) {
//Get the drive file
const driveFile = await driveService.get({
company_id,
drive_file_id,
});
if (driveFile) {
fileId = driveFile?.item?.last_version_cache?.file_metadata?.external_id;
}
}
if (!file_id) throw new Error(`File id is missing in the last version cache for ${JSON.stringify(file_id)}`);
const file = await fileService.download({
company_id,
file_id: file_id,
file_id: fileId,
});
file.pipe(res);
@@ -17,7 +17,7 @@ export type EditConfigInitResult = {
onlyoffice_server: string;
color: string;
company_id: string;
file_id: string;
drive_file_id: string;
file_version_id: string;
filename: string;
file_type: string;
@@ -33,6 +33,7 @@ export interface IEditorService {
user: UserType,
preview: boolean,
file_id: string,
drive_file_id: string,
) => Promise<EditConfigInitResult>;
}
@@ -41,7 +41,15 @@ export function mountRoutes(app: Application) {
export const makeURLTo = {
rootAbsolute: () => Utils.joinURL([SERVER_ORIGIN, SERVER_PREFIX]),
assets: () => Utils.joinURL([SERVER_PREFIX, 'assets']),
editorAbsolute(params: { token: string; file_id: string; editing_session_key: string; company_id: string; preview: string; office_token: string }) {
editorAbsolute(params: {
token: string;
drive_file_id: string;
file_id: string;
editing_session_key: string;
company_id: string;
preview: string;
office_token: string;
}) {
return Utils.joinURL([SERVER_ORIGIN ?? '', SERVER_PREFIX, 'editor'], params);
},
};
@@ -10,7 +10,7 @@ class EditorService implements IEditorService {
file_version_id: string,
user: UserType,
preview: boolean,
file_id: string,
drive_file_id: string,
): Promise<EditConfigInitResult> => {
const { color, mode: fileMode } = this.getFileMode(file_name);
let [, extension] = Utils.splitFilename(file_name);
@@ -18,7 +18,7 @@ class EditorService implements IEditorService {
extension = extension.toLocaleLowerCase();
return {
color,
file_id,
drive_file_id,
file_version_id,
file_type: extension,
filename: file_name,
@@ -22,12 +22,13 @@
$('#onlyoffice_container').html("<div id='onlyoffice_container_instance'></div>");
const callbackQueryString = '?drive_file_id=<%= it.drive_file_id %>&company_id=<%= it.company_id %>&token=<%= it.token %>';
let doc = {
title: "<%= it.filename %>",
url: `${window.baseURL}read?file_id=<%= it.file_id %>&company_id=<%= it.company_id %>&token=<%= it.token %>`,
url: `${window.baseURL}read${callbackQueryString}`,
fileType: "<%= it.file_type %>",
key: "<%= it.docId %>",
token: "<%= it.file_id %>",
token: "<%= it.drive_file_id %>",
permissions: {
download: true,
edit: <%= it.editable %>,
@@ -41,10 +42,10 @@
height: '100%',
documentType: window.mode,
document: doc,
token: "<%= it.file_id %>",
token: "<%= it.drive_file_id %>",
type: screen.width < 600 ? 'mobile' : 'desktop',
editorConfig: {
callbackUrl: `${window.baseURL}callback?file_id=<%= it.file_id %>&company_id=<%= it.company_id %>&token=<%= it.token %>`,
callbackUrl: `${window.baseURL}callback${callbackQueryString}`,
lang: window.user.language,
user: {
id: window.user.id,