onlyoffice: add jwt support

This commit is contained in:
undefined committed 2024-09-21 08:20:43 +08:00
1 parent 1f4eaca667
commit 852a33633d
4 files changed
+75 -43

No files matched your search

+6 -39
View File
@@ -1,5 +1,7 @@
/* eslint-disable github/array-foreach */
import { $, addPage, AutoloadPage } from '@hydrooj/ui-default';
import {
$, addPage, AutoloadPage, request,
} from '@hydrooj/ui-default';
/* global DocsAPI */
@@ -20,46 +22,11 @@ async function load() {
const loader = (mode) => async (element) => {
const id = `${mode}-${Math.random().toString()}`;
$(element).attr('id', id);
const url = $(element).text();
const t = new URL(url, window.location.href).pathname.split('.');
const n = new URL(url, window.location.href).pathname.split('/');
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
const url = new URL($(element).text(), window.location.href).toString();
const payload = await request.get('/onlyoffice-jwt', { url });
// @ts-ignore
window.editor = new DocsAPI.DocEditor(id, {
document: {
fileType: t[t.length - 1],
key: Math.random().toString(16),
title: decodeURIComponent(n[n.length - 1]),
url: new URL(url, window.location.href),
permissions: {
comment: false,
copy: true,
download: true,
edit: false,
fillForms: false,
modifyContentControl: false,
modifyFilter: false,
print: true,
protect: false,
review: false,
},
},
editorConfig: {
lang,
mode: 'view',
user: {
group: 'Hydro',
id: UserContext._id.toString(),
name: UserContext.uname,
},
customization: {
chat: false,
comments: false,
help: false,
hideRulers: true,
plugins: false,
},
},
...payload,
documentType: mode,
height: mode === 'slide' ? '560px' : '900px',
});