Add saveAttachment() to the attachments plugin API

cshd
Dragory 2020-11-02 17:37:07 +02:00
parent 1210b2acaa
commit 32c8d02531
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
4 changed files with 14 additions and 6 deletions

View File

@ -70,6 +70,7 @@ Scroll down to [PluginAPI](#PluginAPI) for a list of properties available to plu
| --- | --- | | --- | --- |
| addStorageType | <code>AddAttachmentStorageTypeFn</code> | | addStorageType | <code>AddAttachmentStorageTypeFn</code> |
| downloadAttachment | <code>DownloadAttachmentFn</code> | | downloadAttachment | <code>DownloadAttachmentFn</code> |
| saveAttachment | <code>SaveAttachmentFn</code> |
<a name="PluginLogsAPI"></a> <a name="PluginLogsAPI"></a>

View File

@ -60,6 +60,13 @@ function getErrorResult(msg = null) {
* @return {void} * @return {void}
*/ */
/**
* Saves the given attachment based on the configured storage system
* @callback SaveAttachmentFn
* @param {Eris.Attachment} attachment
* @returns {Promise<{ url: string }>}
*/
/** /**
* @type {AttachmentStorageTypeHandler} * @type {AttachmentStorageTypeHandler}
*/ */
@ -206,11 +213,9 @@ async function attachmentToDiscordFileObject(attachment) {
} }
/** /**
* Saves the given attachment based on the configured storage system * @type {SaveAttachmentFn}
* @param {Eris.Attachment} attachment
* @returns {Promise<{ url: string }>}
*/ */
function saveAttachment(attachment) { const saveAttachment = (attachment) => {
if (attachmentSavePromises[attachment.id]) { if (attachmentSavePromises[attachment.id]) {
return attachmentSavePromises[attachment.id]; return attachmentSavePromises[attachment.id];
} }
@ -226,7 +231,7 @@ function saveAttachment(attachment) {
}); });
return attachmentSavePromises[attachment.id]; return attachmentSavePromises[attachment.id];
} };
/** /**
* @type AddAttachmentStorageTypeFn * @type AddAttachmentStorageTypeFn

View File

@ -33,6 +33,7 @@ const displayRoles = require("./data/displayRoles");
* @typedef {object} PluginAttachmentsAPI * @typedef {object} PluginAttachmentsAPI
* @property {AddAttachmentStorageTypeFn} addStorageType * @property {AddAttachmentStorageTypeFn} addStorageType
* @property {DownloadAttachmentFn} downloadAttachment * @property {DownloadAttachmentFn} downloadAttachment
* @property {SaveAttachmentFn} saveAttachment
*/ */
/** /**

View File

@ -115,7 +115,8 @@ module.exports = {
}, },
attachments: { attachments: {
addStorageType: attachments.addStorageType, addStorageType: attachments.addStorageType,
downloadAttachment: attachments.downloadAttachment downloadAttachment: attachments.downloadAttachment,
saveAttachment: attachments.saveAttachment,
}, },
logs: { logs: {
addStorageType: logs.addStorageType, addStorageType: logs.addStorageType,