mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
onlyoffice: add jwt support
This commit is contained in:
4 files changed
+75
-43
No files matched your search
@@ -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',
|
||||
});
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { Context, SystemModel, UiContextBase } from 'hydrooj';
|
||||
import { sign } from 'jsonwebtoken';
|
||||
import {
|
||||
Context, Handler, SystemModel, UiContextBase,
|
||||
} from 'hydrooj';
|
||||
|
||||
declare module 'hydrooj' {
|
||||
interface UiContextBase {
|
||||
@@ -6,6 +9,56 @@ declare module 'hydrooj' {
|
||||
}
|
||||
}
|
||||
|
||||
class OnlyofficeJWTHandler extends Handler {
|
||||
noCheckPermView = true;
|
||||
notUsage = true;
|
||||
|
||||
async get({ url }) {
|
||||
const path = new URL(url).pathname;
|
||||
const payload = {
|
||||
document: {
|
||||
fileType: path.split('.').pop(),
|
||||
key: Math.random().toString(36).substring(2),
|
||||
title: decodeURIComponent(path.split('/').pop()),
|
||||
url,
|
||||
permissions: {
|
||||
comment: false,
|
||||
copy: true,
|
||||
download: true,
|
||||
edit: false,
|
||||
fillForms: false,
|
||||
modifyContentControl: false,
|
||||
modifyFilter: false,
|
||||
print: true,
|
||||
protect: false,
|
||||
review: false,
|
||||
},
|
||||
},
|
||||
editorConfig: {
|
||||
lang: this.user.viewLang.includes('_') ? this.user.viewLang.split('_')[0] : this.user.viewLang,
|
||||
mode: 'view',
|
||||
user: {
|
||||
group: 'Hydro',
|
||||
id: this.user._id.toString(),
|
||||
name: this.user.uname,
|
||||
},
|
||||
customization: {
|
||||
chat: false,
|
||||
comments: false,
|
||||
help: false,
|
||||
hideRulers: true,
|
||||
plugins: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
const token = sign(payload, SystemModel.get('onlyoffice.jwtsecret'));
|
||||
this.response.body = {
|
||||
...payload,
|
||||
token,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function apply(ctx: Context) {
|
||||
Object.defineProperty(UiContextBase, 'onlyofficeApi', {
|
||||
configurable: true,
|
||||
@@ -19,4 +72,5 @@ export function apply(ctx: Context) {
|
||||
enumerable: false,
|
||||
});
|
||||
});
|
||||
ctx.Route('onlyoffice-jwt', '/onlyoffice-jwt', OnlyofficeJWTHandler);
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
{
|
||||
"name": "@hydrooj/onlyoffice",
|
||||
"version": "1.3.2",
|
||||
"version": "1.4.0",
|
||||
"main": "index.ts",
|
||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"preferUnplugged": true,
|
||||
"license": "AGPL-3.0-or-later"
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"jsonwebtoken": "^9.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsonwebtoken": "^9"
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,9 @@ api:
|
||||
type: text
|
||||
name: api
|
||||
desc: OnlyOffice API URL
|
||||
default: https://documentserver/web-apps/apps/api/documents/api.js
|
||||
default: https://documentserver/web-apps/apps/api/documents/api.js
|
||||
jwtsecret:
|
||||
type: text
|
||||
name: jwtsecret
|
||||
desc: JWT Secret
|
||||
default: secret
|
||||
Reference in new issue
Block a user