Merge branch 'master' into printf

pull/73/head
Josh Moore 3 years ago committed by GitHub
commit a41790793e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -167,7 +167,7 @@ Easy! Just pull the changes & run this one-liner:
git pull git pull
# Rebuild the container with the new changes (uncomment the 2nd part if the update requires refreshing the config) # Rebuild the container with the new changes (uncomment the 2nd part if the update requires refreshing the config)
docker-compose up --force-recreate --build -d && docker image prune -f # docker-compose exec ass npm run setup && docker-compose restart docker-compose up --force-recreate --build -d && docker image prune -f # && docker-compose exec ass npm run setup && docker-compose restart
``` ```
- `--force-recreate` will force the container to rebuild - `--force-recreate` will force the container to rebuild
@ -261,20 +261,11 @@ You can insert certain metadata into your embeds with these placeholders:
### Webhooks ### Webhooks
You may use Discord webhooks as an easy way to keep track of your uploads. The first step is to [create a new Webhook]. You only need to follow the first section, **Making a Webhook**. Once you are done that, click **Copy Webhook URL**. Next, paste your URL into a text editor. Extract these two values from the URL: You may use Discord webhooks as an easy way to keep track of your uploads. The first step is to [create a new Webhook]. You only need to follow the first section, **Making a Webhook**. Once you are done that, click **Copy Webhook URL**. Finally, add these headers to your custom uploader:
```
https://discord.com/api/webhooks/12345678910/T0kEn0fw3Bh00K
^^^^^^^^^^ ^^^^^^^^^^^^
Webhook ID Webhook Token
```
Once you have these, add the following HTTP headers to your ShareX config:
| Header | Purpose | | Header | Purpose |
| ------ | ------- | | ------ | ------- |
| **`X-Ass-Webhook-Client`** | The **Webhook ID** | | **`X-Ass-Webhook-Url`** | The **Webhook URL** you copied |
| **`X-Ass-Webhook-Token`** | The **Webhook Token** |
| **`X-Ass-Webhook-Username`** | (Optional) the "username" of the Webhook; can be set to whatever you want | | **`X-Ass-Webhook-Username`** | (Optional) the "username" of the Webhook; can be set to whatever you want |
| **`X-Ass-Webhook-Avatar`** | (Optional) URL to an image to use as the Webhook avatar. Use the **full** URL including `https://` | | **`X-Ass-Webhook-Avatar`** | (Optional) URL to an image to use as the Webhook avatar. Use the **full** URL including `https://` |

211
package-lock.json generated

@ -1,12 +1,12 @@
{ {
"name": "ass", "name": "ass",
"version": "0.8.6", "version": "0.8.7",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ass", "name": "ass",
"version": "0.8.6", "version": "0.8.7",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@tycrek/express-nofavicon": "^1.0.2", "@tycrek/express-nofavicon": "^1.0.2",
@ -17,7 +17,7 @@
"aws-sdk": "^2.930.0", "aws-sdk": "^2.930.0",
"check-node-version": "^4.1.0", "check-node-version": "^4.1.0",
"crypto-random-string": "3.3.1", "crypto-random-string": "3.3.1",
"discord.js": "^12.5.3", "discord-webhook-node": "^1.1.8",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"express": "^4.17.1", "express": "^4.17.1",
"express-rate-limit": "^5.2.6", "express-rate-limit": "^5.2.6",
@ -102,24 +102,6 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/@discordjs/collection": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
},
"node_modules/@discordjs/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/@jimp/bmp": { "node_modules/@jimp/bmp": {
"version": "0.16.1", "version": "0.16.1",
"resolved": "https://registry.npmjs.org/@jimp/bmp/-/bmp-0.16.1.tgz", "resolved": "https://registry.npmjs.org/@jimp/bmp/-/bmp-0.16.1.tgz",
@ -728,17 +710,6 @@
"@vibrant/types": "^3.2.1-alpha.1" "@vibrant/types": "^3.2.1-alpha.1"
} }
}, },
"node_modules/abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"dependencies": {
"event-target-shim": "^5.0.0"
},
"engines": {
"node": ">=6.5"
}
},
"node_modules/accepts": { "node_modules/accepts": {
"version": "1.3.7", "version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
@ -1522,23 +1493,13 @@
"node": ">=4.5.0" "node": ">=4.5.0"
} }
}, },
"node_modules/discord.js": { "node_modules/discord-webhook-node": {
"version": "12.5.3", "version": "1.1.8",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz", "resolved": "https://registry.npmjs.org/discord-webhook-node/-/discord-webhook-node-1.1.8.tgz",
"integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==", "integrity": "sha512-3u0rrwywwYGc6HrgYirN/9gkBYqmdpvReyQjapoXARAHi0P0fIyf3W5tS5i3U3cc7e44E+e7dIHYUeec7yWaug==",
"deprecated": "no longer supported",
"dependencies": { "dependencies": {
"@discordjs/collection": "^0.1.6", "form-data": "^3.0.0",
"@discordjs/form-data": "^3.0.1", "node-fetch": "^2.6.0"
"abort-controller": "^3.0.0",
"node-fetch": "^2.6.1",
"prism-media": "^1.2.9",
"setimmediate": "^1.0.5",
"tweetnacl": "^1.0.3",
"ws": "^7.4.4"
},
"engines": {
"node": ">=12.0.0"
} }
}, },
"node_modules/doctypes": { "node_modules/doctypes": {
@ -1611,14 +1572,6 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
"engines": {
"node": ">=6"
}
},
"node_modules/events": { "node_modules/events": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
@ -1761,6 +1714,19 @@
"imul": "^1.0.0" "imul": "^1.0.0"
} }
}, },
"node_modules/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/forwarded": { "node_modules/forwarded": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -2635,31 +2601,6 @@
"node": ">=4.0.0" "node": ">=4.0.0"
} }
}, },
"node_modules/prism-media": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.2.tgz",
"integrity": "sha512-L6UsGHcT6i4wrQhFF1aPK+MNYgjRqR2tUoIqEY+CG1NqVkMjPRKzS37j9f8GiYPlD6wG9ruBj+q5Ax+bH8Ik1g==",
"peerDependencies": {
"@discordjs/opus": "^0.5.0",
"ffmpeg-static": "^4.2.7 || ^3.0.0 || ^2.4.0",
"node-opus": "^0.3.3",
"opusscript": "^0.0.8"
},
"peerDependenciesMeta": {
"@discordjs/opus": {
"optional": true
},
"ffmpeg-static": {
"optional": true
},
"node-opus": {
"optional": true
},
"opusscript": {
"optional": true
}
}
},
"node_modules/process": { "node_modules/process": {
"version": "0.11.10", "version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
@ -3077,11 +3018,6 @@
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
}, },
"node_modules/setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"node_modules/setprototypeof": { "node_modules/setprototypeof": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
@ -3320,11 +3256,6 @@
"utf8-byte-length": "^1.0.1" "utf8-byte-length": "^1.0.1"
} }
}, },
"node_modules/tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
},
"node_modules/type-fest": { "node_modules/type-fest": {
"version": "0.8.1", "version": "0.8.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
@ -3567,26 +3498,6 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"node_modules/ws": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz",
"integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==",
"engines": {
"node": ">=8.3.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/xhr": { "node_modules/xhr": {
"version": "2.6.0", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/xhr/-/xhr-2.6.0.tgz", "resolved": "https://registry.npmjs.org/xhr/-/xhr-2.6.0.tgz",
@ -3740,21 +3651,6 @@
"parse-cache-control": "^1.0.1" "parse-cache-control": "^1.0.1"
} }
}, },
"@discordjs/collection": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
},
"@discordjs/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"@jimp/bmp": { "@jimp/bmp": {
"version": "0.16.1", "version": "0.16.1",
"resolved": "https://registry.npmjs.org/@jimp/bmp/-/bmp-0.16.1.tgz", "resolved": "https://registry.npmjs.org/@jimp/bmp/-/bmp-0.16.1.tgz",
@ -4230,14 +4126,6 @@
"@vibrant/types": "^3.2.1-alpha.1" "@vibrant/types": "^3.2.1-alpha.1"
} }
}, },
"abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"requires": {
"event-target-shim": "^5.0.0"
}
},
"accepts": { "accepts": {
"version": "1.3.7", "version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
@ -4835,19 +4723,13 @@
"streamsearch": "0.1.2" "streamsearch": "0.1.2"
} }
}, },
"discord.js": { "discord-webhook-node": {
"version": "12.5.3", "version": "1.1.8",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz", "resolved": "https://registry.npmjs.org/discord-webhook-node/-/discord-webhook-node-1.1.8.tgz",
"integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==", "integrity": "sha512-3u0rrwywwYGc6HrgYirN/9gkBYqmdpvReyQjapoXARAHi0P0fIyf3W5tS5i3U3cc7e44E+e7dIHYUeec7yWaug==",
"requires": { "requires": {
"@discordjs/collection": "^0.1.6", "form-data": "^3.0.0",
"@discordjs/form-data": "^3.0.1", "node-fetch": "^2.6.0"
"abort-controller": "^3.0.0",
"node-fetch": "^2.6.1",
"prism-media": "^1.2.9",
"setimmediate": "^1.0.5",
"tweetnacl": "^1.0.3",
"ws": "^7.4.4"
} }
}, },
"doctypes": { "doctypes": {
@ -4908,11 +4790,6 @@
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
}, },
"event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
},
"events": { "events": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
@ -5030,6 +4907,16 @@
"imul": "^1.0.0" "imul": "^1.0.0"
} }
}, },
"form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"forwarded": { "forwarded": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -5714,12 +5601,6 @@
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-3.4.0.tgz", "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-3.4.0.tgz",
"integrity": "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w==" "integrity": "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w=="
}, },
"prism-media": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.2.tgz",
"integrity": "sha512-L6UsGHcT6i4wrQhFF1aPK+MNYgjRqR2tUoIqEY+CG1NqVkMjPRKzS37j9f8GiYPlD6wG9ruBj+q5Ax+bH8Ik1g==",
"requires": {}
},
"process": { "process": {
"version": "0.11.10", "version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
@ -6065,11 +5946,6 @@
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
}, },
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"setprototypeof": { "setprototypeof": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
@ -6250,11 +6126,6 @@
"utf8-byte-length": "^1.0.1" "utf8-byte-length": "^1.0.1"
} }
}, },
"tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
},
"type-fest": { "type-fest": {
"version": "0.8.1", "version": "0.8.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
@ -6443,12 +6314,6 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"ws": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz",
"integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==",
"requires": {}
},
"xhr": { "xhr": {
"version": "2.6.0", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/xhr/-/xhr-2.6.0.tgz", "resolved": "https://registry.npmjs.org/xhr/-/xhr-2.6.0.tgz",

@ -1,6 +1,6 @@
{ {
"name": "ass", "name": "ass",
"version": "0.8.6", "version": "0.8.7",
"description": "The superior self-hosted ShareX server", "description": "The superior self-hosted ShareX server",
"main": "ass.js", "main": "ass.js",
"engines": { "engines": {
@ -43,7 +43,7 @@
"aws-sdk": "^2.930.0", "aws-sdk": "^2.930.0",
"check-node-version": "^4.1.0", "check-node-version": "^4.1.0",
"crypto-random-string": "3.3.1", "crypto-random-string": "3.3.1",
"discord.js": "^12.5.3", "discord-webhook-node": "^1.1.8",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"express": "^4.17.1", "express": "^4.17.1",
"express-rate-limit": "^5.2.6", "express-rate-limit": "^5.2.6",

@ -1,7 +1,7 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
//const rateLimit = require('express-rate-limit'); //const rateLimit = require('express-rate-limit');
const { DateTime } = require('luxon'); const { DateTime } = require('luxon');
const { WebhookClient, MessageEmbed } = require('discord.js'); const { Webhook, MessageBuilder } = require('discord-webhook-node');
const { doUpload, processUploaded } = require('../storage'); const { doUpload, processUploaded } = require('../storage');
const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType, spaceReplace } = require('../config.json'); const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType, spaceReplace } = require('../config.json');
const { path, log, verify, getTrueHttp, getTrueDomain, generateId, formatBytes } = require('../utils'); const { path, log, verify, getTrueHttp, getTrueDomain, generateId, formatBytes } = require('../utils');
@ -64,61 +64,89 @@ router.post('/', (req, res, next) => {
// Fix spaces in originalname // Fix spaces in originalname
req.file.originalname = req.file.originalname.replace(/\s/g, spaceReplace === '!' ? '' : spaceReplace); req.file.originalname = req.file.originalname.replace(/\s/g, spaceReplace === '!' ? '' : spaceReplace);
// Save the file information // Generate a unique resource ID
const resourceId = generateId(generator, resourceIdSize, req.headers['x-ass-gfycat'] || gfyIdSize, req.file.originalname); let resourceId = '';
log.debug('Saving data', data.name);
data.put(resourceId.split('.')[0], req.file).then(() => { // Function to call to generate a fresh ID. Used for multiple attempts in case an ID is already taken
// Log the upload const gen = () => generateId(generator, resourceIdSize, req.headers['x-ass-gfycat'] || gfyIdSize, req.file.originalname);
const logInfo = `${req.file.originalname} (${req.file.mimetype}, ${formatBytes(req.file.size)})`;
log.success('File uploaded', logInfo, `uploaded by ${users[req.token] ? users[req.token].username : '<token-only>'}`); // Keeps track of the number of attempts in case all ID's are taken
const attempts = {
// Build the URLs count: 0,
const resourceUrl = `${getTrueHttp()}${trueDomain}/${resourceId}`; max: 50
const thumbnailUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/thumbnail`; };
const deleteUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/delete/${req.file.deleteId}`;
// Called by a promise, this will recursively resolve itself until a unique ID is found
// Send the response function genCheckId(resolve, reject) {
res.type('json').send({ resource: resourceUrl, thumbnail: thumbnailUrl, delete: deleteUrl }) const uniqueId = gen();
.on('finish', () => { attempts.count++;
log.debug('Upload response sent'); data.has(uniqueId)
.then((exists) => {
// After we have sent the user the response, also send a Webhook to Discord (if headers are present) log.debug('ID check', exists ? 'Taken' : 'Available');
if (req.headers['x-ass-webhook-client'] && req.headers['x-ass-webhook-token']) { return attempts.count - 1 >= attempts.max ? reject(new Error('No ID\'s remaining')) : exists ? genCheckId(resolve, reject) : resolve(uniqueId);
const client = req.headers['x-ass-webhook-client'] })
.catch(reject);
// Build the webhook client & embed }
const whc = new WebhookClient(client, req.headers['x-ass-webhook-token']);
const embed = new MessageEmbed() new Promise((resolve, reject) => genCheckId(resolve, reject))
.setTitle(logInfo) .then((uniqueId) => {
.setURL(resourceUrl) resourceId = uniqueId;
.setDescription(`**Size:** \`${formatBytes(req.file.size)}\`\n**[Delete](${deleteUrl})**`) log.debug('Saving data', data.name);
.setThumbnail(thumbnailUrl) })
.setColor(req.file.vibrant) .then(() => data.put(resourceId.split('.')[0], req.file))
.setTimestamp(req.file.timestamp); .then(() => {
// Log the upload
// Send the embed to the webhook, then delete the client after to free resources const logInfo = `${req.file.originalname} (${req.file.mimetype}, ${formatBytes(req.file.size)})`;
log.debug('Sending webhook to client', client); log.success('File uploaded', logInfo, `uploaded by ${users[req.token] ? users[req.token].username : '<token-only>'}`);
whc.send(null, {
username: req.headers['x-ass-webhook-username'] || 'ass', // Build the URLs
avatarURL: req.headers['x-ass-webhook-avatar'] || ASS_LOGO, const resourceUrl = `${getTrueHttp()}${trueDomain}/${resourceId}`;
embeds: [embed] const thumbnailUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/thumbnail`;
}).then(() => log.debug('Webhook sent').callback(() => whc.destroy())); const deleteUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/delete/${req.file.deleteId}`;
}
// Send the response
// Also update the users upload count res.type('json').send({ resource: resourceUrl, thumbnail: thumbnailUrl, delete: deleteUrl })
if (!users[req.token]) { .on('finish', () => {
const generateUsername = () => generateId('random', 20, null); // skipcq: JS-0074 log.debug('Upload response sent');
let username = generateUsername();
while (Object.values(users).findIndex((user) => user.username === username) !== -1) // skipcq: JS-0073 // After we have sent the user the response, also send a Webhook to Discord (if headers are present)
username = generateUsername(); if (req.headers['x-ass-webhook-url']) {
users[req.token] = { username, count: 0 };
} // Build the webhook
users[req.token].count += 1; const hook = new Webhook(req.headers['x-ass-webhook-url']);
fs.writeJsonSync(path('auth.json'), { users }, { spaces: 4 }); hook.setUsername(req.headers['x-ass-webhook-username'] || 'ass');
hook.setAvatar(req.headers['x-ass-webhook-avatar'] || ASS_LOGO);
log.debug('Upload request flow completed', '');
}); // Build the embed
}).catch(next); const embed = new MessageBuilder()
.setTitle(logInfo)
.setURL(resourceUrl)
.setDescription(`**Size:** \`${formatBytes(req.file.size)}\`\n**[Delete](${deleteUrl})**`)
.setThumbnail(thumbnailUrl)
.setColor(req.file.vibrant)
.setTimestamp();
// Send the embed to the webhook, then delete the client after to free resources
log.debug('Sending embed to webhook');
hook.send(embed)
.then(() => log.debug('Webhook sent'))
.catch((err) => log.error('Webhook error').err(err));
}
// Also update the users upload count
if (!users[req.token]) {
const generateUsername = () => generateId('random', 20, null); // skipcq: JS-0074
let username = generateUsername();
while (Object.values(users).findIndex((user) => user.username === username) !== -1) // skipcq: JS-0073
username = generateUsername();
users[req.token] = { username, count: 0 };
}
users[req.token].count += 1;
fs.writeJsonSync(path('auth.json'), { users }, { spaces: 4 });
log.debug('Upload request flow completed', '');
});
}).catch(next);
}); });
module.exports = router; module.exports = router;

Loading…
Cancel
Save