This commit is contained in:
2020-09-18 15:34:01 +00:00
parent f37476bfe2
commit 84ba1d4e7c

View File

@@ -12,7 +12,6 @@ async function ayPreRender(ayAllData) {
return true; return true;
} }
/////////////////////////////////////// ///////////////////////////////////////
// Set our stock handlebars helpers // Set our stock handlebars helpers
// //
@@ -45,8 +44,13 @@ function ayRegisterHelpers() {
if (ayValue == null) { if (ayValue == null) {
return ""; return "";
} }
//replace attachment urls with tokenized local urls
let src = ayValue.replace(/\[ATTACH:(.*)\]/g, function (match, p1) {
return attachmentDownloadUrl(p1);
});
return new Handlebars.SafeString( return new Handlebars.SafeString(
DOMPurify.sanitize(marked(ayValue, { breaks: true })) DOMPurify.sanitize(marked(src, { breaks: true }))
); );
}); });
@@ -319,3 +323,24 @@ function ayPad(n, width, z) {
n = n + ""; n = n + "";
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
} }
/////////////////////////////
// attachment download URL
//
function attachmentDownloadUrl(fileId, ctype) {
//http://localhost:7575/api/v8/attachment/download/100?t=sssss
//Ctype is optional and is the MIME content type, used to detect image urls at client for drag and drop ops
//in wiki but ignored by server
let url =
"attachment/download/" +
fileId +
"?t=" +
AYMETA.ayClientMetaData.DownloadToken;
if (ctype && ctype.includes("image")) {
url += "&i=1";
}
return AYMETA.ayServerMetaData.ayApiUrl + url;
}