onlyoffice: support pdf documents

This commit is contained in:
undefined committed 2024-09-26 06:26:28 +08:00
1 parent 520c75d1d1
commit dcbca065e5
6 files changed
+38 -24

No files matched your search

+2 -2
View File
@@ -35,9 +35,9 @@ const loader = (mode) => async (element) => {
const getEles = (types: string[]) => types.flatMap((type) => $(`div[data-${type}]`).get()); const getEles = (types: string[]) => types.flatMap((type) => $(`div[data-${type}]`).get());
addPage(new AutoloadPage('onlyoffice', async () => { addPage(new AutoloadPage('onlyoffice', async () => {
const all = getEles(['doc', 'docx', 'cell', 'xls', 'xlsx', 'slide', 'ppt', 'pptx']); const all = getEles(['doc', 'docx', 'cell', 'xls', 'xlsx', 'slide', 'ppt', 'pptx', 'pdf']);
if (all.length) await load(); if (all.length) await load();
getEles(['doc', 'docx']).forEach(loader('word')); getEles(['doc', 'docx', 'pdf']).forEach(loader('word'));
getEles(['cell', 'xls', 'xlsx']).forEach(loader('cell')); getEles(['cell', 'xls', 'xlsx']).forEach(loader('cell'));
getEles(['slide', 'ppt', 'pptx']).forEach(loader('slide')); getEles(['slide', 'ppt', 'pptx']).forEach(loader('slide'));
})); }));
+13 -4
View File
@@ -1,4 +1,5 @@
import { sign } from 'jsonwebtoken'; import { sign } from 'jsonwebtoken';
import { } from '@hydrooj/ui-default/backendlib/markdown-it-media';
import { import {
Context, Handler, SystemModel, UiContextBase, Context, Handler, SystemModel, UiContextBase,
} from 'hydrooj'; } from 'hydrooj';
@@ -15,6 +16,7 @@ class OnlyofficeJWTHandler extends Handler {
async get({ url }) { async get({ url }) {
const path = new URL(url).pathname; const path = new URL(url).pathname;
const allowDownload = !!SystemModel.get('onlyoffice.allowDownload');
const payload = { const payload = {
document: { document: {
fileType: path.split('.').pop(), fileType: path.split('.').pop(),
@@ -23,19 +25,19 @@ class OnlyofficeJWTHandler extends Handler {
url, url,
permissions: { permissions: {
comment: false, comment: false,
copy: true, copy: allowDownload,
download: true, download: allowDownload,
edit: false, edit: false,
fillForms: false, fillForms: false,
modifyContentControl: false, modifyContentControl: false,
modifyFilter: false, modifyFilter: false,
print: true, print: allowDownload,
protect: false, protect: false,
review: false, review: false,
}, },
}, },
editorConfig: { editorConfig: {
lang: this.user.viewLang.includes('_') ? this.user.viewLang.split('_')[0] : this.user.viewLang, lang: this.user.viewLang?.includes('_') ? this.user.viewLang.split('_')[0] : this.user.viewLang || 'zh',
mode: 'view', mode: 'view',
user: { user: {
group: 'Hydro', group: 'Hydro',
@@ -73,4 +75,11 @@ export function apply(ctx: Context) {
}); });
}); });
ctx.Route('onlyoffice-jwt', '/onlyoffice-jwt', OnlyofficeJWTHandler); ctx.Route('onlyoffice-jwt', '/onlyoffice-jwt', OnlyofficeJWTHandler);
if (SystemModel.get('onlyoffice.pdf')) {
ctx.provideModule('richmedia', 'pdf', {
get(service, src, md) {
return `<div data-${service}>${md.utils.escapeHtml(src)}</div>`;
},
});
}
} }
+6 -1
View File
@@ -7,4 +7,9 @@ jwtsecret:
type: text type: text
name: jwtsecret name: jwtsecret
desc: JWT Secret desc: JWT Secret
default: secret default: secret
pdf:
type: boolean
name: pdf
desc: Handle pdf documents
default: false
@@ -83,7 +83,7 @@ function resourceUrl(service: string, src: string, url: string) {
declare module 'hydrooj' { declare module 'hydrooj' {
interface ModuleInterfaces { interface ModuleInterfaces {
richmedia: { richmedia: {
get: (src: string) => string | null; get: (service: string, src: string, md: MarkdownIt) => string | null;
} }
} }
} }
@@ -94,7 +94,7 @@ export function Media(md: MarkdownIt) {
let src = md.utils.escapeHtml(tokens[idx].attrGet('src')); let src = md.utils.escapeHtml(tokens[idx].attrGet('src'));
const service = md.utils.escapeHtml(tokens[idx].attrGet('service')).toLowerCase(); const service = md.utils.escapeHtml(tokens[idx].attrGet('service')).toLowerCase();
if (Hydro.module.richmedia?.[service]) { if (Hydro.module.richmedia?.[service]) {
const result = Hydro.module.richmedia[service].get(src); const result = Hydro.module.richmedia[service].get(service, src, md);
if (result) return result; if (result) return result;
} }
if (service === 'pdf') { if (service === 'pdf') {
@@ -1,18 +1,18 @@
import { Intent, Position, Toaster } from '@blueprintjs/core'; import { Intent, OverlayToaster, Position } from '@blueprintjs/core';
import $ from 'jquery'; import $ from 'jquery';
import { tpl, zIndexManager } from 'vj/utils/base'; import { tpl, zIndexManager } from 'vj/utils/base';
const ToasterContainer = document.createElement('div'); const ToasterContainer = document.createElement('div');
ToasterContainer.style.position = 'fixed'; ToasterContainer.style.position = 'fixed';
ToasterContainer.style.bottom = '0px'; ToasterContainer.style.bottom = '0px';
ToasterContainer.style.width = '100%';
ToasterContainer.style.zIndex = '9999'; ToasterContainer.style.zIndex = '9999';
document.body.append(ToasterContainer); document.body.append(ToasterContainer);
export const AppToaster = Toaster.create({ const AppToaster = OverlayToaster.createAsync(
className: 'recipe-toaster', { position: Position.BOTTOM_LEFT, usePortal: false },
position: Position.LEFT_BOTTOM, { container: ToasterContainer },
usePortal: true, );
} as any, ToasterContainer);
interface NotificationOptions { interface NotificationOptions {
avatar?: string; avatar?: string;
@@ -65,20 +65,20 @@ export default class Notification {
setTimeout(() => this.$n.remove(), 200); setTimeout(() => this.$n.remove(), 200);
} }
static success(message: string, duration?: number) { static async success(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.SUCCESS }); return (await AppToaster).show({ message, timeout: duration, intent: Intent.SUCCESS });
} }
static info(message: string, duration?: number) { static async info(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.PRIMARY }); return (await AppToaster).show({ message, timeout: duration, intent: Intent.PRIMARY });
} }
static warn(message: string, duration?: number) { static async warn(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.WARNING }); return (await AppToaster).show({ message, timeout: duration, intent: Intent.WARNING });
} }
static error(message: string, duration?: number) { static async error(message: string, duration?: number) {
return AppToaster.show({ message, timeout: duration, intent: Intent.DANGER }); return (await AppToaster).show({ message, timeout: duration, intent: Intent.DANGER });
} }
} }
+1 -1
View File
@@ -261,7 +261,7 @@ small, figcaption
.typo .typo
word-wrap() word-wrap()
overflow: auto overflow: auto hidden;
.typo a, .typo .link, .typo-a .typo a, .typo .link, .typo-a
&, &:visited, &:active, &:hover &, &:visited, &:active, &:hover