Add Attachment.deleteData
This commit is contained in:
parent
10afcf1bb0
commit
279b3f81c7
1 changed files with 26 additions and 0 deletions
|
@ -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);
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue