From 32c8d025313ef850d130375b62cfed4ccccc9066 Mon Sep 17 00:00:00 2001
From: Dragory <2606411+Dragory@users.noreply.github.com>
Date: Mon, 2 Nov 2020 17:37:07 +0200
Subject: [PATCH] Add saveAttachment() to the attachments plugin API
---
docs/plugin-api.md | 1 +
src/data/attachments.js | 15 ++++++++++-----
src/pluginApi.js | 1 +
src/plugins.js | 3 ++-
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/docs/plugin-api.md b/docs/plugin-api.md
index 87f013e..dbde608 100644
--- a/docs/plugin-api.md
+++ b/docs/plugin-api.md
@@ -70,6 +70,7 @@ Scroll down to [PluginAPI](#PluginAPI) for a list of properties available to plu
| --- | --- |
| addStorageType | AddAttachmentStorageTypeFn
|
| downloadAttachment | DownloadAttachmentFn
|
+| saveAttachment | SaveAttachmentFn
|
diff --git a/src/data/attachments.js b/src/data/attachments.js
index a5392c0..8b9be56 100644
--- a/src/data/attachments.js
+++ b/src/data/attachments.js
@@ -60,6 +60,13 @@ function getErrorResult(msg = null) {
* @return {void}
*/
+/**
+ * Saves the given attachment based on the configured storage system
+ * @callback SaveAttachmentFn
+ * @param {Eris.Attachment} attachment
+ * @returns {Promise<{ url: string }>}
+ */
+
/**
* @type {AttachmentStorageTypeHandler}
*/
@@ -206,11 +213,9 @@ async function attachmentToDiscordFileObject(attachment) {
}
/**
- * Saves the given attachment based on the configured storage system
- * @param {Eris.Attachment} attachment
- * @returns {Promise<{ url: string }>}
+ * @type {SaveAttachmentFn}
*/
-function saveAttachment(attachment) {
+const saveAttachment = (attachment) => {
if (attachmentSavePromises[attachment.id]) {
return attachmentSavePromises[attachment.id];
}
@@ -226,7 +231,7 @@ function saveAttachment(attachment) {
});
return attachmentSavePromises[attachment.id];
-}
+};
/**
* @type AddAttachmentStorageTypeFn
diff --git a/src/pluginApi.js b/src/pluginApi.js
index 0a101dc..dd776c8 100644
--- a/src/pluginApi.js
+++ b/src/pluginApi.js
@@ -33,6 +33,7 @@ const displayRoles = require("./data/displayRoles");
* @typedef {object} PluginAttachmentsAPI
* @property {AddAttachmentStorageTypeFn} addStorageType
* @property {DownloadAttachmentFn} downloadAttachment
+ * @property {SaveAttachmentFn} saveAttachment
*/
/**
diff --git a/src/plugins.js b/src/plugins.js
index 894c529..7ee9fce 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -115,7 +115,8 @@ module.exports = {
},
attachments: {
addStorageType: attachments.addStorageType,
- downloadAttachment: attachments.downloadAttachment
+ downloadAttachment: attachments.downloadAttachment,
+ saveAttachment: attachments.saveAttachment,
},
logs: {
addStorageType: logs.addStorageType,