diff --git a/actions/upload_image_to_imgur.js b/actions/upload_image_to_imgur.js new file mode 100644 index 00000000..eefdf18f --- /dev/null +++ b/actions/upload_image_to_imgur.js @@ -0,0 +1,92 @@ +const { ImgurClient } = require('imgur'); + + +module.exports = { + name: "Upload Image To Imgur", + section: "Other Stuff", + + subtitle: function (data) { + return `Upload Image to Imgur`; + }, + + variableStorage(data, varType) { + const type = parseInt(data.storage); + if (type !== varType) return; + return [data.varName2, 'Image URL']; + }, + + fields: ["clientID", "clientSecret", "refreshToken", "imageURL", "storage", "varName2"], + + html: function (data) { + return ` +
+
+
+ Client ID:
+ +
+
+ Client Secret:
+ +
+
+ Refresh Token (optional):
+ +
+
+
+
+ Image URL:
+ +
+
+ Store In:
+ +
+
+ +
+ Variable Name:
+ +
+ +
`; + }, + + init: function () { }, + + action: function (cache) { + const data = cache.actions[cache.index]; + + const clientID = this.evalMessage(data.clientID, cache); + const clientSecret = this.evalMessage(data.clientSecret, cache); + const refreshToken = this.evalMessage(data.refreshToken, cache); + const imageURL = this.evalMessage(data.imageURL, cache); + const varName2 = this.evalMessage(data.varName2, cache); + const storage = parseInt(data.storage); + + const client = new ImgurClient({ + clientId: clientID, + clientSecret: clientSecret, + refreshToken: refreshToken || undefined, + }); + + client.upload({ + image: imageURL, + type: 'url', + }) + .then((response) => { + const uploadedImageUrl = response.data.link; + this.storeValue(uploadedImageUrl, storage, varName2, cache); + this.callNextAction(cache); + }) + .catch((err) => { + console.error('Error uploading image to Imgur:', err.message); + this.callNextAction(cache); + }); + }, + + mod: function () { }, +};