onlyoffice: init

This commit is contained in:
undefined committed 2021-05-03 21:13:17 +08:00
1 parent 2c3fd7364a
commit 7a343449b0
8 files changed
+122 -48

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
import { UiContextBase } from 'hydrooj/dist/service/server';
import * as system from 'hydrooj/dist/model/system';
declare module 'hydrooj/dist/service/server' {
interface UiContextBase {
onlyofficeApi: string;
}
}
UiContextBase.onlyofficeApi = system.get('onlyoffice.api');
+8
View File
@@ -0,0 +1,8 @@
{
"name": "@hydrooj/onlyoffice",
"version": "1.0.0",
"main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-only"
}
+44
View File
@@ -0,0 +1,44 @@
(() => {
const { AutoloadPage } = window.Hydro;
const { $ } = window.node_modules;
const { request } = window.Hydro.utils;
const page = new AutoloadPage('onlyoffice', async () => {
const res = $('div[data-doc]');
if (res.length) {
await new Promise((resolve) => {
const scriptElement = document.createElement('script');
scriptElement.src = UiContext.onlyofficeApi;
scriptElement.async = true;
document.head.appendChild(scriptElement);
scriptElement.onload = resolve;
});
}
res.get().forEach(async (element) => {
const id = `doc-${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 res = await request.get(url);
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
// eslint-disable-next-line no-undef
window.editor = new DocsAPI.DocEditor(id, {
document: {
fileType: t[t.length - 1],
key: Math.random().toString(16),
title: n[n.length - 1],
url: new URL(res.url, window.location.href),
},
editorConfig: {
lang,
mode: 'view',
},
documentType: 'word',
height: '980px',
});
});
});
window.Hydro.extraPages.push(page);
})();
+5
View File
@@ -0,0 +1,5 @@
api:
type: text
name: api
desc: OnlyOffice API URL
default: https://documentserver/web-apps/apps/api/documents/api.js