mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: allow third-party richmedia provider
This commit is contained in:
1 file changed
+13
-6
@@ -68,6 +68,7 @@ function resourceUrl(service: string, src: string, url: string) {
|
|||||||
src = src.split('?')[0];
|
src = src.split('?')[0];
|
||||||
return `//player.bilibili.com/player.html?${src.startsWith('BV') ? 'bvid' : 'aid'}=${src}&autoplay=0`;
|
return `//player.bilibili.com/player.html?${src.startsWith('BV') ? 'bvid' : 'aid'}=${src}&autoplay=0`;
|
||||||
}
|
}
|
||||||
|
if (service === 'msoffice') return `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(src)}`;
|
||||||
if (service === 'youku') return `https://player.youku.com/embed/${src}`;
|
if (service === 'youku') return `https://player.youku.com/embed/${src}`;
|
||||||
if (service === 'vimeo') return `https://player.vimeo.com/video/${src}`;
|
if (service === 'vimeo') return `https://player.vimeo.com/video/${src}`;
|
||||||
if (service === 'vine') return `https://vine.co/v/${src}/embed/simple`;
|
if (service === 'vine') return `https://vine.co/v/${src}/embed/simple`;
|
||||||
@@ -79,16 +80,22 @@ function resourceUrl(service: string, src: string, url: string) {
|
|||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'hydrooj' {
|
||||||
|
interface ModuleInterfaces {
|
||||||
|
richmedia: {
|
||||||
|
get: (src: string) => string | null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function Media(md: MarkdownIt) {
|
export function Media(md: MarkdownIt) {
|
||||||
const supported = ['youtube', 'vimeo', 'vine', 'prezi', 'bilibili', 'youku'];
|
const supported = ['youtube', 'vimeo', 'vine', 'prezi', 'bilibili', 'youku', 'msoffice'];
|
||||||
md.renderer.rules.video = function tokenizeReturn(tokens, idx) {
|
md.renderer.rules.video = function tokenizeReturn(tokens, idx) {
|
||||||
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 (service === 'msoffice') {
|
if (Hydro.module.richmedia?.[service]) {
|
||||||
return `\
|
const result = Hydro.module.richmedia[service].get(src);
|
||||||
<iframe src="https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(src)}"
|
if (result) return result;
|
||||||
scrolling="no" border="0" frameborder="no" framespacing="0" width="100%" style="min-height:500px" ${allowFullScreen}></iframe>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
if (service === 'pdf') {
|
if (service === 'pdf') {
|
||||||
if (src.startsWith('file://') || src.startsWith('./')) src += src.includes('?') ? '&noDisposition=1' : '?noDisposition=1';
|
if (src.startsWith('file://') || src.startsWith('./')) src += src.includes('?') ? '&noDisposition=1' : '?noDisposition=1';
|
||||||
|
|||||||
Reference in new issue
Block a user