mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
onlyoffice: handle invalid url error
This commit is contained in:
2 files changed
+18
-9
No files matched your search
@@ -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());
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in new issue
Block a user