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

View File

@@ -8,11 +8,10 @@ async function ayPreRender(ayAllData) {
PreParedReportDataObject = await ayPrepareData(ayAllData);
} else {
PreParedReportDataObject = ayAllData;
}
}
return true;
}
///////////////////////////////////////
// Set our stock handlebars helpers
//
@@ -45,8 +44,13 @@ function ayRegisterHelpers() {
if (ayValue == null) {
return "";
}
//replace attachment urls with tokenized local urls
let src = ayValue.replace(/\[ATTACH:(.*)\]/g, function (match, p1) {
return attachmentDownloadUrl(p1);
});
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 + "";
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;
}