@reldens/server-utils 0.9.0 → 0.10.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/lib/uploader-factory.js +19 -16
- package/package.json +47 -47
package/lib/uploader-factory.js
CHANGED
|
@@ -35,16 +35,18 @@ class UploaderFactory
|
|
|
35
35
|
cb(null, dest);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
38
|
+
diskStorageConfiguration['filename'] = (req, file, cb) => {
|
|
39
|
+
if(!this.applySecureFileNames) {
|
|
40
|
+
cb(null, file.originalname);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let secureFilename = FileHandler.generateSecureFilename(file.originalname);
|
|
44
|
+
if(!req.fileNameMapping){
|
|
45
|
+
req.fileNameMapping = {};
|
|
46
|
+
}
|
|
47
|
+
req.fileNameMapping[secureFilename] = file.originalname;
|
|
48
|
+
cb(null, secureFilename);
|
|
49
|
+
};
|
|
48
50
|
let storage = multer.diskStorage(diskStorageConfiguration);
|
|
49
51
|
let limits = {
|
|
50
52
|
fileSize: this.maxFileSize
|
|
@@ -83,13 +85,13 @@ class UploaderFactory
|
|
|
83
85
|
if(FileHandler.exists(file.path)){
|
|
84
86
|
FileHandler.remove(file.path);
|
|
85
87
|
}
|
|
86
|
-
return res.status(415).send('File contents do not match declared type');
|
|
88
|
+
return res.status(415).send('File contents do not match declared type.');
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
next();
|
|
91
93
|
} catch(error){
|
|
92
|
-
|
|
94
|
+
this.error = {message: 'File validation error.', error};
|
|
93
95
|
this.cleanupFiles(req.files);
|
|
94
96
|
return res.status(500).send('Error processing uploaded files');
|
|
95
97
|
}
|
|
@@ -156,11 +158,12 @@ class UploaderFactory
|
|
|
156
158
|
{
|
|
157
159
|
try {
|
|
158
160
|
if(!FileHandler.isFile(file.path)){
|
|
161
|
+
this.error = {message: 'File path must be provided.', file};
|
|
159
162
|
return false;
|
|
160
163
|
}
|
|
161
164
|
return FileHandler.validateFileType(file.path, allowedFileType, this.allowedExtensions, this.maxFileSize);
|
|
162
|
-
} catch(
|
|
163
|
-
|
|
165
|
+
} catch(error){
|
|
166
|
+
this.error = {message: 'Error validating file contents.', error};
|
|
164
167
|
return false;
|
|
165
168
|
}
|
|
166
169
|
}
|
|
@@ -187,8 +190,8 @@ class UploaderFactory
|
|
|
187
190
|
if(FileHandler.exists(file.path)){
|
|
188
191
|
FileHandler.remove(file.path);
|
|
189
192
|
}
|
|
190
|
-
} catch(
|
|
191
|
-
|
|
193
|
+
} catch(error){
|
|
194
|
+
this.error = {message: 'Error cleaning up file.', error};
|
|
192
195
|
}
|
|
193
196
|
}
|
|
194
197
|
}
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@reldens/server-utils",
|
|
3
|
-
"scope": "@reldens",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Reldens - Server Utils",
|
|
6
|
-
"author": "Damian A. Pastorini",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"homepage": "https://github.com/damian-pastorini/reldens-server-utils",
|
|
9
|
-
"source": true,
|
|
10
|
-
"main": "index.js",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "https://github.com/damian-pastorini/reldens-server-utils.git"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"reldens",
|
|
17
|
-
"utils",
|
|
18
|
-
"shortcuts",
|
|
19
|
-
"system",
|
|
20
|
-
"game",
|
|
21
|
-
"mmorpg",
|
|
22
|
-
"rpg",
|
|
23
|
-
"dwd",
|
|
24
|
-
"colyseus",
|
|
25
|
-
"phaser",
|
|
26
|
-
"parcel",
|
|
27
|
-
"nodejs",
|
|
28
|
-
"mmo",
|
|
29
|
-
"multiplayer",
|
|
30
|
-
"rol",
|
|
31
|
-
"platform",
|
|
32
|
-
"framework"
|
|
33
|
-
],
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/damian-pastorini/reldens-server-utils/issues"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"body-parser": "2.2.0",
|
|
39
|
-
"cors": "2.8.5",
|
|
40
|
-
"express": "4.21.2",
|
|
41
|
-
"express-rate-limit": "7.5.0",
|
|
42
|
-
"express-session": "1.18.1",
|
|
43
|
-
"helmet": "8.1.0",
|
|
44
|
-
"multer": "^1.4.5-lts.2",
|
|
45
|
-
"xss-clean": "
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@reldens/server-utils",
|
|
3
|
+
"scope": "@reldens",
|
|
4
|
+
"version": "0.10.0",
|
|
5
|
+
"description": "Reldens - Server Utils",
|
|
6
|
+
"author": "Damian A. Pastorini",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/damian-pastorini/reldens-server-utils",
|
|
9
|
+
"source": true,
|
|
10
|
+
"main": "index.js",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/damian-pastorini/reldens-server-utils.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"reldens",
|
|
17
|
+
"utils",
|
|
18
|
+
"shortcuts",
|
|
19
|
+
"system",
|
|
20
|
+
"game",
|
|
21
|
+
"mmorpg",
|
|
22
|
+
"rpg",
|
|
23
|
+
"dwd",
|
|
24
|
+
"colyseus",
|
|
25
|
+
"phaser",
|
|
26
|
+
"parcel",
|
|
27
|
+
"nodejs",
|
|
28
|
+
"mmo",
|
|
29
|
+
"multiplayer",
|
|
30
|
+
"rol",
|
|
31
|
+
"platform",
|
|
32
|
+
"framework"
|
|
33
|
+
],
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/damian-pastorini/reldens-server-utils/issues"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"body-parser": "2.2.0",
|
|
39
|
+
"cors": "2.8.5",
|
|
40
|
+
"express": "4.21.2",
|
|
41
|
+
"express-rate-limit": "7.5.0",
|
|
42
|
+
"express-session": "1.18.1",
|
|
43
|
+
"helmet": "8.1.0",
|
|
44
|
+
"multer": "^1.4.5-lts.2",
|
|
45
|
+
"xss-clean": "0.1.4"
|
|
46
|
+
}
|
|
47
|
+
}
|