feat: made sure to clear attachment properties after deletion

confirmed everything works through testing
pull/2660/head
William Grant 3 years ago
parent 386997f233
commit 6cf2c0b0df

@ -28,16 +28,16 @@ export const deleteExternalMessageFiles = async (message: {
if (attachments && attachments.length) { if (attachments && attachments.length) {
await Promise.all(attachments.map(deleteData)); await Promise.all(attachments.map(deleteData));
// testing that the files were successfully deleted // test that the files were deleted successfully
try { try {
await Promise.all( await Promise.all(
attachments.map(async (attachment: { path: string; thumbnail: any; screenshot: any }) => { attachments.map(async (attachment: { path: string; thumbnail: any; screenshot: any }) => {
await readAttachmentData(attachment.path); await readAttachmentData(attachment.path);
}) })
); );
window.log.info(`WIP: failed in deleting files`); window.log.info('[deleteExternalMessageFiles]: Failed to delete attachments for', message);
} catch (err) { } catch (err) {
window.log.info(`WIP: succeeded in deleting files`, err); // If we fail to read the path then we know we deleted successfully
} }
} }
@ -52,6 +52,9 @@ export const deleteExternalMessageFiles = async (message: {
if (thumbnail && thumbnail.path && !thumbnail.copied) { if (thumbnail && thumbnail.path && !thumbnail.copied) {
await deleteOnDisk(thumbnail.path); await deleteOnDisk(thumbnail.path);
} }
attachment.thumbnail = undefined;
return attachment;
}) })
); );
} }
@ -64,6 +67,9 @@ export const deleteExternalMessageFiles = async (message: {
if (image && image.path) { if (image && image.path) {
await deleteOnDisk(image.path); await deleteOnDisk(image.path);
} }
item.image = undefined;
return image;
}) })
); );
} }

@ -145,7 +145,6 @@ export const loadData = async (attachment: any) => {
// deleteData :: (RelativePath -> IO Unit) // deleteData :: (RelativePath -> IO Unit)
// Attachment -> // Attachment ->
// IO Unit // IO Unit
// NOTE Flattening this function seemed to have worked
export const deleteData = async (attachment: { path: string; thumbnail: any; screenshot: any }) => { export const deleteData = async (attachment: { path: string; thumbnail: any; screenshot: any }) => {
if (!isValid(attachment)) { if (!isValid(attachment)) {
throw new TypeError('deleteData: attachment is not valid'); throw new TypeError('deleteData: attachment is not valid');
@ -155,15 +154,20 @@ export const deleteData = async (attachment: { path: string; thumbnail: any; scr
if (isString(path)) { if (isString(path)) {
await deleteOnDisk(path); await deleteOnDisk(path);
attachment.path = '';
} }
if (thumbnail && isString(thumbnail.path)) { if (thumbnail && isString(thumbnail.path)) {
await deleteOnDisk(thumbnail.path); await deleteOnDisk(thumbnail.path);
attachment.thumbnail = undefined;
} }
if (screenshot && isString(screenshot.path)) { if (screenshot && isString(screenshot.path)) {
await deleteOnDisk(screenshot.path); await deleteOnDisk(screenshot.path);
attachment.screenshot = undefined;
} }
return attachment;
}; };
type CaptureDimensionType = { contentType: string; path: string }; type CaptureDimensionType = { contentType: string; path: string };

Loading…
Cancel
Save