1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-02 22:49:09 +02:00

Desktop: Add support for media players (video, audio and PDF)

This commit is contained in:
Laurent Cozic
2020-12-09 21:30:51 +00:00
parent a3f8b9027c
commit 13dbeb4b36
14 changed files with 171 additions and 21 deletions

View File

@@ -14,7 +14,14 @@ export interface Options {
enableLongPress?: boolean;
}
export default function(href: string, options: Options = null) {
export interface LinkReplacementResult {
html: string;
resource: any;
resourceReady: boolean;
resourceFullPath: string;
}
export default function(href: string, options: Options = null): LinkReplacementResult {
options = {
title: '',
resources: {},
@@ -35,6 +42,7 @@ export default function(href: string, options: Options = null) {
let hrefAttr = '#';
let mime = '';
let resourceId = '';
let resource = null;
if (isResourceUrl) {
resourceId = resourceHrefInfo.itemId;
@@ -44,11 +52,18 @@ export default function(href: string, options: Options = null) {
if (result && result.item) {
if (!title) title = result.item.title;
mime = result.item.mime;
resource = result.item;
}
if (result && resourceStatus !== 'ready' && !options.plainResourceRendering) {
const icon = utils.resourceStatusFile(resourceStatus);
return `<a class="not-loaded-resource resource-status-${resourceStatus}" data-resource-id="${resourceId}">` + `<img src="data:image/svg+xml;utf8,${htmlentities(icon)}"/>`;
return {
resourceReady: false,
html: `<a class="not-loaded-resource resource-status-${resourceStatus}" data-resource-id="${resourceId}">` + `<img src="data:image/svg+xml;utf8,${htmlentities(icon)}"/>`,
resource,
resourceFullPath: null,
};
} else {
href = `joplin://${resourceId}`;
if (resourceHrefInfo.hash) href += `#${resourceHrefInfo.hash}`;
@@ -100,5 +115,10 @@ export default function(href: string, options: Options = null) {
if (js) attrHtml.push(js);
}
return `<a ${attrHtml.join(' ')}>${icon}`;
return {
html: `<a ${attrHtml.join(' ')}>${icon}`,
resourceReady: true,
resource,
resourceFullPath: resource && options?.ResourceModel?.fullPath ? options.ResourceModel.fullPath(resource) : null,
};
}