wingbot 3.62.1 → 3.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const Router = require('../../src/Router');
|
|
2
|
+
const { compileWithState } = require('../../src/utils');
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
*
|
|
@@ -6,6 +7,7 @@ const Router = require('../../src/Router');
|
|
|
6
7
|
* @param {'any'|'image'|'audio'|'video'|'file'} params.type
|
|
7
8
|
* @param {string} params.variable
|
|
8
9
|
* @param {'array'|'string'} params.datatype
|
|
10
|
+
* @param {string} params.allowSuffixes
|
|
9
11
|
* @returns {import('../../src/Router').Middleware}
|
|
10
12
|
*/
|
|
11
13
|
module.exports = (params) => {
|
|
@@ -15,10 +17,21 @@ module.exports = (params) => {
|
|
|
15
17
|
* @param {import('../../src/Responder')} res
|
|
16
18
|
*/
|
|
17
19
|
const uploadPlugin = async (req, res) => {
|
|
20
|
+
|
|
21
|
+
const allowSuffixes = compileWithState(req, res, params.allowSuffixes)
|
|
22
|
+
.split(',')
|
|
23
|
+
.map((s) => s.toLowerCase().trim())
|
|
24
|
+
.filter((s) => !!s);
|
|
25
|
+
|
|
18
26
|
if (req.isAttachment()) {
|
|
27
|
+
const suffixOk = allowSuffixes.length === 0
|
|
28
|
+
|| req.attachments.every((a) => {
|
|
29
|
+
const [, suffix = ''] = a.payload.url.match(/\.([a-z0-9]+)(\?.+)?$/i) || [];
|
|
30
|
+
return allowSuffixes.includes(suffix.toLowerCase());
|
|
31
|
+
});
|
|
19
32
|
|
|
20
33
|
const typeOk = (!params.type || params.type === 'any')
|
|
21
|
-
|| req.attachments.every((a) => a.type === params.type);
|
|
34
|
+
|| (req.attachments.every((a) => a.type === params.type) && suffixOk);
|
|
22
35
|
|
|
23
36
|
if (!typeOk) {
|
|
24
37
|
await res.run('badType');
|
package/plugins/plugins.json
CHANGED
|
@@ -644,6 +644,11 @@
|
|
|
644
644
|
{ "value": "string", "label": "string" },
|
|
645
645
|
{ "value": "array", "label": "array of strings" }
|
|
646
646
|
]
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
"name": "allowSuffixes",
|
|
650
|
+
"label": "Allowed attachment suffixes (comma separated)",
|
|
651
|
+
"type": "text"
|
|
647
652
|
}
|
|
648
653
|
],
|
|
649
654
|
"items": [
|