file attachment fix
This commit is contained in:
@@ -24,12 +24,27 @@ export const FileAttachment = Node.create<FileAttachmentOptions>({
|
|||||||
return {
|
return {
|
||||||
src: {
|
src: {
|
||||||
default: null,
|
default: null,
|
||||||
|
parseHTML: element => element.getAttribute('data-src'),
|
||||||
|
renderHTML: attributes => {
|
||||||
|
if (!attributes.src) return {};
|
||||||
|
return { 'data-src': attributes.src };
|
||||||
|
},
|
||||||
},
|
},
|
||||||
filename: {
|
filename: {
|
||||||
default: null,
|
default: null,
|
||||||
|
parseHTML: element => element.getAttribute('data-filename'),
|
||||||
|
renderHTML: attributes => {
|
||||||
|
if (!attributes.filename) return {};
|
||||||
|
return { 'data-filename': attributes.filename };
|
||||||
|
},
|
||||||
},
|
},
|
||||||
filesize: {
|
filesize: {
|
||||||
default: null,
|
default: null,
|
||||||
|
parseHTML: element => element.getAttribute('data-filesize'),
|
||||||
|
renderHTML: attributes => {
|
||||||
|
if (!attributes.filesize) return {};
|
||||||
|
return { 'data-filesize': attributes.filesize };
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -50,17 +65,17 @@ export const FileAttachment = Node.create<FileAttachmentOptions>({
|
|||||||
const isPdf = filename.toLowerCase().endsWith('.pdf');
|
const isPdf = filename.toLowerCase().endsWith('.pdf');
|
||||||
|
|
||||||
if (isPdf) {
|
if (isPdf) {
|
||||||
return ['div', mergeAttributes(this.options.HTMLAttributes, {
|
return ['div', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
||||||
'data-type': 'file-attachment',
|
'data-type': 'file-attachment',
|
||||||
'data-src': HTMLAttributes.src,
|
|
||||||
'data-filename': HTMLAttributes.filename,
|
|
||||||
class: 'file-attachment-wrapper relative w-full my-4 rounded-xl overflow-hidden border border-border flex min-h-[500px] bg-muted/20 group'
|
class: 'file-attachment-wrapper relative w-full my-4 rounded-xl overflow-hidden border border-border flex min-h-[500px] bg-muted/20 group'
|
||||||
}),
|
}),
|
||||||
['iframe', { src: HTMLAttributes.src, class: 'w-full h-full border-0 absolute inset-0' }]
|
['iframe', { src: HTMLAttributes.src, class: 'w-full h-full border-0 absolute inset-0' }]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['div', mergeAttributes(this.options.HTMLAttributes, { 'data-type': 'file-attachment', 'data-src': HTMLAttributes.src, 'data-filename': HTMLAttributes.filename }),
|
return ['div', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
||||||
|
'data-type': 'file-attachment',
|
||||||
|
}),
|
||||||
['a', { href: HTMLAttributes.src, target: '_blank', rel: 'noopener noreferrer', class: 'file-attachment-link flex items-center p-3 gap-3 w-full h-full' },
|
['a', { href: HTMLAttributes.src, target: '_blank', rel: 'noopener noreferrer', class: 'file-attachment-link flex items-center p-3 gap-3 w-full h-full' },
|
||||||
['div', { class: 'flex-shrink-0 flex items-center justify-center w-10 h-10 rounded-md bg-primary/10 text-primary' },
|
['div', { class: 'flex-shrink-0 flex items-center justify-center w-10 h-10 rounded-md bg-primary/10 text-primary' },
|
||||||
// SVG for FileText
|
// SVG for FileText
|
||||||
@@ -116,6 +131,7 @@ export const FileAttachment = Node.create<FileAttachmentOptions>({
|
|||||||
wrapper.setAttribute('data-type', 'file-attachment');
|
wrapper.setAttribute('data-type', 'file-attachment');
|
||||||
wrapper.setAttribute('data-src', node.attrs.src);
|
wrapper.setAttribute('data-src', node.attrs.src);
|
||||||
wrapper.setAttribute('data-filename', node.attrs.filename);
|
wrapper.setAttribute('data-filename', node.attrs.filename);
|
||||||
|
wrapper.setAttribute('data-filesize', node.attrs.filesize);
|
||||||
|
|
||||||
if (isFramable) {
|
if (isFramable) {
|
||||||
// Framed mode matching FileViewer
|
// Framed mode matching FileViewer
|
||||||
|
|||||||
+12
-10
@@ -626,16 +626,18 @@ export const cleanupNoteAttachments = async (noteId: string) => {
|
|||||||
if (!pb.authStore.isValid) return;
|
if (!pb.authStore.isValid) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const note = store.notes.find(n => n.id === noteId);
|
|
||||||
if (!note) return;
|
|
||||||
|
|
||||||
const record = await pb.collection(NOTES_COLLECTION).getOne(noteId);
|
const record = await pb.collection(NOTES_COLLECTION).getOne(noteId);
|
||||||
if (!record.attachments || record.attachments.length === 0) return;
|
if (!record.attachments || record.attachments.length === 0) return;
|
||||||
|
|
||||||
const content = note.content || "";
|
const content = record.content || "";
|
||||||
const filesToDelete: string[] = [];
|
const filesToDelete: string[] = [];
|
||||||
|
|
||||||
|
// Also check decoded content just in case of encoding mismatches
|
||||||
|
const decodedContent = decodeURIComponent(content);
|
||||||
|
|
||||||
for (const filename of record.attachments) {
|
for (const filename of record.attachments) {
|
||||||
if (!content.includes(filename)) {
|
// Check for literal filename OR the part of the URL that includes the filename
|
||||||
|
if (!content.includes(filename) && !decodedContent.includes(filename)) {
|
||||||
filesToDelete.push(filename);
|
filesToDelete.push(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,16 +657,16 @@ export const cleanupTaskAttachments = async (taskId: string) => {
|
|||||||
if (!pb.authStore.isValid) return;
|
if (!pb.authStore.isValid) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const task = store.tasks.find(t => t.id === taskId);
|
|
||||||
if (!task) return;
|
|
||||||
|
|
||||||
const record = await pb.collection(TASGRID_COLLECTION).getOne(taskId);
|
const record = await pb.collection(TASGRID_COLLECTION).getOne(taskId);
|
||||||
if (!record.attachments || record.attachments.length === 0) return;
|
if (!record.attachments || record.attachments.length === 0) return;
|
||||||
|
|
||||||
const content = task.content || "";
|
const content = record.content || "";
|
||||||
const filesToDelete: string[] = [];
|
const filesToDelete: string[] = [];
|
||||||
|
|
||||||
|
const decodedContent = decodeURIComponent(content);
|
||||||
|
|
||||||
for (const filename of record.attachments) {
|
for (const filename of record.attachments) {
|
||||||
if (!content.includes(filename)) {
|
if (!content.includes(filename) && !decodedContent.includes(filename)) {
|
||||||
filesToDelete.push(filename);
|
filesToDelete.push(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user