mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
onlyoffice: init
This commit is contained in:
1 parent
2c3fd7364a
commit
7a343449b0
8 files changed
+80
-6
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.24.4",
|
"version": "2.24.5",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -275,7 +275,11 @@ export async function prepare() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UiContextBase = {
|
export interface UiContextBase {
|
||||||
|
cdn_prefix: string;
|
||||||
|
url_prefix: string;
|
||||||
|
}
|
||||||
|
export const UiContextBase: UiContextBase = {
|
||||||
cdn_prefix: '/',
|
cdn_prefix: '/',
|
||||||
url_prefix: '/',
|
url_prefix: '/',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { UiContextBase } from 'hydrooj/dist/service/server';
|
||||||
|
import * as system from 'hydrooj/dist/model/system';
|
||||||
|
|
||||||
|
declare module 'hydrooj/dist/service/server' {
|
||||||
|
interface UiContextBase {
|
||||||
|
onlyofficeApi: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UiContextBase.onlyofficeApi = system.get('onlyoffice.api');
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "@hydrooj/onlyoffice",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "package.json",
|
||||||
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
|
"author": "undefined <i@undefined.moe>",
|
||||||
|
"license": "AGPL-3.0-only"
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
(() => {
|
||||||
|
const { AutoloadPage } = window.Hydro;
|
||||||
|
const { $ } = window.node_modules;
|
||||||
|
const { request } = window.Hydro.utils;
|
||||||
|
|
||||||
|
const page = new AutoloadPage('onlyoffice', async () => {
|
||||||
|
const res = $('div[data-doc]');
|
||||||
|
if (res.length) {
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
const scriptElement = document.createElement('script');
|
||||||
|
scriptElement.src = UiContext.onlyofficeApi;
|
||||||
|
scriptElement.async = true;
|
||||||
|
document.head.appendChild(scriptElement);
|
||||||
|
scriptElement.onload = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.get().forEach(async (element) => {
|
||||||
|
const id = `doc-${Math.random().toString()}`;
|
||||||
|
$(element).attr('id', id);
|
||||||
|
const url = $(element).text();
|
||||||
|
const t = new URL(url, window.location.href).pathname.split('.');
|
||||||
|
const n = new URL(url, window.location.href).pathname.split('/');
|
||||||
|
const res = await request.get(url);
|
||||||
|
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
window.editor = new DocsAPI.DocEditor(id, {
|
||||||
|
document: {
|
||||||
|
fileType: t[t.length - 1],
|
||||||
|
key: Math.random().toString(16),
|
||||||
|
title: n[n.length - 1],
|
||||||
|
url: new URL(res.url, window.location.href),
|
||||||
|
},
|
||||||
|
editorConfig: {
|
||||||
|
lang,
|
||||||
|
mode: 'view',
|
||||||
|
},
|
||||||
|
documentType: 'word',
|
||||||
|
height: '980px',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
window.Hydro.extraPages.push(page);
|
||||||
|
})();
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
api:
|
||||||
|
type: text
|
||||||
|
name: api
|
||||||
|
desc: OnlyOffice API URL
|
||||||
|
default: https://documentserver/web-apps/apps/api/documents/api.js
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
/* eslint-disable prefer-destructuring */
|
/* eslint-disable prefer-destructuring */
|
||||||
|
|
||||||
|
const { escapeHtml } = require('vj/../../node_modules/markdown-it/lib/common/utils');
|
||||||
|
|
||||||
/* eslint-disable no-restricted-properties */
|
/* eslint-disable no-restricted-properties */
|
||||||
const ytRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
|
const ytRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
|
||||||
function youtubeParser(url) {
|
function youtubeParser(url) {
|
||||||
@@ -115,11 +118,13 @@ module.exports = function videoPlugin(md) {
|
|||||||
+ ' }); </script>';
|
+ ' }); </script>';
|
||||||
}
|
}
|
||||||
if (service === 'pdf') return `<iframe src="${videoID}?noDisposition=on#view=fit" width="100%" style="min-height: 100vh;border: none;"></iframe>`;
|
if (service === 'pdf') return `<iframe src="${videoID}?noDisposition=on#view=fit" width="100%" style="min-height: 100vh;border: none;"></iframe>`;
|
||||||
return videoID === '' ? ''
|
if (service === 'video') {
|
||||||
: `<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item ${service}-player" type="text/html" width="${options[service].width
|
return `<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item ${service}-player" type="text/html" width="${options[service].width
|
||||||
}" height="${options[service].height
|
}" height="${options[service].height
|
||||||
}" src="${options.url(service, videoID, tokens[idx].url, options)
|
}" src="${options.url(service, videoID, tokens[idx].url, options)
|
||||||
}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
|
}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
|
||||||
|
}
|
||||||
|
return `<div data-${service}>${escapeHtml(videoID)}</div>`;
|
||||||
};
|
};
|
||||||
md.inline.ruler.before('emphasis', 'video', (state, silent) => {
|
md.inline.ruler.before('emphasis', 'video', (state, silent) => {
|
||||||
let token;
|
let token;
|
||||||
@@ -140,7 +145,6 @@ module.exports = function videoPlugin(md) {
|
|||||||
else if (serviceLower === 'vine') videoID = vineParser(videoID);
|
else if (serviceLower === 'vine') videoID = vineParser(videoID);
|
||||||
else if (serviceLower === 'prezi') videoID = preziParser(videoID);
|
else if (serviceLower === 'prezi') videoID = preziParser(videoID);
|
||||||
else if (serviceLower === 'osf') videoID = mfrParser(videoID);
|
else if (serviceLower === 'osf') videoID = mfrParser(videoID);
|
||||||
else if (!options[serviceLower]) return false;
|
|
||||||
if (videoID === ')') videoID = '';
|
if (videoID === ')') videoID = '';
|
||||||
const serviceStart = oldPos + 2;
|
const serviceStart = oldPos + 2;
|
||||||
const serviceEnd = md.helpers.parseLinkLabel(state, oldPos + 1, false);
|
const serviceEnd = md.helpers.parseLinkLabel(state, oldPos + 1, false);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.6.23",
|
"version": "4.6.24",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
Reference in new issue
Block a user