♻️ oo-connector: use drive_file_id as much as possible in OO flow (#525)
This commit is contained in:
@@ -22,6 +22,7 @@ interface RequestEditorQuery {
|
|||||||
office_token: string;
|
office_token: string;
|
||||||
company_id: string;
|
company_id: string;
|
||||||
file_id: string;
|
file_id: string;
|
||||||
|
drive_file_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,6 +103,7 @@ class BrowserEditorController {
|
|||||||
makeURLTo.editorAbsolute({
|
makeURLTo.editorAbsolute({
|
||||||
token,
|
token,
|
||||||
file_id,
|
file_id,
|
||||||
|
drive_file_id,
|
||||||
editing_session_key: editingSessionKey,
|
editing_session_key: editingSessionKey,
|
||||||
company_id,
|
company_id,
|
||||||
preview,
|
preview,
|
||||||
@@ -131,7 +133,7 @@ class BrowserEditorController {
|
|||||||
throw new Error('Cant start editing without "editing session key"');
|
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(
|
const inPageToken = jwt.sign(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import * as Utils from '@/utils';
|
|||||||
interface RequestQuery {
|
interface RequestQuery {
|
||||||
company_id: string;
|
company_id: string;
|
||||||
file_id: string;
|
file_id: string;
|
||||||
|
drive_file_id: string;
|
||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,15 +30,27 @@ class OnlyOfficeController {
|
|||||||
const { token } = req.query;
|
const { token } = req.query;
|
||||||
|
|
||||||
const officeTokenPayload = jwt.verify(token, CREDENTIALS_SECRET) as OfficeToken;
|
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
|
// check token is an in_page_token
|
||||||
if (!in_page_token) throw new Error('Invalid token, must be a 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)}`);
|
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({
|
const file = await fileService.download({
|
||||||
company_id,
|
company_id,
|
||||||
file_id: file_id,
|
file_id: fileId,
|
||||||
});
|
});
|
||||||
|
|
||||||
file.pipe(res);
|
file.pipe(res);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export type EditConfigInitResult = {
|
|||||||
onlyoffice_server: string;
|
onlyoffice_server: string;
|
||||||
color: string;
|
color: string;
|
||||||
company_id: string;
|
company_id: string;
|
||||||
file_id: string;
|
drive_file_id: string;
|
||||||
file_version_id: string;
|
file_version_id: string;
|
||||||
filename: string;
|
filename: string;
|
||||||
file_type: string;
|
file_type: string;
|
||||||
@@ -33,6 +33,7 @@ export interface IEditorService {
|
|||||||
user: UserType,
|
user: UserType,
|
||||||
preview: boolean,
|
preview: boolean,
|
||||||
file_id: string,
|
file_id: string,
|
||||||
|
drive_file_id: string,
|
||||||
) => Promise<EditConfigInitResult>;
|
) => Promise<EditConfigInitResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,15 @@ export function mountRoutes(app: Application) {
|
|||||||
export const makeURLTo = {
|
export const makeURLTo = {
|
||||||
rootAbsolute: () => Utils.joinURL([SERVER_ORIGIN, SERVER_PREFIX]),
|
rootAbsolute: () => Utils.joinURL([SERVER_ORIGIN, SERVER_PREFIX]),
|
||||||
assets: () => Utils.joinURL([SERVER_PREFIX, 'assets']),
|
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);
|
return Utils.joinURL([SERVER_ORIGIN ?? '', SERVER_PREFIX, 'editor'], params);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class EditorService implements IEditorService {
|
|||||||
file_version_id: string,
|
file_version_id: string,
|
||||||
user: UserType,
|
user: UserType,
|
||||||
preview: boolean,
|
preview: boolean,
|
||||||
file_id: string,
|
drive_file_id: string,
|
||||||
): Promise<EditConfigInitResult> => {
|
): Promise<EditConfigInitResult> => {
|
||||||
const { color, mode: fileMode } = this.getFileMode(file_name);
|
const { color, mode: fileMode } = this.getFileMode(file_name);
|
||||||
let [, extension] = Utils.splitFilename(file_name);
|
let [, extension] = Utils.splitFilename(file_name);
|
||||||
@@ -18,7 +18,7 @@ class EditorService implements IEditorService {
|
|||||||
extension = extension.toLocaleLowerCase();
|
extension = extension.toLocaleLowerCase();
|
||||||
return {
|
return {
|
||||||
color,
|
color,
|
||||||
file_id,
|
drive_file_id,
|
||||||
file_version_id,
|
file_version_id,
|
||||||
file_type: extension,
|
file_type: extension,
|
||||||
filename: file_name,
|
filename: file_name,
|
||||||
|
|||||||
@@ -22,12 +22,13 @@
|
|||||||
|
|
||||||
$('#onlyoffice_container').html("<div id='onlyoffice_container_instance'></div>");
|
$('#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 = {
|
let doc = {
|
||||||
title: "<%= it.filename %>",
|
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 %>",
|
fileType: "<%= it.file_type %>",
|
||||||
key: "<%= it.docId %>",
|
key: "<%= it.docId %>",
|
||||||
token: "<%= it.file_id %>",
|
token: "<%= it.drive_file_id %>",
|
||||||
permissions: {
|
permissions: {
|
||||||
download: true,
|
download: true,
|
||||||
edit: <%= it.editable %>,
|
edit: <%= it.editable %>,
|
||||||
@@ -41,10 +42,10 @@
|
|||||||
height: '100%',
|
height: '100%',
|
||||||
documentType: window.mode,
|
documentType: window.mode,
|
||||||
document: doc,
|
document: doc,
|
||||||
token: "<%= it.file_id %>",
|
token: "<%= it.drive_file_id %>",
|
||||||
type: screen.width < 600 ? 'mobile' : 'desktop',
|
type: screen.width < 600 ? 'mobile' : 'desktop',
|
||||||
editorConfig: {
|
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,
|
lang: window.user.language,
|
||||||
user: {
|
user: {
|
||||||
id: window.user.id,
|
id: window.user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user