mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
fixes of new attachment URLs
This commit is contained in:
parent
b84670d503
commit
0e4a040ed8
2789
package-lock.json
generated
2789
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1474,7 +1474,7 @@ class BNote extends AbstractBeccaEntity {
|
||||
let parentContent = parentNote.getContent();
|
||||
|
||||
const oldNoteUrl = `api/images/${this.noteId}/`;
|
||||
const newAttachmentUrl = `api/notes/${parentNote.noteId}/images/${attachment.attachmentId}/`;
|
||||
const newAttachmentUrl = `api/attachments/${attachment.attachmentId}/image/`;
|
||||
|
||||
const fixedContent = utils.replaceAll(parentContent, oldNoteUrl, newAttachmentUrl);
|
||||
|
||||
|
@ -110,7 +110,7 @@ export default class AttachmentDetailWidget extends BasicWidget {
|
||||
if (this.attachment.content) {
|
||||
return $("<pre>").text(this.attachment.content);
|
||||
} else if (this.attachment.role === 'image') {
|
||||
return `<img src="api/notes/${this.attachment.parentId}/images/${this.attachment.attachmentId}/${encodeURIComponent(this.attachment.title)}?${this.attachment.utcDateModified}">`;
|
||||
return `<img src="api/attachments/${this.attachment.attachmentId}/image/${encodeURIComponent(this.attachment.title)}?${this.attachment.utcDateModified}">`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
@ -44,15 +44,9 @@ function returnImage(req, res) {
|
||||
}
|
||||
|
||||
function returnAttachedImage(req, res) {
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
if (!note) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
const attachment = becca.getAttachment(req.params.attachmentId);
|
||||
|
||||
if (!attachment || attachment.parentId !== note.noteId) {
|
||||
if (!attachment) {
|
||||
res.set('Content-Type', 'image/png');
|
||||
return res.send(fs.readFileSync(`${RESOURCE_DIR}/db/image-deleted.png`));
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ function saveImageToAttachment(noteId, uploadBuffer, originalName, shrinkImageSw
|
||||
|
||||
return {
|
||||
attachment,
|
||||
url: `api/notes/${note.noteId}/images/${attachment.attachmentId}/${encodeURIComponent(fileName)}`
|
||||
url: `api/attachments/${attachment.attachmentId}/image/${encodeURIComponent(fileName)}`
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -435,7 +435,7 @@ const downloadImagePromises = {};
|
||||
function replaceUrl(content, url, attachment) {
|
||||
const quotedUrl = utils.quoteRegex(url);
|
||||
|
||||
return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "ig"), ` src="api/notes/${attachment.parentId}/images/${encodeURIComponent(attachment.title)}"`);
|
||||
return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "ig"), ` src="api/attachments/${encodeURIComponent(attachment.title)}/image"`);
|
||||
}
|
||||
|
||||
function downloadImages(noteId, content) {
|
||||
@ -461,7 +461,7 @@ function downloadImages(noteId, content) {
|
||||
|
||||
content = `${content.substr(0, imageMatch.index)}<img src="api/images/${note.noteId}/${sanitizedTitle}"${content.substr(imageMatch.index + imageMatch[0].length)}`;
|
||||
}
|
||||
else if (!url.includes('api/images/') && !/api\/notes\/.+\/images\/.*/.test(url)
|
||||
else if (!url.includes('api/images/') && !/api\/attachments\/.+\/image\/?.*/.test(url)
|
||||
// this is an exception for the web clipper's "imageId"
|
||||
&& (url.length !== 20 || url.toLowerCase().startsWith('http'))) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user