fixes of new attachment URLs

This commit is contained in:
zadam 2023-04-17 22:40:53 +02:00
parent b84670d503
commit 0e4a040ed8
6 changed files with 2742 additions and 65 deletions

2789
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1474,7 +1474,7 @@ class BNote extends AbstractBeccaEntity {
let parentContent = parentNote.getContent(); let parentContent = parentNote.getContent();
const oldNoteUrl = `api/images/${this.noteId}/`; 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); const fixedContent = utils.replaceAll(parentContent, oldNoteUrl, newAttachmentUrl);

View File

@ -110,7 +110,7 @@ export default class AttachmentDetailWidget extends BasicWidget {
if (this.attachment.content) { if (this.attachment.content) {
return $("<pre>").text(this.attachment.content); return $("<pre>").text(this.attachment.content);
} else if (this.attachment.role === 'image') { } 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 { } else {
return ''; return '';
} }

View File

@ -44,15 +44,9 @@ function returnImage(req, res) {
} }
function returnAttachedImage(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); const attachment = becca.getAttachment(req.params.attachmentId);
if (!attachment || attachment.parentId !== note.noteId) { if (!attachment) {
res.set('Content-Type', 'image/png'); res.set('Content-Type', 'image/png');
return res.send(fs.readFileSync(`${RESOURCE_DIR}/db/image-deleted.png`)); return res.send(fs.readFileSync(`${RESOURCE_DIR}/db/image-deleted.png`));
} }

View File

@ -170,7 +170,7 @@ function saveImageToAttachment(noteId, uploadBuffer, originalName, shrinkImageSw
return { return {
attachment, attachment,
url: `api/notes/${note.noteId}/images/${attachment.attachmentId}/${encodeURIComponent(fileName)}` url: `api/attachments/${attachment.attachmentId}/image/${encodeURIComponent(fileName)}`
}; };
} }

View File

@ -435,7 +435,7 @@ const downloadImagePromises = {};
function replaceUrl(content, url, attachment) { function replaceUrl(content, url, attachment) {
const quotedUrl = utils.quoteRegex(url); 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) { 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)}`; 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" // this is an exception for the web clipper's "imageId"
&& (url.length !== 20 || url.toLowerCase().startsWith('http'))) { && (url.length !== 20 || url.toLowerCase().startsWith('http'))) {