onlyoffice: handle invalid url error

This commit is contained in:
undefined committed 2024-10-06 13:57:10 +08:00
1 parent 12fe9bcd80
commit ad96cee008
2 files changed
+18 -9

No files matched your search

+11 -7
View File
@@ -23,13 +23,17 @@ const loader = (mode) => async (element) => {
const id = `${mode}-${Math.random().toString()}`;
$(element).attr('id', id);
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, {
...payload,
documentType: mode,
height: mode === 'slide' ? '560px' : '900px',
});
try {
const payload = await request.get('/onlyoffice-jwt', { url });
// @ts-ignore
window.editor = new DocsAPI.DocEditor(id, {
...payload,
documentType: mode,
height: mode === 'slide' ? '560px' : '900px',
});
} catch (e) {
console.error(e);
}
};
const getEles = (types: string[]) => types.flatMap((type) => $(`div[data-${type}]`).get());
+7 -2
View File
@@ -1,7 +1,7 @@
import { sign } from 'jsonwebtoken';
import { } from '@hydrooj/ui-default/backendlib/markdown-it-media';
import {
Context, Handler, superagent, SystemModel, UiContextBase,
Context, Handler, superagent, SystemModel, UiContextBase, ValidationError,
} from 'hydrooj';
declare module 'hydrooj' {
@@ -19,7 +19,12 @@ class OnlyofficeJWTHandler extends Handler {
const res = await superagent.get(SystemModel.get('onlyoffice.externalSign')).query({ url });
this.response.body = res.body;
}
const path = new URL(url).pathname;
let path: string;
try {
path = new URL(url).pathname;
} catch (e) {
throw new ValidationError('url');
}
const allowDownload = !!SystemModel.get('onlyoffice.allowDownload');
const payload = {
document: {