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
+75
-43
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user