mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
onlyoffice: add jwt support
This commit is contained in:
4 files changed
+74
-42
No files matched your search
@@ -1,5 +1,7 @@
|
|||||||
/* eslint-disable github/array-foreach */
|
/* eslint-disable github/array-foreach */
|
||||||
import { $, addPage, AutoloadPage } from '@hydrooj/ui-default';
|
import {
|
||||||
|
$, addPage, AutoloadPage, request,
|
||||||
|
} from '@hydrooj/ui-default';
|
||||||
|
|
||||||
/* global DocsAPI */
|
/* global DocsAPI */
|
||||||
|
|
||||||
@@ -20,46 +22,11 @@ async function load() {
|
|||||||
const loader = (mode) => async (element) => {
|
const loader = (mode) => async (element) => {
|
||||||
const id = `${mode}-${Math.random().toString()}`;
|
const id = `${mode}-${Math.random().toString()}`;
|
||||||
$(element).attr('id', id);
|
$(element).attr('id', id);
|
||||||
const url = $(element).text();
|
const url = new URL($(element).text(), window.location.href).toString();
|
||||||
const t = new URL(url, window.location.href).pathname.split('.');
|
const payload = await request.get('/onlyoffice-jwt', { url });
|
||||||
const n = new URL(url, window.location.href).pathname.split('/');
|
|
||||||
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.editor = new DocsAPI.DocEditor(id, {
|
window.editor = new DocsAPI.DocEditor(id, {
|
||||||
document: {
|
...payload,
|
||||||
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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
documentType: mode,
|
documentType: mode,
|
||||||
height: mode === 'slide' ? '560px' : '900px',
|
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' {
|
declare module 'hydrooj' {
|
||||||
interface UiContextBase {
|
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) {
|
export function apply(ctx: Context) {
|
||||||
Object.defineProperty(UiContextBase, 'onlyofficeApi', {
|
Object.defineProperty(UiContextBase, 'onlyofficeApi', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
@@ -19,4 +72,5 @@ export function apply(ctx: Context) {
|
|||||||
enumerable: false,
|
enumerable: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
ctx.Route('onlyoffice-jwt', '/onlyoffice-jwt', OnlyofficeJWTHandler);
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/onlyoffice",
|
"name": "@hydrooj/onlyoffice",
|
||||||
"version": "1.3.2",
|
"version": "1.4.0",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"license": "AGPL-3.0-or-later"
|
"license": "AGPL-3.0-or-later",
|
||||||
|
"dependencies": {
|
||||||
|
"jsonwebtoken": "^9.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jsonwebtoken": "^9"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,3 +3,8 @@ api:
|
|||||||
name: api
|
name: api
|
||||||
desc: OnlyOffice API URL
|
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