@tiledesk/tiledesk-server 2.14.23 → 2.14.25
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/CHANGELOG.md +12 -1
- package/middleware/file-type.js +50 -3
- package/package.json +1 -1
- package/routes/files.js +16 -14
- package/routes/filesp.js +36 -1
- package/routes/images.js +221 -216
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,18 @@
|
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
# 2.14.25
|
|
10
|
+
- Deprecate user file upload routes in files.js and images.js
|
|
11
|
+
|
|
12
|
+
# 2.14.24
|
|
13
|
+
- Improved extension management on file uploading to support .wav and .svg
|
|
14
|
+
|
|
15
|
+
# 2.14.23
|
|
16
|
+
- Updated whatsapp-connector to 1.0.22
|
|
17
|
+
- Added new endpoint for files uploading
|
|
18
|
+
|
|
19
|
+
# 2.14.22 - aborted
|
|
9
20
|
- Updated whatsapp-connector to 1.0.20
|
|
10
21
|
- Added new endpoint for files uploading
|
|
11
22
|
|
package/middleware/file-type.js
CHANGED
|
@@ -4,9 +4,46 @@ const fs = require('fs');
|
|
|
4
4
|
// List of text-based MIME types that FileType cannot detect (they don't have binary signatures)
|
|
5
5
|
const TEXT_MIME_TYPES = [
|
|
6
6
|
'text/plain',
|
|
7
|
-
'text/csv'
|
|
7
|
+
'text/csv',
|
|
8
|
+
'image/svg+xml',
|
|
9
|
+
'application/xml',
|
|
10
|
+
'text/xml'
|
|
8
11
|
];
|
|
9
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Checks if two MIME types are equivalent, accepting common aliases
|
|
15
|
+
* Examples:
|
|
16
|
+
* - audio/wav === audio/wave === audio/vnd.wave
|
|
17
|
+
* - image/jpeg === image/jpg
|
|
18
|
+
*/
|
|
19
|
+
function areMimeTypesEquivalent(mimeType1, mimeType2) {
|
|
20
|
+
if (!mimeType1 || !mimeType2) return false;
|
|
21
|
+
if (mimeType1 === mimeType2) return true;
|
|
22
|
+
|
|
23
|
+
// Normalize to lowercase for comparison
|
|
24
|
+
const m1 = mimeType1.toLowerCase();
|
|
25
|
+
const m2 = mimeType2.toLowerCase();
|
|
26
|
+
if (m1 === m2) return true;
|
|
27
|
+
|
|
28
|
+
// Common MIME type aliases
|
|
29
|
+
const aliases = {
|
|
30
|
+
'audio/wav': ['audio/wave', 'audio/x-wav', 'audio/vnd.wave'],
|
|
31
|
+
'audio/wave': ['audio/wav', 'audio/x-wav', 'audio/vnd.wave'],
|
|
32
|
+
'audio/x-wav': ['audio/wav', 'audio/wave', 'audio/vnd.wave'],
|
|
33
|
+
'audio/vnd.wave': ['audio/wav', 'audio/wave', 'audio/x-wav'],
|
|
34
|
+
'image/jpeg': ['image/jpg'],
|
|
35
|
+
'image/jpg': ['image/jpeg'],
|
|
36
|
+
'application/x-zip-compressed': ['application/zip'],
|
|
37
|
+
'application/zip': ['application/x-zip-compressed'],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Check if m1 is an alias of m2 or vice versa
|
|
41
|
+
if (aliases[m1] && aliases[m1].includes(m2)) return true;
|
|
42
|
+
if (aliases[m2] && aliases[m2].includes(m1)) return true;
|
|
43
|
+
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
10
47
|
async function verifyFileContent(buffer, mimetype) {
|
|
11
48
|
if (!buffer) throw new Error("No file provided");
|
|
12
49
|
|
|
@@ -26,6 +63,16 @@ async function verifyFileContent(buffer, mimetype) {
|
|
|
26
63
|
err.source = "FileContentVerification";
|
|
27
64
|
throw err;
|
|
28
65
|
}
|
|
66
|
+
} else if (mimetype && mimetype.startsWith('image/svg')) {
|
|
67
|
+
// Handle SVG files (can be image/svg+xml or variants)
|
|
68
|
+
try {
|
|
69
|
+
buffer.toString('utf8');
|
|
70
|
+
return true;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
const err = new Error(`File content is not valid text for mimetype: ${mimetype}`);
|
|
73
|
+
err.source = "FileContentVerification";
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
29
76
|
} else {
|
|
30
77
|
// For non-text files, FileType should be able to detect them
|
|
31
78
|
const err = new Error(`File content does not match mimetype. Detected: unknown, provided: ${mimetype}`);
|
|
@@ -34,8 +81,8 @@ async function verifyFileContent(buffer, mimetype) {
|
|
|
34
81
|
}
|
|
35
82
|
}
|
|
36
83
|
|
|
37
|
-
// If FileType detected a type, it must match the declared mimetype
|
|
38
|
-
if (mimetype && fileType.mime
|
|
84
|
+
// If FileType detected a type, it must match the declared mimetype (or be equivalent)
|
|
85
|
+
if (mimetype && !areMimeTypesEquivalent(fileType.mime, mimetype)) {
|
|
39
86
|
const err = new Error(`File content does not match mimetype. Detected: ${fileType.mime}, provided: ${mimetype}`);
|
|
40
87
|
err.source = "FileContentVerification";
|
|
41
88
|
throw err;
|
package/package.json
CHANGED
package/routes/files.js
CHANGED
|
@@ -38,15 +38,16 @@ curl -u andrea.leo@f21.it:123456 \
|
|
|
38
38
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
// DEPRECATED FROM VERSION 2.14.24
|
|
42
|
+
// router.post('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], upload.single('file'), (req, res, next) => {
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
// winston.verbose("files/users")
|
|
45
|
+
// return res.status(201).json({
|
|
46
|
+
// message: 'File uploded successfully',
|
|
47
|
+
// filename: req.file.filename
|
|
48
|
+
// });
|
|
48
49
|
|
|
49
|
-
});
|
|
50
|
+
// });
|
|
50
51
|
|
|
51
52
|
/*
|
|
52
53
|
curl \
|
|
@@ -57,13 +58,14 @@ curl \
|
|
|
57
58
|
|
|
58
59
|
*/
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
61
|
+
// DEPRECATED FROM VERSION 2.14.24
|
|
62
|
+
// router.post('/public', upload.single('file'), (req, res, next) => {
|
|
63
|
+
// winston.debug("files/public")
|
|
64
|
+
// return res.status(201).json({
|
|
65
|
+
// message: 'File uploded successfully',
|
|
66
|
+
// filename: req.file.filename
|
|
67
|
+
// });
|
|
68
|
+
// });
|
|
67
69
|
|
|
68
70
|
|
|
69
71
|
|
package/routes/filesp.js
CHANGED
|
@@ -83,7 +83,7 @@ const fileFilter = (extensionsSource = 'chat') => {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
const expectedMimeType = mime.lookup(ext);
|
|
86
|
-
if (expectedMimeType && file.mimetype
|
|
86
|
+
if (expectedMimeType && !areMimeTypesEquivalent(file.mimetype, expectedMimeType)) {
|
|
87
87
|
const error = new Error(`File content does not match mimetype. Detected: ${file.mimetype}, provided: ${expectedMimeType}`);
|
|
88
88
|
error.status = 403;
|
|
89
89
|
return cb(error);
|
|
@@ -102,6 +102,41 @@ function getMimeTypes(allowed_extension) {
|
|
|
102
102
|
return allowedMimeTypes;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Checks if two MIME types are equivalent, accepting common aliases
|
|
107
|
+
* Examples:
|
|
108
|
+
* - audio/wav === audio/wave
|
|
109
|
+
* - audio/x-wav === audio/wave
|
|
110
|
+
* - image/jpeg === image/jpg
|
|
111
|
+
*/
|
|
112
|
+
function areMimeTypesEquivalent(mimeType1, mimeType2) {
|
|
113
|
+
if (!mimeType1 || !mimeType2) return false;
|
|
114
|
+
if (mimeType1 === mimeType2) return true;
|
|
115
|
+
|
|
116
|
+
// Normalize to lowercase for comparison
|
|
117
|
+
const m1 = mimeType1.toLowerCase();
|
|
118
|
+
const m2 = mimeType2.toLowerCase();
|
|
119
|
+
if (m1 === m2) return true;
|
|
120
|
+
|
|
121
|
+
// Common MIME type aliases
|
|
122
|
+
const aliases = {
|
|
123
|
+
'audio/wav': ['audio/wave', 'audio/x-wav', 'audio/vnd.wave'],
|
|
124
|
+
'audio/wave': ['audio/wav', 'audio/x-wav', 'audio/vnd.wave'],
|
|
125
|
+
'audio/x-wav': ['audio/wav', 'audio/wave', 'audio/vnd.wave'],
|
|
126
|
+
'audio/vnd.wave': ['audio/wav', 'audio/wave', 'audio/x-wav'],
|
|
127
|
+
'image/jpeg': ['image/jpg'],
|
|
128
|
+
'image/jpg': ['image/jpeg'],
|
|
129
|
+
'application/x-zip-compressed': ['application/zip'],
|
|
130
|
+
'application/zip': ['application/x-zip-compressed'],
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Check if m1 is an alias of m2 or vice versa
|
|
134
|
+
if (aliases[m1] && aliases[m1].includes(m2)) return true;
|
|
135
|
+
if (aliases[m2] && aliases[m2].includes(m1)) return true;
|
|
136
|
+
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
105
140
|
const uploadChat = multer({
|
|
106
141
|
storage: fileService.getStorage("files"),
|
|
107
142
|
fileFilter: fileFilter('chat'),
|
package/routes/images.js
CHANGED
|
@@ -68,40 +68,41 @@ curl -u andrea.leo@f21.it:123456 \
|
|
|
68
68
|
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
71
|
+
// DEPRECATED FROM VERSION 2.14.24
|
|
72
|
+
// router.post('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken],
|
|
73
|
+
// // bodymiddleware,
|
|
74
|
+
// upload.single('file'), (req, res, next) => {
|
|
75
|
+
// try {
|
|
76
|
+
// // winston.info("req.query.folder1:"+req.body.folder);
|
|
77
|
+
|
|
78
|
+
// var folder = req.folder || "error";
|
|
79
|
+
// winston.debug("folder:"+folder);
|
|
80
|
+
|
|
81
|
+
// var destinationFolder = 'uploads/users/' + req.user.id + "/images/" + folder +"/";
|
|
82
|
+
// winston.debug("destinationFolder",destinationFolder);
|
|
83
|
+
|
|
84
|
+
// var thumFilename = destinationFolder+'thumbnails_200_200-' + req.file.originalname;
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
// fileService.getFileDataAsBuffer(req.file.filename).then(function(buffer) {
|
|
88
|
+
|
|
89
|
+
// sharp(buffer).resize(200, 200).toBuffer((err, resizeImage, info) => {
|
|
90
|
+
// //in prod nn genera thumb
|
|
91
|
+
// if (err) { winston.error("Error generating thumbnail", err); }
|
|
92
|
+
// fileService.createFile ( thumFilename, resizeImage, undefined, undefined);
|
|
93
|
+
// });
|
|
94
|
+
|
|
95
|
+
// return res.status(201).json({
|
|
96
|
+
// message: 'Image uploded successfully',
|
|
97
|
+
// filename: encodeURIComponent(req.file.filename),
|
|
98
|
+
// thumbnail: encodeURIComponent(thumFilename)
|
|
99
|
+
// });
|
|
100
|
+
// });
|
|
101
|
+
// } catch (error) {
|
|
102
|
+
// winston.error('Error uploading user image.',error);
|
|
103
|
+
// return res.status(500).send({success: false, msg: 'Error uploading user image.'});
|
|
104
|
+
// }
|
|
105
|
+
// });
|
|
105
106
|
|
|
106
107
|
|
|
107
108
|
|
|
@@ -121,46 +122,48 @@ curl -v -X PUT -u andrea.leo@f21.it:123456 \
|
|
|
121
122
|
https://tiledesk-server-pre.herokuapp.com/images/users/
|
|
122
123
|
|
|
123
124
|
*/
|
|
124
|
-
router.put('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken],
|
|
125
|
-
// bodymiddleware,
|
|
126
|
-
uploadFixedFolder.single('file'), (req, res, next) => {
|
|
127
|
-
try {
|
|
128
|
-
winston.debug("/users/folder");
|
|
129
|
-
// winston.info("req.query.folder1:"+req.body.folder);
|
|
130
|
-
|
|
131
|
-
// var folder = req.folder || "error";
|
|
132
|
-
// winston.info("folder:"+folder);
|
|
133
|
-
|
|
134
|
-
if (req.upload_file_already_exists) {
|
|
135
|
-
winston.warn('Error uploading photo image, file already exists',req.file.filename );
|
|
136
|
-
return res.status(409).send({success: false, msg: 'Error uploading user image, file already exists'});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
var destinationFolder = 'uploads/users/' + req.user.id + "/images/";
|
|
140
|
-
winston.debug("destinationFolder",destinationFolder);
|
|
141
|
-
|
|
142
|
-
var thumFilename = destinationFolder+'thumbnails_200_200-' + req.file.originalname;
|
|
143
125
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
126
|
+
// DEPRECATED FROM VERSION 2.14.24
|
|
127
|
+
// router.put('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken],
|
|
128
|
+
// // bodymiddleware,
|
|
129
|
+
// uploadFixedFolder.single('file'), (req, res, next) => {
|
|
130
|
+
// try {
|
|
131
|
+
// winston.debug("/users/folder");
|
|
132
|
+
// // winston.info("req.query.folder1:"+req.body.folder);
|
|
133
|
+
|
|
134
|
+
// // var folder = req.folder || "error";
|
|
135
|
+
// // winston.info("folder:"+folder);
|
|
136
|
+
|
|
137
|
+
// if (req.upload_file_already_exists) {
|
|
138
|
+
// winston.warn('Error uploading photo image, file already exists',req.file.filename );
|
|
139
|
+
// return res.status(409).send({success: false, msg: 'Error uploading user image, file already exists'});
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// var destinationFolder = 'uploads/users/' + req.user.id + "/images/";
|
|
143
|
+
// winston.debug("destinationFolder",destinationFolder);
|
|
144
|
+
|
|
145
|
+
// var thumFilename = destinationFolder+'thumbnails_200_200-' + req.file.originalname;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
// fileService.getFileDataAsBuffer(req.file.filename).then(function(buffer) {
|
|
149
|
+
|
|
150
|
+
// sharp(buffer).resize(200, 200).toBuffer((err, resizeImage, info) => {
|
|
151
|
+
// //in prod nn genera thumb
|
|
152
|
+
// if (err) { winston.error("Error generating thumbnail", err); }
|
|
153
|
+
// fileService.createFile ( thumFilename, resizeImage, undefined, undefined);
|
|
154
|
+
// });
|
|
155
|
+
|
|
156
|
+
// return res.status(201).json({
|
|
157
|
+
// message: 'Image uploded successfully',
|
|
158
|
+
// filename: encodeURIComponent(req.file.filename),
|
|
159
|
+
// thumbnail: encodeURIComponent(thumFilename)
|
|
160
|
+
// });
|
|
161
|
+
// });
|
|
162
|
+
// } catch (error) {
|
|
163
|
+
// winston.error('Error uploading user image.',error);
|
|
164
|
+
// return res.status(500).send({success: false, msg: 'Error uploading user image.'});
|
|
165
|
+
// }
|
|
166
|
+
// });
|
|
164
167
|
|
|
165
168
|
|
|
166
169
|
|
|
@@ -186,81 +189,82 @@ curl -v -X PUT -u andrea.leo@f21.it:123456 \
|
|
|
186
189
|
https://tiledesk-server-pre.herokuapp.com/images/users/photo
|
|
187
190
|
|
|
188
191
|
*/
|
|
189
|
-
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
192
|
+
// DEPRECATED FROM VERSION 2.14.24
|
|
193
|
+
// router.put('/users/photo', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken],
|
|
194
|
+
// // bodymiddleware,
|
|
195
|
+
// uploadAvatar.single('file'), async (req, res, next) => {
|
|
196
|
+
// try {
|
|
197
|
+
// winston.debug("/users/photo");
|
|
198
|
+
|
|
199
|
+
// if (req.upload_file_already_exists) {
|
|
200
|
+
// winston.warn('Error uploading photo image, file already exists',req.file.filename );
|
|
201
|
+
// return res.status(409).send({success: false, msg: 'Error uploading photo image, file already exists'});
|
|
202
|
+
// }
|
|
203
|
+
|
|
204
|
+
// let userid = req.user.id;
|
|
205
|
+
// let bot_id;
|
|
206
|
+
// let entity_id = userid;
|
|
207
|
+
|
|
208
|
+
// // if (req.query.user_id) {
|
|
209
|
+
// // userid = req.query.user_id;
|
|
210
|
+
// // }
|
|
207
211
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
});
|
|
212
|
+
// if (req.query.bot_id) {
|
|
213
|
+
// bot_id = req.query.bot_id;
|
|
214
|
+
|
|
215
|
+
// let chatbot = await faq_kb.findById(bot_id).catch((err) => {
|
|
216
|
+
// winston.error("Error finding bot ", err);
|
|
217
|
+
// return res.status(500).send({ success: false, error: "Unable to find chatbot with id " + bot_id });
|
|
218
|
+
// })
|
|
219
|
+
|
|
220
|
+
// if (!chatbot) {
|
|
221
|
+
// return res.status(404).send({ success: false, error: "Chatbot not found" })
|
|
222
|
+
// }
|
|
223
|
+
|
|
224
|
+
// let id_project = chatbot.id_project;
|
|
225
|
+
|
|
226
|
+
// let puser = await project_user.findOne({ id_user: userid, id_project: id_project }).catch((err) => {
|
|
227
|
+
// winston.error("Error finding project user: ", err);
|
|
228
|
+
// return res.status(500).send({ success: false, error: "Unable to find project user for user " + userid + "in project " + id_project });
|
|
229
|
+
// })
|
|
230
|
+
// if (!puser) {
|
|
231
|
+
// winston.warn("User" + userid + "don't belongs the project " + id_project);
|
|
232
|
+
// return res.status(401).send({ success: false, error: "You don't belong the chatbot's project" })
|
|
233
|
+
// }
|
|
234
|
+
|
|
235
|
+
// if ((puser.role !== roleConstants.ADMIN) && (puser.role !== roleConstants.OWNER)) {
|
|
236
|
+
// winston.warn("User with role " + puser.role + "can't modify the chatbot");
|
|
237
|
+
// return res.status(403).send({ success: false, error: "You don't have the role required to modify the chatbot" });
|
|
238
|
+
// }
|
|
239
|
+
|
|
240
|
+
// entity_id = bot_id;
|
|
241
|
+
// }
|
|
242
|
+
|
|
243
|
+
// var destinationFolder = 'uploads/users/' + entity_id + "/images/";
|
|
244
|
+
// winston.debug("destinationFolder:"+destinationFolder);
|
|
245
|
+
|
|
246
|
+
// var thumFilename = destinationFolder+'thumbnails_200_200-photo.jpg';
|
|
247
|
+
|
|
248
|
+
// winston.debug("req.file.filename:"+req.file.filename);
|
|
249
|
+
// fileService.getFileDataAsBuffer(req.file.filename).then(function(buffer) {
|
|
250
|
+
|
|
251
|
+
// sharp(buffer).resize(200, 200).toBuffer((err, resizeImage, info) => {
|
|
252
|
+
// //in prod nn genera thumb
|
|
253
|
+
// if (err) { winston.error("Error generating thumbnail", err); }
|
|
254
|
+
// fileService.createFile ( thumFilename, resizeImage, undefined, undefined);
|
|
255
|
+
// });
|
|
256
|
+
|
|
257
|
+
// return res.status(201).json({
|
|
258
|
+
// message: 'Image uploded successfully',
|
|
259
|
+
// filename: encodeURIComponent(req.file.filename),
|
|
260
|
+
// thumbnail: encodeURIComponent(thumFilename)
|
|
261
|
+
// });
|
|
262
|
+
// });
|
|
263
|
+
// } catch (error) {
|
|
264
|
+
// winston.error('Error uploading user image.',error);
|
|
265
|
+
// return res.status(500).send({success: false, msg: 'Error uploading user image.'});
|
|
266
|
+
// }
|
|
267
|
+
// });
|
|
264
268
|
|
|
265
269
|
|
|
266
270
|
|
|
@@ -276,57 +280,57 @@ curl -v -X DELETE -u andrea.leo@frontiere21.it:123 \
|
|
|
276
280
|
|
|
277
281
|
*/
|
|
278
282
|
|
|
279
|
-
router.delete('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], (req, res, next) => {
|
|
280
|
-
|
|
281
|
-
|
|
283
|
+
// router.delete('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], (req, res, next) => {
|
|
284
|
+
// try {
|
|
285
|
+
// winston.debug("delete /users");
|
|
282
286
|
|
|
283
|
-
|
|
284
|
-
|
|
287
|
+
// let path = req.query.path;
|
|
288
|
+
// winston.debug("path:"+path);
|
|
285
289
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
// // TODO later if enabled there is problem when admin delete a bot image
|
|
291
|
+
// // if (path.indexOf("/"+req.user.id+"/")==-1) {
|
|
292
|
+
// // winston.warn('Permission denied to delete image:'+path);
|
|
293
|
+
// // return res.status(403).send({success: false, msg: 'Permission denied to delete image:'+path});
|
|
294
|
+
// // }
|
|
291
295
|
|
|
292
|
-
|
|
293
|
-
|
|
296
|
+
// let filename = pathlib.basename(path);
|
|
297
|
+
// winston.debug("filename:"+filename);
|
|
294
298
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
+
// if (!filename) {
|
|
300
|
+
// winston.warn('Error delete image. No filename specified:'+path);
|
|
301
|
+
// return res.status(500).send({success: false, msg: 'Error delete image. No filename specified:'+path});
|
|
302
|
+
// }
|
|
299
303
|
|
|
300
304
|
|
|
301
305
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
});
|
|
306
|
+
// fileService.deleteFile(path).then(function(data) {
|
|
307
|
+
|
|
308
|
+
// let thumbFilename = 'thumbnails_200_200-'+filename;
|
|
309
|
+
// winston.debug("thumbFilename:"+thumbFilename);
|
|
310
|
+
|
|
311
|
+
// let thumbPath = path.replace(filename,thumbFilename);
|
|
312
|
+
// winston.debug("thumbPath:"+thumbPath);
|
|
313
|
+
|
|
314
|
+
// fileService.deleteFile(thumbPath).then(function(data) {
|
|
315
|
+
// winston.debug("thumbFilename deleted:"+thumbPath);
|
|
316
|
+
// }).catch(function(error) {
|
|
317
|
+
// winston.error('Error deleting thumbnail image.',error);
|
|
318
|
+
// });
|
|
319
|
+
|
|
320
|
+
// return res.status(200).json({
|
|
321
|
+
// message: 'Image deleted successfully',
|
|
322
|
+
// filename: encodeURIComponent(data.filename)
|
|
323
|
+
// });
|
|
324
|
+
// }).catch(function(error) {
|
|
325
|
+
// winston.error('Error deleting image.',error);
|
|
326
|
+
// return res.status(500).send({success: false, msg: 'Error deleting image.'});
|
|
327
|
+
// });
|
|
328
|
+
|
|
329
|
+
// } catch (error) {
|
|
330
|
+
// winston.error('Error deleting image.',error);
|
|
331
|
+
// return res.status(500).send({success: false, msg: 'Error deleting image.'});
|
|
332
|
+
// }
|
|
333
|
+
// });
|
|
330
334
|
|
|
331
335
|
|
|
332
336
|
/*
|
|
@@ -397,42 +401,43 @@ curl -v -X POST -H 'Content-Type: multipart/form-data' -F "file=@/Users/andreale
|
|
|
397
401
|
curl -v -X POST -H 'Content-Type: multipart/form-data' -F "file=@/Users/andrealeo/dev/chat21/tiledesk-server-dev-org/test.jpg" https://tiledesk-server-pre.herokuapp.com/images/public/
|
|
398
402
|
*/
|
|
399
403
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
404
|
+
// DEPRECATED FROM VERSION 2.14.24
|
|
405
|
+
// router.post('/public', upload.single('file'), (req, res, next) => {
|
|
406
|
+
// try {
|
|
407
|
+
// winston.debug("req",req);
|
|
408
|
+
// var folder = req.folder || "error";
|
|
409
|
+
// winston.debug("folder",folder);
|
|
405
410
|
|
|
406
|
-
|
|
407
|
-
|
|
411
|
+
// var destinationFolder = "uploads/public/images/" + folder +"/";
|
|
412
|
+
// winston.debug("destinationFolder",destinationFolder);
|
|
408
413
|
|
|
409
|
-
|
|
414
|
+
// winston.debug("req.file.filename",req.file.filename);
|
|
410
415
|
|
|
411
|
-
|
|
416
|
+
// var thumFilename = destinationFolder+'thumbnails_200_200-' + req.file.originalname;
|
|
412
417
|
|
|
413
418
|
|
|
414
|
-
|
|
419
|
+
// fileService.getFileDataAsBuffer(req.file.filename).then(function(buffer) {
|
|
415
420
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
421
|
+
// sharp(buffer).resize(200, 200).toBuffer((err, resizeImage, info) => {
|
|
422
|
+
// if (err) { winston.error("Error generating thumbnail", err); }
|
|
423
|
+
// fileService.createFile ( thumFilename, resizeImage, undefined, undefined);
|
|
424
|
+
// });
|
|
420
425
|
|
|
421
426
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
427
|
+
// return res.status(201).json({
|
|
428
|
+
// message: 'Image uploded successfully',
|
|
429
|
+
// filename: encodeURIComponent(req.file.filename),
|
|
430
|
+
// thumbnail: encodeURIComponent(thumFilename)
|
|
431
|
+
// });
|
|
432
|
+
// });
|
|
428
433
|
|
|
429
434
|
|
|
430
435
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
});
|
|
436
|
+
// } catch (error) {
|
|
437
|
+
// winston.error('Error deleting public image.',error);
|
|
438
|
+
// return res.status(500).send({success: false, msg: 'Error deleting public image.'});
|
|
439
|
+
// }
|
|
440
|
+
// });
|
|
436
441
|
|
|
437
442
|
|
|
438
443
|
// router.use('/uploads', express.static(path.join(__dirname, '/uploads')));
|