@reldens/server-utils 0.8.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.
@@ -37,10 +37,7 @@ class FileHandler
37
37
  return false;
38
38
  }
39
39
  let pathStr = String(filePath);
40
- if(pathStr.includes('../') || pathStr.includes('..\\')){
41
- return false;
42
- }
43
- return true;
40
+ return !(pathStr.includes('../') || pathStr.includes('..\\'));
44
41
  }
45
42
 
46
43
  sanitizePath(filePath)
@@ -48,11 +45,10 @@ class FileHandler
48
45
  if(!filePath){
49
46
  return '';
50
47
  }
51
- let sanitized = String(filePath)
48
+ return String(filePath)
52
49
  .replace(/\.\./g, '')
53
50
  .replace(/[:*?"<>|]/g, '')
54
51
  .substring(0, 255);
55
- return sanitized;
56
52
  }
57
53
 
58
54
  generateSecureFilename(originalName)
@@ -35,16 +35,18 @@ class UploaderFactory
35
35
  cb(null, dest);
36
36
  }
37
37
  };
38
- if(this.applySecureFileNames){
39
- diskStorageConfiguration['filename'] = (req, file, cb) => {
40
- let secureFilename = FileHandler.generateSecureFilename(file.originalname);
41
- if(!req.fileNameMapping){
42
- req.fileNameMapping = {};
43
- }
44
- req.fileNameMapping[secureFilename] = file.originalname;
45
- cb(null, secureFilename);
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
- console.error('File validation error:', error);
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(err){
163
- console.error('Error validating file contents:', err);
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(err){
191
- console.error('Error cleaning up file:', file.path, err);
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.8.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
- }
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
+ }