@things-factory/attachment-base 4.3.378 → 4.3.379
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/package.json +4 -4
- package/dist-server/attachment-const 2.js +0 -9
- package/dist-server/attachment-const.js 2.map +0 -1
- package/dist-server/awb-storage-s3 2.js +0 -42
- package/dist-server/awb-storage-s3.js 2.map +0 -1
- package/dist-server/index 2.js +0 -31
- package/dist-server/index.js 2.map +0 -1
- package/dist-server/invoice-storage-s3 3.js +0 -42
- package/dist-server/invoice-storage-s3.js 3.map +0 -1
- package/dist-server/routes 2.js +0 -23
- package/dist-server/routes.js 2.map +0 -1
- package/dist-server/storage-file 2.js +0 -74
- package/dist-server/storage-file.js 2.map +0 -1
- package/dist-server/storage-s3 2.js +0 -99
- package/dist-server/storage-s3.js 2.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/attachment-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.379",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"@aws-sdk/lib-storage": "^3.46.0",
|
|
28
28
|
"@aws-sdk/s3-presigned-post": "^3.46.0",
|
|
29
29
|
"@koa/multer": "^3.0.0",
|
|
30
|
-
"@things-factory/auth-base": "^4.3.
|
|
31
|
-
"@things-factory/env": "^4.3.
|
|
30
|
+
"@things-factory/auth-base": "^4.3.379",
|
|
31
|
+
"@things-factory/env": "^4.3.379",
|
|
32
32
|
"memfs": "^3.0.1",
|
|
33
33
|
"mime": "^2.4.4",
|
|
34
34
|
"multer": "^1.3.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "be80e8ec81dedb5706ebf0dd7d240ecd5ed0a67e"
|
|
37
37
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ATTACHMENT_PATH = exports.INVSTORAGE = exports.AWBSTORAGE = exports.STORAGE = void 0;
|
|
4
|
-
const env_1 = require("@things-factory/env");
|
|
5
|
-
exports.STORAGE = env_1.config.get('storage');
|
|
6
|
-
exports.AWBSTORAGE = env_1.config.get('awbFileStorage');
|
|
7
|
-
exports.INVSTORAGE = env_1.config.get('invoiceFileStorage');
|
|
8
|
-
exports.ATTACHMENT_PATH = env_1.config.get('attachmentPath', 'attachment');
|
|
9
|
-
//# sourceMappingURL=attachment-const.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-const.js","sourceRoot":"","sources":["../server/attachment-const.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAEjC,QAAA,OAAO,GAAQ,YAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AACpC,QAAA,UAAU,GAAQ,YAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;AAC9C,QAAA,UAAU,GAAQ,YAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;AAChD,QAAA,eAAe,GAAW,YAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAA"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
4
|
-
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
5
|
-
const env_1 = require("@things-factory/env");
|
|
6
|
-
const attachment_const_1 = require("./attachment-const");
|
|
7
|
-
if (attachment_const_1.AWBSTORAGE && attachment_const_1.AWBSTORAGE.type == 's3') {
|
|
8
|
-
const client = new client_s3_1.S3Client({
|
|
9
|
-
credentials: {
|
|
10
|
-
accessKeyId: attachment_const_1.AWBSTORAGE.accessKeyId,
|
|
11
|
-
secretAccessKey: attachment_const_1.AWBSTORAGE.secretAccessKey
|
|
12
|
-
},
|
|
13
|
-
region: attachment_const_1.AWBSTORAGE.region
|
|
14
|
-
});
|
|
15
|
-
/* upload file */
|
|
16
|
-
attachment_const_1.AWBSTORAGE.uploadFile = async ({ stream, filename }) => {
|
|
17
|
-
const upload = new lib_storage_1.Upload({
|
|
18
|
-
client,
|
|
19
|
-
params: {
|
|
20
|
-
Bucket: attachment_const_1.AWBSTORAGE.bucketName,
|
|
21
|
-
Key: `${filename}.pdf`,
|
|
22
|
-
Body: stream,
|
|
23
|
-
ContentType: 'application/pdf'
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
let result;
|
|
27
|
-
let url;
|
|
28
|
-
try {
|
|
29
|
-
result = (await upload.done());
|
|
30
|
-
url = `https://${attachment_const_1.AWBSTORAGE.bucketName}.s3.${attachment_const_1.AWBSTORAGE.region}.amazonaws.com/${filename}.pdf`;
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
console.log(e);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
result,
|
|
37
|
-
url
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
env_1.logger.info('operato-awb: S3 Bucket Storage is Ready.');
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=awb-storage-s3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"awb-storage-s3.js","sourceRoot":"","sources":["../server/awb-storage-s3.ts"],"names":[],"mappings":";;AAAA,kDAA6C;AAC7C,sDAA6C;AAC7C,6CAA4C;AAE5C,yDAA+C;AAE/C,IAAI,6BAAU,IAAI,6BAAU,CAAC,IAAI,IAAI,IAAI,EAAE;IACzC,MAAM,MAAM,GAAG,IAAI,oBAAQ,CAAC;QAC1B,WAAW,EAAE;YACX,WAAW,EAAE,6BAAU,CAAC,WAAW;YACnC,eAAe,EAAE,6BAAU,CAAC,eAAe;SAC5C;QACD,MAAM,EAAE,6BAAU,CAAC,MAAM;KAC1B,CAAC,CAAA;IAEF,iBAAiB;IACjB,6BAAU,CAAC,UAAU,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;QACrD,MAAM,MAAM,GAAG,IAAI,oBAAM,CAAC;YACxB,MAAM;YACN,MAAM,EAAE;gBACN,MAAM,EAAE,6BAAU,CAAC,UAAU;gBAC7B,GAAG,EAAE,GAAG,QAAQ,MAAM;gBACtB,IAAI,EAAE,MAAM;gBACZ,WAAW,EAAE,iBAAiB;aAC/B;SACF,CAAC,CAAA;QAEF,IAAI,MAAM,CAAA;QACV,IAAI,GAAG,CAAA;QACP,IAAI;YACF,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAQ,CAAA;YACrC,GAAG,GAAG,WAAW,6BAAU,CAAC,UAAU,OAAO,6BAAU,CAAC,MAAM,kBAAkB,QAAQ,MAAM,CAAA;SAC/F;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;SACf;QAED,OAAO;YACL,MAAM;YACN,GAAG;SACJ,CAAA;IACH,CAAC,CAAA;IAED,YAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAA;CACxD"}
|
package/dist-server/index 2.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.singleUpload = exports.multipleUpload = exports.deleteAttachmentsByRef = exports.deleteAttachment = exports.createAttachments = exports.createAttachment = void 0;
|
|
18
|
-
__exportStar(require("./attachment-const"), exports);
|
|
19
|
-
__exportStar(require("./migrations"), exports);
|
|
20
|
-
__exportStar(require("./service"), exports);
|
|
21
|
-
var attachment_mutation_1 = require("./service/attachment/attachment-mutation");
|
|
22
|
-
Object.defineProperty(exports, "createAttachment", { enumerable: true, get: function () { return attachment_mutation_1.createAttachment; } });
|
|
23
|
-
Object.defineProperty(exports, "createAttachments", { enumerable: true, get: function () { return attachment_mutation_1.createAttachments; } });
|
|
24
|
-
Object.defineProperty(exports, "deleteAttachment", { enumerable: true, get: function () { return attachment_mutation_1.deleteAttachment; } });
|
|
25
|
-
Object.defineProperty(exports, "deleteAttachmentsByRef", { enumerable: true, get: function () { return attachment_mutation_1.deleteAttachmentsByRef; } });
|
|
26
|
-
Object.defineProperty(exports, "multipleUpload", { enumerable: true, get: function () { return attachment_mutation_1.multipleUpload; } });
|
|
27
|
-
Object.defineProperty(exports, "singleUpload", { enumerable: true, get: function () { return attachment_mutation_1.singleUpload; } });
|
|
28
|
-
require("./routes");
|
|
29
|
-
__exportStar(require("./attachment-const"), exports);
|
|
30
|
-
__exportStar(require("./util"), exports);
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,+CAA4B;AAC5B,4CAAyB;AACzB,gFAOiD;AAN/C,uHAAA,gBAAgB,OAAA;AAChB,wHAAA,iBAAiB,OAAA;AACjB,uHAAA,gBAAgB,OAAA;AAChB,6HAAA,sBAAsB,OAAA;AACtB,qHAAA,cAAc,OAAA;AACd,mHAAA,YAAY,OAAA;AAGd,oBAAiB;AAEjB,qDAAkC;AAClC,yCAAsB"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
4
|
-
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
5
|
-
const env_1 = require("@things-factory/env");
|
|
6
|
-
const attachment_const_1 = require("./attachment-const");
|
|
7
|
-
if (attachment_const_1.INVSTORAGE && attachment_const_1.INVSTORAGE.type == 's3') {
|
|
8
|
-
const client = new client_s3_1.S3Client({
|
|
9
|
-
credentials: {
|
|
10
|
-
accessKeyId: attachment_const_1.INVSTORAGE.accessKeyId,
|
|
11
|
-
secretAccessKey: attachment_const_1.INVSTORAGE.secretAccessKey
|
|
12
|
-
},
|
|
13
|
-
region: attachment_const_1.INVSTORAGE.region
|
|
14
|
-
});
|
|
15
|
-
// Upload Invoice File
|
|
16
|
-
attachment_const_1.INVSTORAGE.uploadInvoiceS3 = async ({ stream, filename }) => {
|
|
17
|
-
const upload = new lib_storage_1.Upload({
|
|
18
|
-
client,
|
|
19
|
-
params: {
|
|
20
|
-
Bucket: attachment_const_1.INVSTORAGE.invoiceBucket,
|
|
21
|
-
Key: `${filename}.pdf`,
|
|
22
|
-
Body: stream,
|
|
23
|
-
ContentType: 'application/pdf'
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
let result;
|
|
27
|
-
let url;
|
|
28
|
-
try {
|
|
29
|
-
result = (await upload.done());
|
|
30
|
-
url = `https://${attachment_const_1.INVSTORAGE.invoiceBucket}.s3.${attachment_const_1.INVSTORAGE.region}.amazonaws.com/${filename}.pdf`;
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
console.log(e);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
result,
|
|
37
|
-
url
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
env_1.logger.info('operato-invoice: S3 Bucket Storage is Ready');
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=invoice-storage-s3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-storage-s3.js","sourceRoot":"","sources":["../server/invoice-storage-s3.ts"],"names":[],"mappings":";;AAAA,kDAA6C;AAC7C,sDAA6C;AAC7C,6CAA4C;AAE5C,yDAA+C;AAE/C,IAAI,6BAAU,IAAI,6BAAU,CAAC,IAAI,IAAI,IAAI,EAAE;IACzC,MAAM,MAAM,GAAG,IAAI,oBAAQ,CAAC;QAC1B,WAAW,EAAE;YACX,WAAW,EAAE,6BAAU,CAAC,WAAW;YACnC,eAAe,EAAE,6BAAU,CAAC,eAAe;SAC5C;QACD,MAAM,EAAE,6BAAU,CAAC,MAAM;KAC1B,CAAC,CAAA;IAEF,sBAAsB;IACtB,6BAAU,CAAC,eAAe,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC1D,MAAM,MAAM,GAAG,IAAI,oBAAM,CAAC;YACxB,MAAM;YACN,MAAM,EAAE;gBACN,MAAM,EAAE,6BAAU,CAAC,aAAa;gBAChC,GAAG,EAAE,GAAG,QAAQ,MAAM;gBACtB,IAAI,EAAE,MAAM;gBACZ,WAAW,EAAE,iBAAiB;aAC/B;SACF,CAAC,CAAA;QAEF,IAAI,MAAM,CAAA;QACV,IAAI,GAAG,CAAA;QACP,IAAI;YACF,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAQ,CAAA;YACrC,GAAG,GAAG,WAAW,6BAAU,CAAC,aAAa,OAAO,6BAAU,CAAC,MAAM,kBAAkB,QAAQ,MAAM,CAAA;SAClG;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;SACf;QAED,OAAO;YACL,MAAM;YACN,GAAG;SACJ,CAAA;IACH,CAAC,CAAA;IAED,YAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAA;CAC3D"}
|
package/dist-server/routes 2.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
require("./storage-file");
|
|
4
|
-
require("./storage-s3");
|
|
5
|
-
const attachment_const_1 = require("./attachment-const");
|
|
6
|
-
const multer = require('@koa/multer');
|
|
7
|
-
const upload = multer(); // note you can pass `multer` options here
|
|
8
|
-
// process.on('bootstrap-module-domain-private-route' as any, (app, routes) => {
|
|
9
|
-
process.on('bootstrap-module-global-public-route', (app, routes) => {
|
|
10
|
-
// TODO make this secure
|
|
11
|
-
routes.get(`/${attachment_const_1.ATTACHMENT_PATH}/:attachment`, async (context, next) => {
|
|
12
|
-
await attachment_const_1.STORAGE.sendFile(context, context.params.attachment, next);
|
|
13
|
-
});
|
|
14
|
-
routes.post(`/${attachment_const_1.ATTACHMENT_PATH}`, async (context, next) => {
|
|
15
|
-
const { files } = await upload(context.request);
|
|
16
|
-
const result = await Promise.all(files.map(file => attachment_const_1.STORAGE.uploadFile({ stream: file, filename: file.filename })));
|
|
17
|
-
context.status = 200;
|
|
18
|
-
// Support < IE 10 browser
|
|
19
|
-
context.res.setHeader('Content-Type', 'text/html;charset=UTF-8');
|
|
20
|
-
context.body = JSON.stringify(result);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,0BAAuB;AACvB,wBAAqB;AAErB,yDAA6D;AAE7D,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;AACrC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAA,CAAC,0CAA0C;AAElE,gFAAgF;AAChF,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;IACxE,wBAAwB;IACxB,MAAM,CAAC,GAAG,CAAC,IAAI,kCAAe,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACpE,MAAM,0BAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAClE,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,IAAI,CAAC,IAAI,kCAAe,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACzD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAE/C,MAAM,MAAM,GAAiD,MAAM,OAAO,CAAC,GAAG,CAC5E,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,0BAAO,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CACjF,CAAA;QAED,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;QACpB,0BAA0B;QAC1B,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,yBAAyB,CAAC,CAAA;QAChE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const fs = __importStar(require("fs"));
|
|
27
|
-
const mkdirp = __importStar(require("mkdirp"));
|
|
28
|
-
const path_1 = require("path");
|
|
29
|
-
const uuid_1 = require("uuid");
|
|
30
|
-
const env_1 = require("@things-factory/env");
|
|
31
|
-
const attachment_const_1 = require("./attachment-const");
|
|
32
|
-
const send = require('koa-send');
|
|
33
|
-
if (attachment_const_1.STORAGE && attachment_const_1.STORAGE.type == 'file') {
|
|
34
|
-
const uploadDir = env_1.config.getPath(null, attachment_const_1.STORAGE.base || 'attachments');
|
|
35
|
-
attachment_const_1.STORAGE.uploadFile = ({ stream, filename }) => {
|
|
36
|
-
mkdirp.sync(uploadDir);
|
|
37
|
-
const id = (0, uuid_1.v4)();
|
|
38
|
-
const ext = filename.split('.').pop();
|
|
39
|
-
const path = ext ? (0, path_1.resolve)(uploadDir, `${id}.${ext}`) : (0, path_1.resolve)(uploadDir, id);
|
|
40
|
-
const relativePath = path.split('\\').pop().split('/').pop();
|
|
41
|
-
var size = 0;
|
|
42
|
-
return new Promise((resolve, reject) => stream
|
|
43
|
-
.on('error', error => {
|
|
44
|
-
if (stream.truncated)
|
|
45
|
-
// Delete the truncated file
|
|
46
|
-
fs.unlinkSync(path);
|
|
47
|
-
reject(error);
|
|
48
|
-
})
|
|
49
|
-
.pipe(fs.createWriteStream(path))
|
|
50
|
-
.on('error', error => reject(error))
|
|
51
|
-
.on('data', chunk => (size += chunk.length))
|
|
52
|
-
.on('finish', () => resolve({ id, path: relativePath, size })));
|
|
53
|
-
};
|
|
54
|
-
attachment_const_1.STORAGE.deleteFile = async (path) => {
|
|
55
|
-
const fullpath = (0, path_1.resolve)(uploadDir, path);
|
|
56
|
-
await fs.unlink(fullpath, env_1.logger.error);
|
|
57
|
-
};
|
|
58
|
-
attachment_const_1.STORAGE.sendFile = async (context, attachment, next) => {
|
|
59
|
-
await send(context, attachment, { root: uploadDir });
|
|
60
|
-
};
|
|
61
|
-
attachment_const_1.STORAGE.readFile = (attachment, encoding) => {
|
|
62
|
-
const fullpath = (0, path_1.resolve)(uploadDir, attachment);
|
|
63
|
-
return fs.readFileSync(fullpath, encoding);
|
|
64
|
-
};
|
|
65
|
-
attachment_const_1.STORAGE.generateUploadURL = async (type) => {
|
|
66
|
-
const id = (0, uuid_1.v4)();
|
|
67
|
-
return await {
|
|
68
|
-
url: `/${attachment_const_1.ATTACHMENT_PATH}`,
|
|
69
|
-
fields: {}
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
env_1.logger.info('File Storage is Ready.');
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=storage-file.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage-file.js","sourceRoot":"","sources":["../server/storage-file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,u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A;IACH,CAAC,CAAA;IAED,YAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;CACtC"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const uuid_1 = require("uuid");
|
|
4
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
|
-
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
6
|
-
const s3_presigned_post_1 = require("@aws-sdk/s3-presigned-post");
|
|
7
|
-
const env_1 = require("@things-factory/env");
|
|
8
|
-
const attachment_const_1 = require("./attachment-const");
|
|
9
|
-
const mime = require('mime');
|
|
10
|
-
const { fs } = require('memfs');
|
|
11
|
-
if (attachment_const_1.STORAGE && attachment_const_1.STORAGE.type == 's3') {
|
|
12
|
-
const client = new client_s3_1.S3Client({
|
|
13
|
-
credentials: {
|
|
14
|
-
accessKeyId: attachment_const_1.STORAGE.accessKeyId,
|
|
15
|
-
secretAccessKey: attachment_const_1.STORAGE.secretAccessKey
|
|
16
|
-
},
|
|
17
|
-
region: attachment_const_1.STORAGE.region
|
|
18
|
-
});
|
|
19
|
-
const streamToBuffer = (stream) => new Promise((resolve, reject) => {
|
|
20
|
-
const chunks = [];
|
|
21
|
-
stream.on('data', chunk => chunks.push(chunk));
|
|
22
|
-
stream.once('end', () => resolve(Buffer.concat(chunks)));
|
|
23
|
-
stream.once('error', reject);
|
|
24
|
-
});
|
|
25
|
-
/* upload file */
|
|
26
|
-
attachment_const_1.STORAGE.uploadFile = async ({ stream, filename }) => {
|
|
27
|
-
const id = (0, uuid_1.v4)();
|
|
28
|
-
const ext = filename.split('.').pop();
|
|
29
|
-
const key = ext ? `${id}.${ext}` : id;
|
|
30
|
-
var size = 0;
|
|
31
|
-
const upload = new lib_storage_1.Upload({
|
|
32
|
-
client,
|
|
33
|
-
params: {
|
|
34
|
-
Bucket: attachment_const_1.STORAGE.bucketName,
|
|
35
|
-
Key: key,
|
|
36
|
-
Body: stream
|
|
37
|
-
// ContentType: 'text/plain',
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
const result = (await upload.done());
|
|
41
|
-
return {
|
|
42
|
-
id,
|
|
43
|
-
path: key,
|
|
44
|
-
size
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
attachment_const_1.STORAGE.deleteFile = async (path) => {
|
|
48
|
-
const command = new client_s3_1.DeleteObjectCommand({
|
|
49
|
-
Bucket: attachment_const_1.STORAGE.bucketName,
|
|
50
|
-
Key: path
|
|
51
|
-
});
|
|
52
|
-
return await client.send(command);
|
|
53
|
-
};
|
|
54
|
-
/* TODO Streaming to Streaming 으로 구현하라. */
|
|
55
|
-
attachment_const_1.STORAGE.sendFile = async (context, attachment, next) => {
|
|
56
|
-
const result = await client.send(new client_s3_1.GetObjectCommand({
|
|
57
|
-
Bucket: attachment_const_1.STORAGE.bucketName,
|
|
58
|
-
Key: attachment
|
|
59
|
-
}));
|
|
60
|
-
context.set({
|
|
61
|
-
'Content-Length': result.ContentLength,
|
|
62
|
-
'Content-Type': mime.getType(attachment),
|
|
63
|
-
'Last-Modified': result.LastModified.toUTCString(),
|
|
64
|
-
ETag: result.ETag,
|
|
65
|
-
'Cache-Control': 'public, max-age=31556926'
|
|
66
|
-
});
|
|
67
|
-
context.body = result.Body;
|
|
68
|
-
};
|
|
69
|
-
attachment_const_1.STORAGE.readFile = async (attachment, encoding) => {
|
|
70
|
-
/*
|
|
71
|
-
* refered to
|
|
72
|
-
* https://transang.me/modern-fetch-and-how-to-get-buffer-output-from-aws-sdk-v3-getobjectcommand/#the-body-type
|
|
73
|
-
*/
|
|
74
|
-
const result = await client.send(new client_s3_1.GetObjectCommand({
|
|
75
|
-
Bucket: attachment_const_1.STORAGE.bucketName,
|
|
76
|
-
Key: attachment
|
|
77
|
-
}));
|
|
78
|
-
var body = result.Body;
|
|
79
|
-
var buffer = await streamToBuffer(body);
|
|
80
|
-
switch (encoding) {
|
|
81
|
-
case 'base64':
|
|
82
|
-
return buffer.toString('base64');
|
|
83
|
-
default:
|
|
84
|
-
return await buffer;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
attachment_const_1.STORAGE.generateUploadURL = async (type) => {
|
|
88
|
-
const expiresInMinutes = 1;
|
|
89
|
-
const id = (0, uuid_1.v4)();
|
|
90
|
-
return await (0, s3_presigned_post_1.createPresignedPost)(client, {
|
|
91
|
-
Bucket: attachment_const_1.STORAGE.bucketName,
|
|
92
|
-
Key: id,
|
|
93
|
-
Expires: expiresInMinutes * 60,
|
|
94
|
-
Conditions: [['eq', '$Content-Type', type]]
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
env_1.logger.info('S3 Bucket Storage is Ready.');
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=storage-s3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage-s3.js","sourceRoot":"","sources":["../server/storage-s3.ts"],"names":[],"mappings":";;AACA,+BAAmC;AAEnC,kDAA2G;AAC3G,sDAA6C;AAC7C,kEAAgE;AAChE,6CAA4C;AAE5C,yDAA4C;AAE5C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/B,IAAI,0BAAO,IAAI,0BAAO,CAAC,IAAI,IAAI,IAAI,EAAE;IACnC,MAAM,MAAM,GAAG,IAAI,oBAAQ,CAAC;QAC1B,WAAW,EAAE;YACX,WAAW,EAAE,0BAAO,CAAC,WAAW;YAChC,eAAe,EAAE,0BAAO,CAAC,eAAe;SACzC;QACD,MAAM,EAAE,0BAAO,CAAC,MAAM;KACvB,CAAC,CAAA;IAEF,MAAM,cAAc,GAAG,CAAC,MAAgB,EAAE,EAAE,CAC1C,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,MAAM,GAAa,EAAE,C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