@tiledesk/tiledesk-server 2.14.17 → 2.14.19
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 +7 -0
- package/app.js +2 -0
- package/middleware/file-type.js +50 -0
- package/middleware/passport.js +531 -589
- package/models/analyticResult.js +2 -1
- package/package.json +3 -2
- package/routes/files.js +75 -18
- package/routes/filesp.js +545 -0
- package/routes/llm.js +1 -1
- package/services/fileGridFsService.js +195 -6
- package/test/fileFilter.test.js +194 -0
- package/test/filepRoute.js +561 -0
- package/test/fixtures/avatar.jpg +0 -0
- package/test/fixtures/fake.pdf +8 -0
- package/test/fixtures/sample.xyz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
|
7
7
|
|
|
8
|
+
# 2.14.19
|
|
9
|
+
- Updated whatsapp-connector to 1.0.19
|
|
10
|
+
- Added new endpoint for files uploading
|
|
11
|
+
|
|
12
|
+
# 2.14.18
|
|
13
|
+
- Bug fix already existing email when login from google
|
|
14
|
+
|
|
8
15
|
# 2.14.17
|
|
9
16
|
- Bug fix google strategy passport
|
|
10
17
|
|
package/app.js
CHANGED
|
@@ -139,6 +139,7 @@ var cacheUtil = require("./utils/cacheUtil");
|
|
|
139
139
|
var orgUtil = require("./utils/orgUtil");
|
|
140
140
|
var images = require('./routes/images');
|
|
141
141
|
var files = require('./routes/files');
|
|
142
|
+
let filesp = require('./routes/filesp');
|
|
142
143
|
var campaigns = require('./routes/campaigns');
|
|
143
144
|
var logs = require('./routes/logs');
|
|
144
145
|
var requestUtilRoot = require('./routes/requestUtilRoot');
|
|
@@ -645,6 +646,7 @@ app.use('/:projectid/logs', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
645
646
|
app.use('/:projectid/webhooks', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], webhooks);
|
|
646
647
|
app.use('/:projectid/copilot', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('agent')], copilot);
|
|
647
648
|
|
|
649
|
+
app.use('/:projectid/files', filesp);
|
|
648
650
|
|
|
649
651
|
if (pubModulesManager) {
|
|
650
652
|
pubModulesManager.useUnderProjects(app);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const FileType = require('file-type');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
// List of text-based MIME types that FileType cannot detect (they don't have binary signatures)
|
|
5
|
+
const TEXT_MIME_TYPES = [
|
|
6
|
+
'text/plain',
|
|
7
|
+
'text/csv'
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
async function verifyFileContent(buffer, mimetype) {
|
|
11
|
+
if (!buffer) throw new Error("No file provided");
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const fileType = await FileType.fromBuffer(buffer);
|
|
15
|
+
|
|
16
|
+
// If FileType couldn't detect the file type (returns null/undefined)
|
|
17
|
+
if (!fileType) {
|
|
18
|
+
// For text-based MIME types, accept the declared mimetype since FileType can't detect them
|
|
19
|
+
if (mimetype && TEXT_MIME_TYPES.includes(mimetype)) {
|
|
20
|
+
// Optionally verify that the content is valid UTF-8 text
|
|
21
|
+
try {
|
|
22
|
+
buffer.toString('utf8');
|
|
23
|
+
return true;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
const err = new Error(`File content is not valid text for mimetype: ${mimetype}`);
|
|
26
|
+
err.source = "FileContentVerification";
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
// For non-text files, FileType should be able to detect them
|
|
31
|
+
const err = new Error(`File content does not match mimetype. Detected: unknown, provided: ${mimetype}`);
|
|
32
|
+
err.source = "FileContentVerification";
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// If FileType detected a type, it must match the declared mimetype
|
|
38
|
+
if (mimetype && fileType.mime !== mimetype) {
|
|
39
|
+
const err = new Error(`File content does not match mimetype. Detected: ${fileType.mime}, provided: ${mimetype}`);
|
|
40
|
+
err.source = "FileContentVerification";
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return true;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = verifyFileContent;
|