diff --git a/js/modules/types/attachment.js b/js/modules/types/attachment.js index e3a125da7e5c..7dcb4906d49c 100644 --- a/js/modules/types/attachment.js +++ b/js/modules/types/attachment.js @@ -142,3 +142,29 @@ exports.loadData = (readAttachmentData) => { return Object.assign({}, attachment, { data }); }; }; + +// deleteData :: (RelativePath -> IO Unit) +// Attachment -> +// IO Unit +exports.deleteData = (deleteAttachmentData) => { + if (!isFunction(deleteAttachmentData)) { + throw new TypeError('`deleteAttachmentData` must be a function'); + } + + return async (attachment) => { + if (!exports.isValid(attachment)) { + throw new TypeError('`attachment` is not valid'); + } + + const hasDataInMemory = exports.hasData(attachment); + if (hasDataInMemory) { + return; + } + + if (!isString(attachment.path)) { + throw new TypeError('`attachment.path` is required'); + } + + await deleteAttachmentData(attachment.path); + }; +};