Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nay-cat authored Dec 16, 2024
1 parent 5924cfa commit 9052c69
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions actions/upload_image_to_imgur.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const { ImgurClient } = require('imgur');

Check failure on line 1 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`

Check failure on line 2 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍⏎␍`

module.exports = {

Check failure on line 4 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
name: "Upload Image To Imgur",

Check failure on line 5 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `"Upload·Image·To·Imgur",␍` with `'Upload·Image·To·Imgur',`
section: "Other Stuff",

Check failure on line 6 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `"Other·Stuff",␍` with `'Other·Stuff',`

Check failure on line 7 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
subtitle: function (data) {

Check failure on line 8 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Expected method shorthand

Check failure on line 8 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
return `Upload Image to Imgur`;

Check failure on line 9 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
},

Check failure on line 10 in actions/upload_image_to_imgur.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`

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 `
<div style="padding-top: 8px; display: flex; flex-direction: column; gap: 10px;">
<div style="display: flex; gap: 10px;">
<div style="width: 33%;">
Client ID:<br>
<input id="clientID" class="round" type="text" style="width: 100%;">
</div>
<div style="width: 33%;">
Client Secret:<br>
<input id="clientSecret" class="round" type="text" style="width: 100%;">
</div>
<div style="width: 33%;">
Refresh Token (optional):<br>
<input id="refreshToken" class="round" type="text" style="width: 100%;">
</div>
</div>
<div style="display: flex; gap: 10px;">
<div style="width: 50%;">
Image URL:<br>
<input id="imageURL" class="round" type="text" style="width: 100%;">
</div>
<div style="width: 50%;">
Store In:<br>
<select id="storage" class="round" style="width: 100%;">
${data.variables[1]}
</select>
</div>
</div>
<div>
Variable Name:<br>
<input id="varName2" class="round" type="text" style="width: 100%;">
</div>
</div>`;
},

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 () { },
};

0 comments on commit 9052c69

Please sign in to comment.