@webiny/api-page-builder-import-export 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f
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/client.d.ts +8 -0
- package/client.js +34 -0
- package/client.js.map +1 -0
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +101 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +101 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/export/combine/index.d.ts +16 -0
- package/export/combine/index.js +44 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/templatesHandler.d.ts +6 -0
- package/export/combine/templatesHandler.js +101 -0
- package/export/combine/templatesHandler.js.map +1 -0
- package/export/pages/ExportPagesCleanup.d.ts +5 -0
- package/export/pages/ExportPagesCleanup.js +82 -0
- package/export/pages/ExportPagesCleanup.js.map +1 -0
- package/export/pages/ExportPagesController.d.ts +5 -0
- package/export/pages/ExportPagesController.js +31 -0
- package/export/pages/ExportPagesController.js.map +1 -0
- package/export/pages/ExportPagesZipPages.d.ts +5 -0
- package/export/pages/ExportPagesZipPages.js +23 -0
- package/export/pages/ExportPagesZipPages.js.map +1 -0
- package/export/pages/controller/CombineZippedPages.d.ts +5 -0
- package/export/pages/controller/CombineZippedPages.js +75 -0
- package/export/pages/controller/CombineZippedPages.js.map +1 -0
- package/export/pages/controller/CreateZipPagesTasks.d.ts +8 -0
- package/export/pages/controller/CreateZipPagesTasks.js +103 -0
- package/export/pages/controller/CreateZipPagesTasks.js.map +1 -0
- package/export/pages/controller/ProcessZipPagesTasks.d.ts +6 -0
- package/export/pages/controller/ProcessZipPagesTasks.js +61 -0
- package/export/pages/controller/ProcessZipPagesTasks.js.map +1 -0
- package/export/pages/types.d.ts +53 -0
- package/export/pages/types.js +26 -0
- package/export/pages/types.js.map +1 -0
- package/export/pages/utils.d.ts +2 -0
- package/export/pages/utils.js +13 -0
- package/export/pages/utils.js.map +1 -0
- package/export/pages/zipPages/ZipPages.d.ts +5 -0
- package/export/pages/zipPages/ZipPages.js +100 -0
- package/export/pages/zipPages/ZipPages.js.map +1 -0
- package/export/pages/zipPages/ZipPagesDataManager.d.ts +14 -0
- package/export/pages/zipPages/ZipPagesDataManager.js +46 -0
- package/export/pages/zipPages/ZipPagesDataManager.js.map +1 -0
- package/export/pages/zipPages/getPageFactory.d.ts +4 -0
- package/export/pages/zipPages/getPageFactory.js +38 -0
- package/export/pages/zipPages/getPageFactory.js.map +1 -0
- package/export/process/blocksHandler.d.ts +6 -0
- package/export/process/blocksHandler.js +169 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/export/process/exporters/BlockExporter.d.ts +12 -0
- package/export/process/exporters/BlockExporter.js +57 -0
- package/export/process/exporters/BlockExporter.js.map +1 -0
- package/export/process/exporters/FormExporter.d.ts +9 -0
- package/export/process/exporters/FormExporter.js +36 -0
- package/export/process/exporters/FormExporter.js.map +1 -0
- package/export/process/exporters/PageExporter.d.ts +18 -0
- package/export/process/exporters/PageExporter.js +59 -0
- package/export/process/exporters/PageExporter.js.map +1 -0
- package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
- package/export/process/exporters/PageTemplateExporter.js +58 -0
- package/export/process/exporters/PageTemplateExporter.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +189 -0
- package/export/process/formsHandler.js.map +1 -0
- package/export/process/index.d.ts +20 -0
- package/export/process/index.js +41 -0
- package/export/process/index.js.map +1 -0
- package/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +168 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/export/s3Stream.d.ts +36 -0
- package/export/s3Stream.js +98 -0
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +24 -0
- package/export/utils.js +169 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +13 -10
- package/export/zipper.js +120 -0
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +158 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +162 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/importExportTasks.crud.js +396 -0
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +3 -3
- package/graphql/crud/pages.crud.js +244 -133
- package/graphql/crud/pages.crud.js.map +1 -0
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +156 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +8 -8
- package/graphql/crud.js.map +1 -0
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +52 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- package/graphql/graphql/forms.gql.d.ts +4 -0
- package/graphql/graphql/forms.gql.js +60 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/importExportTasks.gql.js +75 -0
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +3 -3
- package/graphql/graphql/pages.gql.js +102 -22
- package/graphql/graphql/pages.gql.js.map +1 -0
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +52 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql/utils/resolve.d.ts +3 -3
- package/graphql/graphql/utils/resolve.js +15 -7
- package/graphql/graphql/utils/resolve.js.map +1 -0
- package/graphql/graphql.d.ts +2 -2
- package/graphql/graphql.js +7 -7
- package/graphql/graphql.js.map +1 -0
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +5 -7
- package/graphql/index.js.map +1 -0
- package/graphql/types.d.ts +239 -40
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -0
- package/import/constants.d.ts +3 -0
- package/import/constants.js +13 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +101 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +105 -0
- package/import/create/formsHandler.js.map +1 -0
- package/import/create/index.d.ts +24 -0
- package/import/create/index.js +44 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +105 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/create/templatesHandler.d.ts +3 -0
- package/import/create/templatesHandler.js +101 -0
- package/import/create/templatesHandler.js.map +1 -0
- package/import/pages/ImportPagesController.d.ts +5 -0
- package/import/pages/ImportPagesController.js +29 -0
- package/import/pages/ImportPagesController.js.map +1 -0
- package/import/pages/ImportPagesProcessPages.d.ts +6 -0
- package/import/pages/ImportPagesProcessPages.js +112 -0
- package/import/pages/ImportPagesProcessPages.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.d.ts +6 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js +40 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessZipFile.d.ts +5 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js +71 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js.map +1 -0
- package/import/pages/process/importPage.d.ts +10 -0
- package/import/pages/process/importPage.js +94 -0
- package/import/pages/process/importPage.js.map +1 -0
- package/import/pages/types.d.ts +48 -0
- package/import/pages/types.js +20 -0
- package/import/pages/types.js.map +1 -0
- package/import/process/blocks/ElementIdsProcessor.d.ts +5 -0
- package/import/process/blocks/ElementIdsProcessor.js +26 -0
- package/import/process/blocks/ElementIdsProcessor.js.map +1 -0
- package/import/process/blocks/blocksHandler.d.ts +3 -0
- package/import/process/blocks/blocksHandler.js +169 -0
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +101 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/forms/formsHandler.js +178 -0
- package/import/process/forms/formsHandler.js.map +1 -0
- package/import/process/forms/importForm.d.ts +9 -0
- package/import/process/forms/importForm.js +47 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/import/process/index.d.ts +20 -0
- package/import/process/index.js +41 -0
- package/import/process/index.js.map +1 -0
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +70 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/templates/templatesHandler.d.ts +3 -0
- package/import/process/templates/templatesHandler.js +174 -0
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +21 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +126 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +100 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +13 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +106 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +18 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +31 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +51 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +92 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +21 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/mockSecurity.d.ts +1 -1
- package/mockSecurity.js +2 -3
- package/mockSecurity.js.map +1 -0
- package/package.json +37 -51
- package/tasks/common/ChildTasksCleanup.d.ts +12 -0
- package/tasks/common/ChildTasksCleanup.js +64 -0
- package/tasks/common/ChildTasksCleanup.js.map +1 -0
- package/tasks/index.d.ts +1 -0
- package/tasks/index.js +13 -0
- package/tasks/index.js.map +1 -0
- package/tasks/pages/exportPagesCleanupTask.d.ts +3 -0
- package/tasks/pages/exportPagesCleanupTask.js +36 -0
- package/tasks/pages/exportPagesCleanupTask.js.map +1 -0
- package/tasks/pages/exportPagesControllerTask.d.ts +3 -0
- package/tasks/pages/exportPagesControllerTask.js +83 -0
- package/tasks/pages/exportPagesControllerTask.js.map +1 -0
- package/tasks/pages/exportPagesZipPagesTask.d.ts +3 -0
- package/tasks/pages/exportPagesZipPagesTask.js +39 -0
- package/tasks/pages/exportPagesZipPagesTask.js.map +1 -0
- package/tasks/pages/importPagesControllerTask.d.ts +3 -0
- package/tasks/pages/importPagesControllerTask.js +39 -0
- package/tasks/pages/importPagesControllerTask.js.map +1 -0
- package/tasks/pages/importPagesProcessPageTask.d.ts +3 -0
- package/tasks/pages/importPagesProcessPageTask.js +39 -0
- package/tasks/pages/importPagesProcessPageTask.js.map +1 -0
- package/tasks/pages/index.d.ts +1 -0
- package/tasks/pages/index.js +17 -0
- package/tasks/pages/index.js.map +1 -0
- package/types.d.ts +91 -72
- package/types.js +68 -21
- package/types.js.map +1 -0
- package/utils/ZipFiles.d.ts +11 -0
- package/utils/ZipFiles.js +124 -0
- package/utils/ZipFiles.js.map +1 -0
- package/exportPages/combine/index.d.ts +0 -19
- package/exportPages/combine/index.js +0 -88
- package/exportPages/process/index.d.ts +0 -26
- package/exportPages/process/index.js +0 -204
- package/exportPages/s3Stream.d.ts +0 -29
- package/exportPages/s3Stream.js +0 -106
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -113
- package/exportPages/zipper.js +0 -137
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js +0 -394
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js +0 -80
- package/importPages/client.d.ts +0 -7
- package/importPages/client.js +0 -40
- package/importPages/create/index.d.ts +0 -27
- package/importPages/create/index.js +0 -109
- package/importPages/process/index.d.ts +0 -25
- package/importPages/process/index.js +0 -183
- package/importPages/utils.d.ts +0 -43
- package/importPages/utils.js +0 -539
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ZipFiles = void 0;
|
|
8
|
+
var _archiver = require("archiver");
|
|
9
|
+
var _clientS = require("@webiny/aws-sdk/client-s3");
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _stream = require("stream");
|
|
12
|
+
var _libStorage = require("@webiny/aws-sdk/lib-storage");
|
|
13
|
+
var _nodeHttpHandler = require("@smithy/node-http-handler");
|
|
14
|
+
var _https = require("https");
|
|
15
|
+
var _http = require("http");
|
|
16
|
+
class ZipFiles {
|
|
17
|
+
bucket = process.env.S3_BUCKET;
|
|
18
|
+
debug = process.env.DEBUG === "true";
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.setDebug(options?.debug);
|
|
21
|
+
}
|
|
22
|
+
async process(targetFileName, files) {
|
|
23
|
+
const fileNames = Array.from(files);
|
|
24
|
+
const s3Client = (0, _clientS.createS3)({
|
|
25
|
+
requestHandler: new _nodeHttpHandler.NodeHttpHandler({
|
|
26
|
+
connectionTimeout: 0,
|
|
27
|
+
httpAgent: new _http.Agent({
|
|
28
|
+
maxSockets: 10000,
|
|
29
|
+
keepAlive: true,
|
|
30
|
+
maxFreeSockets: 10000,
|
|
31
|
+
maxTotalSockets: 10000,
|
|
32
|
+
keepAliveMsecs: 900000 // milliseconds / 15 minutes
|
|
33
|
+
}),
|
|
34
|
+
httpsAgent: new _https.Agent({
|
|
35
|
+
maxSockets: 10000,
|
|
36
|
+
keepAlive: true,
|
|
37
|
+
sessionTimeout: 900,
|
|
38
|
+
// seconds / 15 minutes
|
|
39
|
+
maxCachedSessions: 100000,
|
|
40
|
+
maxFreeSockets: 10000,
|
|
41
|
+
maxTotalSockets: 10000,
|
|
42
|
+
keepAliveMsecs: 900000 // milliseconds / 15 minutes
|
|
43
|
+
}),
|
|
44
|
+
requestTimeout: 900000 // milliseconds / 15 minutes
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
const streamPassThrough = new _stream.Stream.PassThrough({
|
|
48
|
+
autoDestroy: true
|
|
49
|
+
});
|
|
50
|
+
const upload = new _libStorage.Upload({
|
|
51
|
+
client: s3Client,
|
|
52
|
+
params: {
|
|
53
|
+
ACL: "private",
|
|
54
|
+
Body: streamPassThrough,
|
|
55
|
+
Bucket: this.bucket,
|
|
56
|
+
ContentType: "application/zip",
|
|
57
|
+
Key: targetFileName
|
|
58
|
+
},
|
|
59
|
+
queueSize: 1,
|
|
60
|
+
partSize: 1024 * 1024 * 5,
|
|
61
|
+
leavePartsOnError: false
|
|
62
|
+
});
|
|
63
|
+
const archive = (0, _archiver.create)("zip", {});
|
|
64
|
+
archive.on("error", error => {
|
|
65
|
+
console.error(error);
|
|
66
|
+
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
|
67
|
+
});
|
|
68
|
+
archive.pipe(streamPassThrough);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* To combine all the files into a single zip file, we need to add files one by one.
|
|
72
|
+
*
|
|
73
|
+
* addFileToArchive() method is called every time an entry event is triggered on the archive - it means that file was added into the archive.
|
|
74
|
+
* The method is called manually, first time, to start the process.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
archive.on("entry", data => {
|
|
78
|
+
this.debug && console.log(`Archived file: ${data.name}`);
|
|
79
|
+
addFileToArchive();
|
|
80
|
+
});
|
|
81
|
+
const addFileToArchive = async () => {
|
|
82
|
+
const file = fileNames.shift();
|
|
83
|
+
if (!file) {
|
|
84
|
+
this.debug && console.log("No more files to add to the archive.");
|
|
85
|
+
/**
|
|
86
|
+
* Must call finalize() with a timeout, otherwise the lambda crashes.
|
|
87
|
+
*/
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
archive.finalize();
|
|
90
|
+
}, 200);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.debug && console.log(`Adding file "${file}" to the archive.`);
|
|
94
|
+
const cmd = new _clientS.GetObjectCommand({
|
|
95
|
+
Bucket: this.bucket,
|
|
96
|
+
Key: file
|
|
97
|
+
});
|
|
98
|
+
const response = await s3Client.send(cmd);
|
|
99
|
+
// Possible to get a null response.Body?
|
|
100
|
+
// Typescript says yes, so let's check it.
|
|
101
|
+
if (!response.Body) {
|
|
102
|
+
this.debug && console.log(`No response.Body for file "${file}", moving to next file.`);
|
|
103
|
+
return addFileToArchive();
|
|
104
|
+
}
|
|
105
|
+
const name = `${_path.default.basename(file)}`;
|
|
106
|
+
archive.append(response.Body, {
|
|
107
|
+
name
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
addFileToArchive();
|
|
111
|
+
const result = await upload.done();
|
|
112
|
+
s3Client.destroy();
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
setDebug(debug) {
|
|
116
|
+
if (debug === undefined) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.debug = debug;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.ZipFiles = ZipFiles;
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=ZipFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_archiver","require","_clientS","_path","_interopRequireDefault","_stream","_libStorage","_nodeHttpHandler","_https","_http","ZipFiles","bucket","process","env","S3_BUCKET","debug","DEBUG","constructor","options","setDebug","targetFileName","files","fileNames","Array","from","s3Client","createS3","requestHandler","NodeHttpHandler","connectionTimeout","httpAgent","HttpAgent","maxSockets","keepAlive","maxFreeSockets","maxTotalSockets","keepAliveMsecs","httpsAgent","HttpsAgent","sessionTimeout","maxCachedSessions","requestTimeout","streamPassThrough","Stream","PassThrough","autoDestroy","upload","Upload","client","params","ACL","Body","Bucket","ContentType","Key","queueSize","partSize","leavePartsOnError","archive","createArchiver","on","error","console","Error","name","code","message","path","stack","pipe","data","log","addFileToArchive","file","shift","setTimeout","finalize","cmd","GetObjectCommand","response","send","basename","append","result","done","destroy","undefined","exports"],"sources":["ZipFiles.ts"],"sourcesContent":["import type { ArchiverError } from \"archiver\";\nimport { create as createArchiver } from \"archiver\";\nimport type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { createS3, GetObjectCommand } from \"@webiny/aws-sdk/client-s3\";\nimport path from \"path\";\nimport { type Readable, Stream } from \"stream\";\nimport { Upload } from \"@webiny/aws-sdk/lib-storage\";\nimport { NodeHttpHandler } from \"@smithy/node-http-handler\";\nimport { Agent as HttpsAgent } from \"https\";\nimport { Agent as HttpAgent } from \"http\";\n\nexport interface ZipFilesOptions {\n debug?: boolean;\n}\n\nexport class ZipFiles {\n private readonly bucket: string = process.env.S3_BUCKET as string;\n private debug: boolean = process.env.DEBUG === \"true\";\n\n public constructor(options?: ZipFilesOptions) {\n this.setDebug(options?.debug);\n }\n\n public async process(\n targetFileName: string,\n files: string[]\n ): Promise<CompleteMultipartUploadOutput> {\n const fileNames = Array.from(files);\n const s3Client = createS3({\n requestHandler: new NodeHttpHandler({\n connectionTimeout: 0,\n httpAgent: new HttpAgent({\n maxSockets: 10000,\n keepAlive: true,\n maxFreeSockets: 10000,\n maxTotalSockets: 10000,\n keepAliveMsecs: 900000 // milliseconds / 15 minutes\n }),\n httpsAgent: new HttpsAgent({\n maxSockets: 10000,\n keepAlive: true,\n sessionTimeout: 900, // seconds / 15 minutes\n maxCachedSessions: 100000,\n maxFreeSockets: 10000,\n maxTotalSockets: 10000,\n keepAliveMsecs: 900000 // milliseconds / 15 minutes\n }),\n requestTimeout: 900000 // milliseconds / 15 minutes\n })\n });\n\n const streamPassThrough = new Stream.PassThrough({\n autoDestroy: true\n });\n\n const upload = new Upload({\n client: s3Client,\n params: {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: \"application/zip\",\n Key: targetFileName\n },\n queueSize: 1,\n partSize: 1024 * 1024 * 5,\n leavePartsOnError: false\n });\n\n const archive = createArchiver(\"zip\", {});\n\n archive.on(\"error\", (error: ArchiverError) => {\n console.error(error);\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n archive.pipe(streamPassThrough);\n\n /**\n * To combine all the files into a single zip file, we need to add files one by one.\n *\n * addFileToArchive() method is called every time an entry event is triggered on the archive - it means that file was added into the archive.\n * The method is called manually, first time, to start the process.\n */\n\n archive.on(\"entry\", data => {\n this.debug && console.log(`Archived file: ${data.name}`);\n addFileToArchive();\n });\n\n const addFileToArchive = async (): Promise<void> => {\n const file = fileNames.shift();\n if (!file) {\n this.debug && console.log(\"No more files to add to the archive.\");\n /**\n * Must call finalize() with a timeout, otherwise the lambda crashes.\n */\n setTimeout(() => {\n archive.finalize();\n }, 200);\n return;\n }\n this.debug && console.log(`Adding file \"${file}\" to the archive.`);\n const cmd = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file\n });\n\n const response = await s3Client.send(cmd);\n // Possible to get a null response.Body?\n // Typescript says yes, so let's check it.\n if (!response.Body) {\n this.debug &&\n console.log(`No response.Body for file \"${file}\", moving to next file.`);\n return addFileToArchive();\n }\n const name = `${path.basename(file)}`;\n\n archive.append(response.Body as Readable, {\n name\n });\n };\n\n addFileToArchive();\n\n const result = await upload.done();\n\n s3Client.destroy();\n return result;\n }\n\n private setDebug(debug?: boolean): void {\n if (debug === undefined) {\n return;\n }\n this.debug = debug;\n }\n}\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HandlerPlugin } from "@webiny/handler/types";
|
|
2
|
-
import { ArgsContext } from "@webiny/handler-args/types";
|
|
3
|
-
import { PbPageImportExportContext } from "../../types";
|
|
4
|
-
import { SecurityIdentity } from "@webiny/api-security/types";
|
|
5
|
-
export declare type HandlerArgs = {
|
|
6
|
-
taskId: string;
|
|
7
|
-
identity: SecurityIdentity;
|
|
8
|
-
};
|
|
9
|
-
export declare type HandlerResponse = {
|
|
10
|
-
data: string;
|
|
11
|
-
error: {
|
|
12
|
-
message: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
declare const _default: () => HandlerPlugin<PbPageImportExportContext, ArgsContext<HandlerArgs>>;
|
|
16
|
-
/**
|
|
17
|
-
* Handles the export pages combine workflow.
|
|
18
|
-
*/
|
|
19
|
-
export default _default;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _types = require("../../types");
|
|
9
|
-
|
|
10
|
-
var _s3Stream = require("../s3Stream");
|
|
11
|
-
|
|
12
|
-
var _zipper = require("../zipper");
|
|
13
|
-
|
|
14
|
-
var _mockSecurity = require("../../mockSecurity");
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Handles the export pages combine workflow.
|
|
18
|
-
*/
|
|
19
|
-
var _default = () => ({
|
|
20
|
-
type: "handler",
|
|
21
|
-
|
|
22
|
-
async handle(context) {
|
|
23
|
-
const log = console.log;
|
|
24
|
-
log("RUNNING Export Pages Combine Handler");
|
|
25
|
-
const {
|
|
26
|
-
invocationArgs: args,
|
|
27
|
-
pageBuilder
|
|
28
|
-
} = context;
|
|
29
|
-
const {
|
|
30
|
-
taskId,
|
|
31
|
-
identity
|
|
32
|
-
} = args;
|
|
33
|
-
(0, _mockSecurity.mockSecurity)(identity, context);
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const task = await pageBuilder.pageImportExportTask.getTask(taskId);
|
|
37
|
-
const {
|
|
38
|
-
exportPagesDataKey
|
|
39
|
-
} = task.input; // Get all files (zip) from given key
|
|
40
|
-
|
|
41
|
-
const listObjectResponse = await _s3Stream.s3Stream.listObject(exportPagesDataKey);
|
|
42
|
-
const zipFileKeys = listObjectResponse.Contents.filter(file => file.Key !== exportPagesDataKey).map(file => file.Key); // Prepare zip of all zips
|
|
43
|
-
|
|
44
|
-
const zipOfZip = new _zipper.ZipOfZip(zipFileKeys); // Upload
|
|
45
|
-
|
|
46
|
-
const pageExportUpload = await zipOfZip.process();
|
|
47
|
-
log(`Done uploading... File is located at ${pageExportUpload.Location} `); // Update task status and save export page data key
|
|
48
|
-
|
|
49
|
-
await pageBuilder.pageImportExportTask.updateTask(taskId, {
|
|
50
|
-
status: _types.PageImportExportTaskStatus.COMPLETED,
|
|
51
|
-
data: {
|
|
52
|
-
message: `Finish uploading page export.`,
|
|
53
|
-
key: pageExportUpload.Key,
|
|
54
|
-
url: pageExportUpload.Location
|
|
55
|
-
}
|
|
56
|
-
}); // Remove individual zip files from storage
|
|
57
|
-
|
|
58
|
-
const deleteFilePromises = zipFileKeys.map(key => _s3Stream.s3Stream.deleteObject(key));
|
|
59
|
-
await Promise.all(deleteFilePromises);
|
|
60
|
-
log(`Successfully deleted ${deleteFilePromises.length} zip files.`);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
log("[EXPORT_PAGES_COMBINE] Error => ", e);
|
|
63
|
-
/**
|
|
64
|
-
* In case of error, we'll update the task status to "failed",
|
|
65
|
-
* so that, client can show notify the user appropriately.
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
await pageBuilder.pageImportExportTask.updateTask(taskId, {
|
|
69
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
|
70
|
-
error: {
|
|
71
|
-
name: e.name,
|
|
72
|
-
message: e.message,
|
|
73
|
-
stack: e.stack,
|
|
74
|
-
code: "IMPORT_FAILED"
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
data: null,
|
|
79
|
-
error: {
|
|
80
|
-
message: e.message
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
exports.default = _default;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { HandlerPlugin } from "@webiny/handler/types";
|
|
2
|
-
import { ArgsContext } from "@webiny/handler-args/types";
|
|
3
|
-
import { PbPageImportExportContext } from "../../types";
|
|
4
|
-
import { SecurityIdentity } from "@webiny/api-security/types";
|
|
5
|
-
export declare type HandlerArgs = {
|
|
6
|
-
taskId: string;
|
|
7
|
-
subTaskIndex: number;
|
|
8
|
-
identity?: SecurityIdentity;
|
|
9
|
-
};
|
|
10
|
-
export declare type HandlerResponse = {
|
|
11
|
-
data: string;
|
|
12
|
-
error: {
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
interface Configuration {
|
|
17
|
-
handlers: {
|
|
18
|
-
process: string;
|
|
19
|
-
combine: string;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
declare const _default: (configuration: Configuration) => HandlerPlugin<PbPageImportExportContext, ArgsContext<HandlerArgs>>;
|
|
23
|
-
/**
|
|
24
|
-
* Handles the export pages process workflow.
|
|
25
|
-
*/
|
|
26
|
-
export default _default;
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _types = require("../../types");
|
|
9
|
-
|
|
10
|
-
var _utils = require("../../importPages/utils");
|
|
11
|
-
|
|
12
|
-
var _client = require("../../importPages/client");
|
|
13
|
-
|
|
14
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
15
|
-
|
|
16
|
-
var _utils2 = require("../utils");
|
|
17
|
-
|
|
18
|
-
var _mockSecurity = require("../../mockSecurity");
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Handles the export pages process workflow.
|
|
22
|
-
*/
|
|
23
|
-
var _default = configuration => ({
|
|
24
|
-
type: "handler",
|
|
25
|
-
|
|
26
|
-
async handle(context) {
|
|
27
|
-
const log = console.log;
|
|
28
|
-
let subTask;
|
|
29
|
-
let noPendingTask = true;
|
|
30
|
-
let prevStatusOfSubTask = _types.PageImportExportTaskStatus.PENDING;
|
|
31
|
-
log("RUNNING Export Pages Process Handler");
|
|
32
|
-
const {
|
|
33
|
-
invocationArgs: args,
|
|
34
|
-
pageBuilder,
|
|
35
|
-
fileManager
|
|
36
|
-
} = context;
|
|
37
|
-
const {
|
|
38
|
-
taskId,
|
|
39
|
-
subTaskIndex,
|
|
40
|
-
identity
|
|
41
|
-
} = args; // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
|
42
|
-
// and this Lambda is invoked internally, without credentials.
|
|
43
|
-
|
|
44
|
-
(0, _mockSecurity.mockSecurity)(identity, context);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
/*
|
|
48
|
-
* Note: We're not going to DB for finding the next sub-task to process,
|
|
49
|
-
* because the data might be out of sync due to GSI eventual consistency.
|
|
50
|
-
*/
|
|
51
|
-
subTask = await pageBuilder.pageImportExportTask.getSubTask(taskId, (0, _utils.zeroPad)(subTaskIndex));
|
|
52
|
-
/**
|
|
53
|
-
* Base condition!!
|
|
54
|
-
* Bail out early, if task not found or task's status is not "pending".
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
if (!subTask || subTask.status !== _types.PageImportExportTaskStatus.PENDING) {
|
|
58
|
-
noPendingTask = true;
|
|
59
|
-
return;
|
|
60
|
-
} else {
|
|
61
|
-
noPendingTask = false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
log(`Fetched sub task => ${subTask.id}`);
|
|
65
|
-
const {
|
|
66
|
-
input
|
|
67
|
-
} = subTask;
|
|
68
|
-
const {
|
|
69
|
-
pageId,
|
|
70
|
-
exportPagesDataKey,
|
|
71
|
-
revisionType
|
|
72
|
-
} = input;
|
|
73
|
-
/**
|
|
74
|
-
* At the moment, we only export a single revision of the page.
|
|
75
|
-
* It could be "published" or "latest" depending upon user input.
|
|
76
|
-
*
|
|
77
|
-
* Note: In case of no "published" revision available, we use the latest revision.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
let page;
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
if (revisionType === _types.PageExportRevisionType.PUBLISHED) {
|
|
84
|
-
// Get "published" page.
|
|
85
|
-
page = await pageBuilder.pages.getPublishedById({
|
|
86
|
-
id: pageId
|
|
87
|
-
});
|
|
88
|
-
} else {
|
|
89
|
-
// Get "latest" page.
|
|
90
|
-
page = await pageBuilder.pages.get(pageId);
|
|
91
|
-
}
|
|
92
|
-
} catch (e) {
|
|
93
|
-
// If we're looking for "published" page and doesn't found it, get latest page.
|
|
94
|
-
if (revisionType === _types.PageExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
|
|
95
|
-
page = await pageBuilder.pages.get(pageId);
|
|
96
|
-
} else {
|
|
97
|
-
throw e;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!page) {
|
|
102
|
-
log(`Unable to load page "${pageId}"`);
|
|
103
|
-
throw new _handlerGraphql.NotFoundError(`Unable to load page "${pageId}"`);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
log(`Processing page key "${pageId}" | version ${page.version} | ${page.status}`); // Mark task status as PROCESSING
|
|
107
|
-
|
|
108
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
|
109
|
-
status: _types.PageImportExportTaskStatus.PROCESSING
|
|
110
|
-
}); // Update stats in main task
|
|
111
|
-
|
|
112
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
|
113
|
-
prevStatus: prevStatusOfSubTask,
|
|
114
|
-
nextStatus: _types.PageImportExportTaskStatus.PROCESSING
|
|
115
|
-
});
|
|
116
|
-
prevStatusOfSubTask = subTask.status;
|
|
117
|
-
log(`Extracting page data and uploading to storage...`); // Extract Page
|
|
118
|
-
|
|
119
|
-
const pageDataZip = await (0, _utils2.exportPage)(page, exportPagesDataKey, fileManager);
|
|
120
|
-
log(`Finish uploading zip...`); // Update task record in DB
|
|
121
|
-
|
|
122
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
|
123
|
-
status: _types.PageImportExportTaskStatus.COMPLETED,
|
|
124
|
-
data: {
|
|
125
|
-
message: `Finish uploading data for page "${page.id}" v${page.version} (${page.status}).`,
|
|
126
|
-
key: pageDataZip.Key
|
|
127
|
-
}
|
|
128
|
-
}); // Update stats in main task
|
|
129
|
-
|
|
130
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
|
131
|
-
prevStatus: prevStatusOfSubTask,
|
|
132
|
-
nextStatus: _types.PageImportExportTaskStatus.COMPLETED
|
|
133
|
-
});
|
|
134
|
-
prevStatusOfSubTask = subTask.status;
|
|
135
|
-
} catch (e) {
|
|
136
|
-
log("[EXPORT_PAGES_PROCESS] Error => ", e);
|
|
137
|
-
|
|
138
|
-
if (subTask && subTask.id) {
|
|
139
|
-
/**
|
|
140
|
-
* In case of error, we'll update the task status to "failed",
|
|
141
|
-
* so that, client can show notify the user appropriately.
|
|
142
|
-
*/
|
|
143
|
-
const {
|
|
144
|
-
invocationArgs: args,
|
|
145
|
-
pageBuilder
|
|
146
|
-
} = context;
|
|
147
|
-
const {
|
|
148
|
-
taskId
|
|
149
|
-
} = args;
|
|
150
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
|
151
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
|
152
|
-
error: {
|
|
153
|
-
name: e.name,
|
|
154
|
-
message: e.message,
|
|
155
|
-
stack: e.stack,
|
|
156
|
-
code: "IMPORT_FAILED"
|
|
157
|
-
}
|
|
158
|
-
}); // Update stats in main task
|
|
159
|
-
|
|
160
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
|
161
|
-
prevStatus: prevStatusOfSubTask,
|
|
162
|
-
nextStatus: _types.PageImportExportTaskStatus.FAILED
|
|
163
|
-
});
|
|
164
|
-
prevStatusOfSubTask = subTask.status;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
data: null,
|
|
169
|
-
error: {
|
|
170
|
-
message: e.message
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
} finally {
|
|
174
|
-
// Base condition!
|
|
175
|
-
if (noPendingTask) {
|
|
176
|
-
log(`No pending sub-task for task ${taskId}`); // Combine individual page zip files.
|
|
177
|
-
|
|
178
|
-
await (0, _client.invokeHandlerClient)({
|
|
179
|
-
context,
|
|
180
|
-
name: configuration.handlers.combine,
|
|
181
|
-
payload: {
|
|
182
|
-
taskId,
|
|
183
|
-
identity: context.security.getIdentity()
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
} else {
|
|
187
|
-
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`); // We want to continue with Self invocation no matter if current page error out.
|
|
188
|
-
|
|
189
|
-
await (0, _client.invokeHandlerClient)({
|
|
190
|
-
context,
|
|
191
|
-
name: configuration.handlers.process,
|
|
192
|
-
payload: {
|
|
193
|
-
taskId,
|
|
194
|
-
subTaskIndex: subTaskIndex + 1,
|
|
195
|
-
identity: context.security.getIdentity()
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
exports.default = _default;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { PassThrough, Readable } from "stream";
|
|
3
|
-
import S3 from "aws-sdk/clients/s3";
|
|
4
|
-
declare class S3Stream {
|
|
5
|
-
s3: S3;
|
|
6
|
-
bucket: string;
|
|
7
|
-
constructor();
|
|
8
|
-
/**
|
|
9
|
-
* We're checking if the file is accessible on S3 by getting object meta data.
|
|
10
|
-
* It help us to filter files that we need to download as part of export data.
|
|
11
|
-
* @param Key {string}
|
|
12
|
-
*/
|
|
13
|
-
isFileAccessible(Key: string): Promise<boolean>;
|
|
14
|
-
getObjectHead(Key: string): Promise<S3.HeadObjectOutput>;
|
|
15
|
-
readStream(Key: string): Readable;
|
|
16
|
-
writeStream(Key: string, contentType?: string): {
|
|
17
|
-
streamPassThrough: PassThrough;
|
|
18
|
-
streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;
|
|
19
|
-
};
|
|
20
|
-
upload(params: {
|
|
21
|
-
Key: string;
|
|
22
|
-
ContentType: string;
|
|
23
|
-
Body: Buffer;
|
|
24
|
-
}): Promise<S3.ManagedUpload.SendData>;
|
|
25
|
-
listObject(prefix: string): Promise<S3.ListObjectsOutput>;
|
|
26
|
-
deleteObject(key: string): Promise<S3.DeleteObjectOutput>;
|
|
27
|
-
}
|
|
28
|
-
export declare const s3Stream: S3Stream;
|
|
29
|
-
export {};
|
package/exportPages/s3Stream.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.s3Stream = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _stream = require("stream");
|
|
13
|
-
|
|
14
|
-
var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
|
|
15
|
-
|
|
16
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
const ARCHIVE_CONTENT_TYPE = "application/zip";
|
|
21
|
-
|
|
22
|
-
class S3Stream {
|
|
23
|
-
constructor() {
|
|
24
|
-
(0, _defineProperty2.default)(this, "s3", void 0);
|
|
25
|
-
(0, _defineProperty2.default)(this, "bucket", void 0);
|
|
26
|
-
this.s3 = new _s.default({
|
|
27
|
-
region: process.env.AWS_REGION
|
|
28
|
-
});
|
|
29
|
-
this.bucket = process.env.S3_BUCKET;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* We're checking if the file is accessible on S3 by getting object meta data.
|
|
33
|
-
* It help us to filter files that we need to download as part of export data.
|
|
34
|
-
* @param Key {string}
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
async isFileAccessible(Key) {
|
|
39
|
-
try {
|
|
40
|
-
await this.getObjectHead(Key);
|
|
41
|
-
return true;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.warn(`Error while fetching meta data for file "${Key}"`);
|
|
44
|
-
console.log(error);
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getObjectHead(Key) {
|
|
50
|
-
return this.s3.headObject({
|
|
51
|
-
Bucket: this.bucket,
|
|
52
|
-
Key
|
|
53
|
-
}).promise();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
readStream(Key) {
|
|
57
|
-
return this.s3.getObject({
|
|
58
|
-
Bucket: this.bucket,
|
|
59
|
-
Key
|
|
60
|
-
}).createReadStream();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
writeStream(Key, contentType = ARCHIVE_CONTENT_TYPE) {
|
|
64
|
-
const streamPassThrough = new _stream.Stream.PassThrough();
|
|
65
|
-
const params = {
|
|
66
|
-
ACL: "public-read",
|
|
67
|
-
Body: streamPassThrough,
|
|
68
|
-
Bucket: this.bucket,
|
|
69
|
-
ContentType: contentType,
|
|
70
|
-
Key
|
|
71
|
-
};
|
|
72
|
-
return {
|
|
73
|
-
streamPassThrough: streamPassThrough,
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
|
|
77
|
-
*/
|
|
78
|
-
streamPassThroughUploadPromise: this.s3.upload(params).promise()
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
upload(params) {
|
|
83
|
-
return this.s3.upload(_objectSpread({
|
|
84
|
-
ACL: "private",
|
|
85
|
-
Bucket: this.bucket
|
|
86
|
-
}, params)).promise();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
listObject(prefix) {
|
|
90
|
-
return this.s3.listObjects({
|
|
91
|
-
Bucket: this.bucket,
|
|
92
|
-
Prefix: prefix
|
|
93
|
-
}).promise();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
deleteObject(key) {
|
|
97
|
-
return this.s3.deleteObject({
|
|
98
|
-
Key: key,
|
|
99
|
-
Bucket: this.bucket
|
|
100
|
-
}).promise();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const s3Stream = new S3Stream();
|
|
106
|
-
exports.s3Stream = s3Stream;
|
package/exportPages/utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import S3 from "aws-sdk/clients/s3";
|
|
2
|
-
import { Page, File } from "@webiny/api-page-builder/types";
|
|
3
|
-
import { FileManagerContext } from "@webiny/api-file-manager/types";
|
|
4
|
-
export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
|
5
|
-
export interface ExportedPageData {
|
|
6
|
-
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
|
7
|
-
files: ImageFile[];
|
|
8
|
-
}
|
|
9
|
-
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
|
10
|
-
export interface ImageFile extends File {
|
|
11
|
-
key: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function extractFilesFromPageData(data: Record<string, any>, files?: any[]): ImageFile[];
|