@unchainedshop/plugins 2.0.3 → 2.0.5
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.
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { Context } from '@unchainedshop/types/api.js';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { configureGridFSFileUploadModule } from './index.js';
|
|
4
|
+
export declare const gridfsHandler: (req: express.Request & {
|
|
5
|
+
unchainedContext: Context & {
|
|
6
|
+
modules: {
|
|
7
|
+
gridfsFileUploads: ReturnType<typeof configureGridFSFileUploadModule>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}, res: express.Response) => Promise<void>;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
2
2
|
import { buildHashedFilename } from '@unchainedshop/file-upload';
|
|
3
|
-
import { pipeline
|
|
4
|
-
import { promisify } from 'util';
|
|
3
|
+
import { pipeline, finished } from 'stream/promises';
|
|
5
4
|
import sign from './sign.js';
|
|
6
|
-
const pipeline = promisify(rawPipeline);
|
|
7
5
|
const { ROOT_URL } = process.env;
|
|
8
6
|
export const gridfsHandler = async (req, res) => {
|
|
9
7
|
try {
|
|
@@ -17,38 +15,45 @@ export const gridfsHandler = async (req, res) => {
|
|
|
17
15
|
if (sign(directoryName, fileId, expiryDate.getTime()) === signature) {
|
|
18
16
|
const file = await modules.files.findFile({ fileId });
|
|
19
17
|
if (file.expires === null) {
|
|
20
|
-
res.
|
|
18
|
+
res.statusCode = 400;
|
|
21
19
|
res.end('File already linked');
|
|
22
20
|
return;
|
|
23
21
|
}
|
|
24
22
|
const writeStream = await modules.gridfsFileUploads.createWriteStream(directoryName, fileId, fileName);
|
|
25
|
-
res.writeHead(200);
|
|
26
23
|
await pipeline(req, writeStream);
|
|
27
24
|
const { length } = writeStream;
|
|
28
|
-
|
|
25
|
+
res.statusCode = 200;
|
|
26
|
+
await services.files.linkFile({ fileId, size: length, type: req.header('Content-Type') }, req.unchainedContext);
|
|
29
27
|
res.end();
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
32
|
-
res.
|
|
30
|
+
res.statusCode = 403;
|
|
33
31
|
res.end();
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
36
34
|
if (req.method === 'GET') {
|
|
37
35
|
const fileId = fileName;
|
|
38
36
|
const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
|
|
39
|
-
res.
|
|
40
|
-
|
|
37
|
+
res.statusCode = 200;
|
|
38
|
+
readStream.pipe(res, { end: false });
|
|
39
|
+
await finished(readStream);
|
|
41
40
|
res.end();
|
|
42
41
|
return;
|
|
43
42
|
}
|
|
44
|
-
res.
|
|
43
|
+
res.statusCode = 404;
|
|
45
44
|
res.end();
|
|
46
45
|
return;
|
|
47
46
|
}
|
|
48
47
|
catch (e) {
|
|
49
48
|
log(e.message, { level: LogLevel.Error });
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (e.code === 'ENOENT') {
|
|
50
|
+
res.statusCode = 404;
|
|
51
|
+
res.end();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
res.statusCode = 503;
|
|
55
|
+
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
56
|
+
}
|
|
52
57
|
}
|
|
53
58
|
};
|
|
54
59
|
//# sourceMappingURL=gridfs-webhook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gridfs-webhook.js","sourceRoot":"","sources":["../../../src/files/gridfs/gridfs-webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"gridfs-webhook.js","sourceRoot":"","sources":["../../../src/files/gridfs/gridfs-webhook.ts"],"names":[],"mapp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AAC,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE;YACvB,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,EAAE,CAAC;SACX;aAAM;YACL,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;SAC7E;KACF;AACH,CAAC,CAAC"}
|
package/lib/worker/message.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IWorkerAdapter, Work } from '@unchainedshop/types/worker.js';
|
|
2
|
-
export declare const messagingLogger:
|
|
2
|
+
export declare const messagingLogger: any;
|
|
3
3
|
export declare const MessageWorker: IWorkerAdapter<{
|
|
4
4
|
template: string;
|
|
5
5
|
_id?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"main": "lib/plugins-index.js",
|
|
5
5
|
"types": "lib/plugins-index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -75,33 +75,33 @@
|
|
|
75
75
|
"express": "^4.18.2"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@types/node": "^18.
|
|
79
|
-
"@unchainedshop/api": "^2.0.
|
|
80
|
-
"@unchainedshop/core-delivery": "^2.0.
|
|
81
|
-
"@unchainedshop/core-enrollments": "^2.0.
|
|
82
|
-
"@unchainedshop/core-filters": "^2.0.
|
|
83
|
-
"@unchainedshop/core-messaging": "^2.0.
|
|
84
|
-
"@unchainedshop/core-orders": "^2.0.
|
|
85
|
-
"@unchainedshop/core-payment": "^2.0.
|
|
86
|
-
"@unchainedshop/core-products": "^2.0.
|
|
87
|
-
"@unchainedshop/core-quotations": "^2.0.
|
|
88
|
-
"@unchainedshop/core-warehousing": "^2.0.
|
|
89
|
-
"@unchainedshop/core-worker": "^2.0.
|
|
90
|
-
"@unchainedshop/events": "^2.0.
|
|
91
|
-
"@unchainedshop/file-upload": "^2.0.
|
|
92
|
-
"@unchainedshop/logger": "^2.0.
|
|
93
|
-
"@unchainedshop/types": "^2.0.
|
|
94
|
-
"@unchainedshop/utils": "^2.0.
|
|
78
|
+
"@types/node": "^18.13.0",
|
|
79
|
+
"@unchainedshop/api": "^2.0.4",
|
|
80
|
+
"@unchainedshop/core-delivery": "^2.0.4",
|
|
81
|
+
"@unchainedshop/core-enrollments": "^2.0.4",
|
|
82
|
+
"@unchainedshop/core-filters": "^2.0.4",
|
|
83
|
+
"@unchainedshop/core-messaging": "^2.0.4",
|
|
84
|
+
"@unchainedshop/core-orders": "^2.0.4",
|
|
85
|
+
"@unchainedshop/core-payment": "^2.0.4",
|
|
86
|
+
"@unchainedshop/core-products": "^2.0.4",
|
|
87
|
+
"@unchainedshop/core-quotations": "^2.0.4",
|
|
88
|
+
"@unchainedshop/core-warehousing": "^2.0.4",
|
|
89
|
+
"@unchainedshop/core-worker": "^2.0.4",
|
|
90
|
+
"@unchainedshop/events": "^2.0.4",
|
|
91
|
+
"@unchainedshop/file-upload": "^2.0.4",
|
|
92
|
+
"@unchainedshop/logger": "^2.0.4",
|
|
93
|
+
"@unchainedshop/types": "^2.0.4",
|
|
94
|
+
"@unchainedshop/utils": "^2.0.4",
|
|
95
95
|
"bluebird": "^3.7.2",
|
|
96
96
|
"event-iterator": "^2.0.0",
|
|
97
97
|
"express": "^4.18.2",
|
|
98
|
-
"jest": "^29.4.
|
|
98
|
+
"jest": "^29.4.2",
|
|
99
99
|
"JSONStream": "^1.3.5",
|
|
100
100
|
"minio": "^7.0.32",
|
|
101
|
-
"mongodb": "^4.
|
|
101
|
+
"mongodb": "^4.14.0",
|
|
102
102
|
"node-sheets": "^1.2.0",
|
|
103
103
|
"nodemailer": "^6.9.1",
|
|
104
|
-
"open": "^8.4.
|
|
104
|
+
"open": "^8.4.1",
|
|
105
105
|
"redis": "^4.6.4",
|
|
106
106
|
"request": "^2.88.2",
|
|
107
107
|
"stripe": "^10.17.0",
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
2
2
|
import { buildHashedFilename } from '@unchainedshop/file-upload';
|
|
3
|
-
import { pipeline
|
|
4
|
-
import {
|
|
3
|
+
import { pipeline, finished } from 'stream/promises';
|
|
4
|
+
import { Context } from '@unchainedshop/types/api.js';
|
|
5
|
+
import express from 'express';
|
|
5
6
|
import sign from './sign.js';
|
|
6
|
-
|
|
7
|
-
const pipeline = promisify(rawPipeline);
|
|
7
|
+
import { configureGridFSFileUploadModule } from './index.js';
|
|
8
8
|
|
|
9
9
|
const { ROOT_URL } = process.env;
|
|
10
10
|
|
|
11
|
-
export const gridfsHandler = async (
|
|
11
|
+
export const gridfsHandler = async (
|
|
12
|
+
req: express.Request & {
|
|
13
|
+
unchainedContext: Context & {
|
|
14
|
+
modules: { gridfsFileUploads: ReturnType<typeof configureGridFSFileUploadModule> };
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
res: express.Response,
|
|
18
|
+
) => {
|
|
12
19
|
try {
|
|
13
20
|
const { services, modules } = req.unchainedContext;
|
|
14
21
|
const url = new URL(req.url, ROOT_URL);
|
|
@@ -16,12 +23,12 @@ export const gridfsHandler = async (req, res) => {
|
|
|
16
23
|
|
|
17
24
|
if (req.method === 'PUT') {
|
|
18
25
|
const { s: signature, e: expiryTimestamp } = req.query;
|
|
19
|
-
const expiryDate = new Date(parseInt(expiryTimestamp, 10));
|
|
26
|
+
const expiryDate = new Date(parseInt(expiryTimestamp as string, 10));
|
|
20
27
|
const fileId = buildHashedFilename(directoryName, fileName, expiryDate);
|
|
21
28
|
if (sign(directoryName, fileId, expiryDate.getTime()) === signature) {
|
|
22
29
|
const file = await modules.files.findFile({ fileId });
|
|
23
30
|
if (file.expires === null) {
|
|
24
|
-
res.
|
|
31
|
+
res.statusCode = 400;
|
|
25
32
|
res.end('File already linked');
|
|
26
33
|
return;
|
|
27
34
|
}
|
|
@@ -30,31 +37,41 @@ export const gridfsHandler = async (req, res) => {
|
|
|
30
37
|
fileId,
|
|
31
38
|
fileName,
|
|
32
39
|
);
|
|
33
|
-
res.writeHead(200);
|
|
34
40
|
await pipeline(req, writeStream);
|
|
35
41
|
const { length } = writeStream;
|
|
36
|
-
|
|
42
|
+
res.statusCode = 200;
|
|
43
|
+
await services.files.linkFile(
|
|
44
|
+
{ fileId, size: length, type: req.header('Content-Type') },
|
|
45
|
+
req.unchainedContext,
|
|
46
|
+
);
|
|
37
47
|
res.end();
|
|
38
48
|
return;
|
|
39
49
|
}
|
|
40
|
-
res.
|
|
50
|
+
res.statusCode = 403;
|
|
41
51
|
res.end();
|
|
42
52
|
return;
|
|
43
53
|
}
|
|
54
|
+
|
|
44
55
|
if (req.method === 'GET') {
|
|
45
56
|
const fileId = fileName;
|
|
46
57
|
const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
|
|
47
|
-
res.
|
|
48
|
-
|
|
58
|
+
res.statusCode = 200;
|
|
59
|
+
readStream.pipe(res, { end: false });
|
|
60
|
+
await finished(readStream);
|
|
49
61
|
res.end();
|
|
50
62
|
return;
|
|
51
63
|
}
|
|
52
|
-
res.
|
|
64
|
+
res.statusCode = 404;
|
|
53
65
|
res.end();
|
|
54
66
|
return;
|
|
55
67
|
} catch (e) {
|
|
56
68
|
log(e.message, { level: LogLevel.Error });
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
if (e.code === 'ENOENT') {
|
|
70
|
+
res.statusCode = 404;
|
|
71
|
+
res.end();
|
|
72
|
+
} else {
|
|
73
|
+
res.statusCode = 503;
|
|
74
|
+
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
75
|
+
}
|
|
59
76
|
}
|
|
60
77
|
};
|