From 9052c6916de2f6f5a6547ffe5544be40f2dcf8a5 Mon Sep 17 00:00:00 2001 From: Nay Date: Mon, 16 Dec 2024 23:38:28 +0100 Subject: [PATCH 1/5] Add files via upload --- actions/upload_image_to_imgur.js | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 actions/upload_image_to_imgur.js 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 () { }, +}; From 7e368c87740f765d3544e1292e3cb1d579420a9a Mon Sep 17 00:00:00 2001 From: Nay Date: Tue, 17 Dec 2024 01:02:36 +0100 Subject: [PATCH 2/5] Update upload_image_to_imgur.js --- actions/upload_image_to_imgur.js | 43 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/actions/upload_image_to_imgur.js b/actions/upload_image_to_imgur.js index eefdf18f..d78b83c8 100644 --- a/actions/upload_image_to_imgur.js +++ b/actions/upload_image_to_imgur.js @@ -1,23 +1,22 @@ const { ImgurClient } = require('imgur'); - module.exports = { - name: "Upload Image To Imgur", - section: "Other Stuff", + name: 'Upload Image To Imgur', + section: 'Other Stuff', - subtitle: function (data) { + subtitle(data) { return `Upload Image to Imgur`; }, variableStorage(data, varType) { - const type = parseInt(data.storage); + const type = parseInt(data.storage, 10); if (type !== varType) return; return [data.varName2, 'Image URL']; }, - fields: ["clientID", "clientSecret", "refreshToken", "imageURL", "storage", "varName2"], + fields: ['clientID', 'clientSecret', 'refreshToken', 'imageURL', 'storage', 'varName2'], - html: function (data) { + html(data) { return `
@@ -42,7 +41,10 @@ module.exports = {
Store In:
@@ -51,13 +53,12 @@ module.exports = { Variable Name:
- `; }, - init: function () { }, + init() {}, - action: function (cache) { + action(cache) { const data = cache.actions[cache.index]; const clientID = this.evalMessage(data.clientID, cache); @@ -65,18 +66,24 @@ module.exports = { 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 storage = parseInt(data.storage, 10); + + if (!clientID || !imageURL) { + console.error('Client ID or Image URL is missing!'); + return this.callNextAction(cache); + } const client = new ImgurClient({ clientId: clientID, - clientSecret: clientSecret, + clientSecret: clientSecret || undefined, refreshToken: refreshToken || undefined, }); - client.upload({ - image: imageURL, - type: 'url', - }) + client + .upload({ + image: imageURL, + type: 'url', + }) .then((response) => { const uploadedImageUrl = response.data.link; this.storeValue(uploadedImageUrl, storage, varName2, cache); @@ -88,5 +95,5 @@ module.exports = { }); }, - mod: function () { }, + mod() {}, }; From b8704163e2d4eaa8d4d14ef5f23e023854aa497e Mon Sep 17 00:00:00 2001 From: Nay Date: Wed, 18 Dec 2024 17:26:43 +0100 Subject: [PATCH 3/5] fixed some bugs & eslint (perhaps) --- actions/upload_image_to_imgur.js | 196 +++++++++++++++---------------- 1 file changed, 97 insertions(+), 99 deletions(-) diff --git a/actions/upload_image_to_imgur.js b/actions/upload_image_to_imgur.js index d78b83c8..4a557d24 100644 --- a/actions/upload_image_to_imgur.js +++ b/actions/upload_image_to_imgur.js @@ -1,99 +1,97 @@ -const { ImgurClient } = require('imgur'); - -module.exports = { - name: 'Upload Image To Imgur', - section: 'Other Stuff', - - subtitle(data) { - return `Upload Image to Imgur`; - }, - - variableStorage(data, varType) { - const type = parseInt(data.storage, 10); - if (type !== varType) return; - return [data.varName2, 'Image URL']; - }, - - fields: ['clientID', 'clientSecret', 'refreshToken', 'imageURL', 'storage', 'varName2'], - - html(data) { - return ` -
-
-
- Client ID:
- -
-
- Client Secret:
- -
-
- Refresh Token (optional):
- -
-
-
-
- Image URL:
- -
-
- Store In:
- -
-
- -
- Variable Name:
- -
-
`; - }, - - init() {}, - - action(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, 10); - - if (!clientID || !imageURL) { - console.error('Client ID or Image URL is missing!'); - return this.callNextAction(cache); - } - - const client = new ImgurClient({ - clientId: clientID, - clientSecret: clientSecret || undefined, - 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() {}, -}; +const { ImgurClient } = require('imgur'); + +module.exports = { + name: 'Upload Image To Imgur', + section: 'Other Stuff', + + subtitle() { + return `Upload Image to Imgur`; + }, + + variableStorage(data, varType) { + const type = parseInt(data.storage, 10); + if (type !== varType) return; + return [data.varName2, 'Image URL']; + }, + + fields: ['clientID', 'clientSecret', 'refreshToken', 'imageURL', 'storage', 'varName2'], + + html() { + return ` +
+
+
+ Client ID:
+ +
+
+ Client Secret (optional):
+ +
+
+ Refresh Token (optional):
+ +
+
+
+
+ Image URL:
+ +
+
+ Store In:
+ +
+
+ +
+ Variable Name:
+ +
+
`; + }, + + init() {}, + + action(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, 10); + + if (!clientID || !imageURL) { + console.error('Client ID or Image URL is missing!'); + return this.callNextAction(cache); + } + + const client = new ImgurClient({ + clientId: clientID, + clientSecret: clientSecret || undefined, + 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 () {}, +}; From bdae302a254b69e6685f0afdbbce3c30599c64c7 Mon Sep 17 00:00:00 2001 From: OneAndOnlyFinbar Date: Wed, 18 Dec 2024 16:11:14 -0500 Subject: [PATCH 4/5] Update upload_image_to_imgur.js --- actions/upload_image_to_imgur.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/upload_image_to_imgur.js b/actions/upload_image_to_imgur.js index 4a557d24..a5d590a0 100644 --- a/actions/upload_image_to_imgur.js +++ b/actions/upload_image_to_imgur.js @@ -93,5 +93,5 @@ module.exports = { this.callNextAction(cache); }); }, - mod () {}, + mod () {} }; From d8956ff34b765db4941868510d67e98efc766423 Mon Sep 17 00:00:00 2001 From: Finbar Date: Wed, 18 Dec 2024 16:14:48 -0500 Subject: [PATCH 5/5] fix lint --- actions/upload_image_to_imgur.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/upload_image_to_imgur.js b/actions/upload_image_to_imgur.js index a5d590a0..db16f11f 100644 --- a/actions/upload_image_to_imgur.js +++ b/actions/upload_image_to_imgur.js @@ -93,5 +93,5 @@ module.exports = { this.callNextAction(cache); }); }, - mod () {} + mod() {}, };