@webiny/api-page-builder-import-export 0.0.0-unstable.3386f66516 → 0.0.0-unstable.39223eb3c1
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 +1 -1
- package/client.js +12 -25
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +2 -2
- package/export/combine/blocksHandler.js +14 -19
- package/export/combine/blocksHandler.js.map +1 -1
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/{pagesHandler.js → formsHandler.js} +25 -30
- package/export/combine/formsHandler.js.map +1 -0
- package/export/combine/index.d.ts +2 -2
- package/export/combine/index.js +24 -23
- package/export/combine/index.js.map +1 -1
- package/export/combine/templatesHandler.d.ts +2 -2
- package/export/combine/templatesHandler.js +14 -19
- package/export/combine/templatesHandler.js.map +1 -1
- 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 +2 -2
- package/export/process/blocksHandler.js +29 -36
- package/export/process/blocksHandler.js.map +1 -1
- 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/{pagesHandler.js → formsHandler.js} +48 -63
- package/export/process/formsHandler.js.map +1 -0
- package/export/process/index.d.ts +2 -2
- package/export/process/index.js +24 -23
- package/export/process/index.js.map +1 -1
- package/export/process/templatesHandler.d.ts +2 -2
- package/export/process/templatesHandler.js +29 -37
- package/export/process/templatesHandler.js.map +1 -1
- package/export/s3Stream.d.ts +16 -11
- package/export/s3Stream.js +27 -42
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +11 -9
- package/export/utils.js +54 -58
- package/export/utils.js.map +1 -1
- package/export/zipper.d.ts +7 -6
- package/export/zipper.js +46 -62
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.d.ts +1 -1
- package/graphql/crud/blocks.crud.js +65 -62
- package/graphql/crud/blocks.crud.js.map +1 -1
- 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 +2 -2
- package/graphql/crud/importExportTasks.crud.js +150 -165
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -1
- package/graphql/crud/pages.crud.js +241 -142
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +1 -1
- package/graphql/crud/templates.crud.js +63 -47
- package/graphql/crud/templates.crud.js.map +1 -1
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +4 -8
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +2 -2
- package/graphql/graphql/blocks.gql.js +8 -13
- package/graphql/graphql/blocks.gql.js.map +1 -1
- 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 +2 -2
- package/graphql/graphql/importExportTasks.gql.js +8 -13
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +104 -20
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +2 -2
- package/graphql/graphql/templates.gql.js +7 -12
- package/graphql/graphql/templates.gql.js.map +1 -1
- 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 -1
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +3 -7
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +4 -6
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +194 -31
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -1
- 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 +2 -2
- package/import/create/blocksHandler.js +13 -22
- package/import/create/blocksHandler.js.map +1 -1
- 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 +2 -2
- package/import/create/index.js +24 -23
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.d.ts +2 -2
- package/import/create/pagesHandler.js +12 -19
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.d.ts +2 -2
- package/import/create/templatesHandler.js +12 -19
- package/import/create/templatesHandler.js.map +1 -1
- 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/{blocksHandler.d.ts → blocks/blocksHandler.d.ts} +2 -2
- package/import/process/{blocksHandler.js → blocks/blocksHandler.js} +32 -38
- 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/{pagesHandler.js → forms/formsHandler.js} +54 -57
- 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 +2 -2
- package/import/process/index.js +26 -25
- package/import/process/index.js.map +1 -1
- 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/{templatesHandler.d.ts → templates/templatesHandler.d.ts} +2 -2
- package/import/process/{templatesHandler.js → templates/templatesHandler.js} +36 -34
- 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 -1
- package/package.json +36 -52
- 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 +23 -2
- package/types.js +60 -13
- package/types.js.map +1 -1
- package/utils/ZipFiles.d.ts +11 -0
- package/utils/ZipFiles.js +124 -0
- package/utils/ZipFiles.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +0 -6
- package/export/combine/pagesHandler.js.map +0 -1
- package/export/process/pagesHandler.d.ts +0 -6
- package/export/process/pagesHandler.js.map +0 -1
- package/import/process/blocksHandler.js.map +0 -1
- package/import/process/pagesHandler.d.ts +0 -3
- package/import/process/pagesHandler.js.map +0 -1
- package/import/process/templatesHandler.js.map +0 -1
- package/import/utils.d.ts +0 -56
- package/import/utils.js +0 -696
- package/import/utils.js.map +0 -1
package/export/utils.js
CHANGED
|
@@ -1,44 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
|
|
7
|
+
exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
|
|
9
8
|
exports.exportBlock = exportBlock;
|
|
10
9
|
exports.exportPage = exportPage;
|
|
11
10
|
exports.exportTemplate = exportTemplate;
|
|
12
11
|
exports.extractFilesFromData = extractFilesFromData;
|
|
13
|
-
|
|
14
12
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
15
|
-
|
|
16
13
|
var _zipper = _interopRequireDefault(require("./zipper"));
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
exports.
|
|
20
|
-
const
|
|
21
|
-
exports.EXPORT_BLOCKS_FOLDER_KEY = EXPORT_BLOCKS_FOLDER_KEY;
|
|
22
|
-
const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
|
|
23
|
-
exports.EXPORT_TEMPLATES_FOLDER_KEY = EXPORT_TEMPLATES_FOLDER_KEY;
|
|
24
|
-
|
|
14
|
+
const EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
|
15
|
+
const EXPORT_BLOCKS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
|
16
|
+
const EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
|
|
17
|
+
const EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
|
|
25
18
|
async function exportPage(page, exportPagesDataKey, fileManager) {
|
|
26
19
|
// Extract all files
|
|
27
|
-
const files = extractFilesFromData(page.content || {});
|
|
28
|
-
|
|
20
|
+
const files = extractFilesFromData(page.content || {});
|
|
21
|
+
// Extract images from page settings
|
|
29
22
|
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
|
30
|
-
const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);
|
|
31
|
-
|
|
23
|
+
const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);
|
|
24
|
+
// Get file data for all images
|
|
32
25
|
const imageFilesData = [];
|
|
33
|
-
|
|
34
26
|
if (fileIds.length > 0) {
|
|
35
|
-
const [filesData] = await fileManager.
|
|
36
|
-
|
|
27
|
+
const [filesData] = await fileManager.listFiles({
|
|
28
|
+
where: {
|
|
29
|
+
id_in: fileIds
|
|
30
|
+
}
|
|
37
31
|
});
|
|
38
32
|
imageFilesData.push(...filesData);
|
|
39
|
-
}
|
|
40
|
-
|
|
33
|
+
}
|
|
41
34
|
|
|
35
|
+
// Extract the page data in a json file and upload it to S3
|
|
42
36
|
const pageData = {
|
|
43
37
|
page: {
|
|
44
38
|
content: page.content,
|
|
@@ -61,32 +55,32 @@ async function exportPage(page, exportPagesDataKey, fileManager) {
|
|
|
61
55
|
});
|
|
62
56
|
return zipper.process();
|
|
63
57
|
}
|
|
64
|
-
|
|
65
|
-
async function exportBlock(block, exportBlocksDataKey, fileManager) {
|
|
58
|
+
async function exportBlock(block, blockCategory, exportBlocksDataKey, fileManager) {
|
|
66
59
|
// Extract all files
|
|
67
60
|
const files = extractFilesFromData(block.content || {});
|
|
68
|
-
const fileIds = files.map(imageFile => imageFile.id);
|
|
69
|
-
|
|
61
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
|
62
|
+
// Get file data for all images
|
|
70
63
|
const imageFilesData = [];
|
|
71
|
-
|
|
72
64
|
if (fileIds.length > 0) {
|
|
73
|
-
const [filesData] = await fileManager.
|
|
74
|
-
|
|
65
|
+
const [filesData] = await fileManager.listFiles({
|
|
66
|
+
where: {
|
|
67
|
+
id_in: fileIds
|
|
68
|
+
}
|
|
75
69
|
});
|
|
76
70
|
imageFilesData.push(...filesData);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (block.preview.id) {
|
|
81
|
-
imageFilesData.push(await fileManager.files.getFile(block.preview.id));
|
|
82
|
-
} // Extract the block data in a json file and upload it to S3
|
|
83
|
-
|
|
71
|
+
}
|
|
84
72
|
|
|
73
|
+
// Extract the block data in a json file and upload it to S3
|
|
85
74
|
const blockData = {
|
|
86
75
|
block: {
|
|
87
76
|
name: block.name,
|
|
88
|
-
content: block.content
|
|
89
|
-
|
|
77
|
+
content: block.content
|
|
78
|
+
},
|
|
79
|
+
category: {
|
|
80
|
+
name: blockCategory.name,
|
|
81
|
+
slug: blockCategory.slug,
|
|
82
|
+
icon: blockCategory.icon,
|
|
83
|
+
description: blockCategory.description
|
|
90
84
|
},
|
|
91
85
|
files: imageFilesData
|
|
92
86
|
};
|
|
@@ -101,27 +95,33 @@ async function exportBlock(block, exportBlocksDataKey, fileManager) {
|
|
|
101
95
|
});
|
|
102
96
|
return zipper.process();
|
|
103
97
|
}
|
|
104
|
-
|
|
105
98
|
async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
106
99
|
// Extract all files
|
|
107
100
|
const files = extractFilesFromData(template.content || {});
|
|
108
|
-
const fileIds = files.map(imageFile => imageFile.id);
|
|
109
|
-
|
|
101
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
|
102
|
+
// Get file data for all images
|
|
110
103
|
const imageFilesData = [];
|
|
111
|
-
|
|
112
104
|
if (fileIds.length > 0) {
|
|
113
|
-
const [filesData] = await fileManager.
|
|
114
|
-
|
|
105
|
+
const [filesData] = await fileManager.listFiles({
|
|
106
|
+
where: {
|
|
107
|
+
id_in: fileIds
|
|
108
|
+
}
|
|
115
109
|
});
|
|
116
110
|
imageFilesData.push(...filesData);
|
|
117
|
-
}
|
|
118
|
-
|
|
111
|
+
}
|
|
119
112
|
|
|
113
|
+
// Extract the template data in a json file and upload it to S3
|
|
120
114
|
const templateData = {
|
|
121
115
|
template: {
|
|
122
116
|
title: template.title,
|
|
117
|
+
slug: template.slug,
|
|
118
|
+
tags: template.tags,
|
|
123
119
|
description: template.description,
|
|
124
|
-
content: template.content
|
|
120
|
+
content: template.content,
|
|
121
|
+
layout: template.layout,
|
|
122
|
+
pageCategory: template.pageCategory,
|
|
123
|
+
dataSources: template.dataSources,
|
|
124
|
+
dataBindings: template.dataBindings
|
|
125
125
|
},
|
|
126
126
|
files: imageFilesData
|
|
127
127
|
};
|
|
@@ -136,29 +136,24 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
|
136
136
|
});
|
|
137
137
|
return zipper.process();
|
|
138
138
|
}
|
|
139
|
-
|
|
140
139
|
function extractFilesFromData(data, files = []) {
|
|
141
|
-
// Base case: termination
|
|
142
140
|
if (!data || typeof data !== "object") {
|
|
143
141
|
return files;
|
|
144
|
-
}
|
|
145
|
-
|
|
142
|
+
}
|
|
146
143
|
|
|
144
|
+
// Recursively call function for each element
|
|
147
145
|
if (Array.isArray(data)) {
|
|
148
146
|
for (let i = 0; i < data.length; i++) {
|
|
149
147
|
const element = data[i];
|
|
150
148
|
extractFilesFromData(element, files);
|
|
151
149
|
}
|
|
152
|
-
|
|
153
150
|
return files;
|
|
154
|
-
}
|
|
155
|
-
|
|
151
|
+
}
|
|
156
152
|
|
|
153
|
+
// Main
|
|
157
154
|
const tuple = Object.entries(data);
|
|
158
|
-
|
|
159
155
|
for (let i = 0; i < tuple.length; i++) {
|
|
160
|
-
const [key, value] = tuple[i];
|
|
161
|
-
|
|
156
|
+
const [key, value] = tuple[i];
|
|
162
157
|
if (key === "file" && value) {
|
|
163
158
|
files.push(value);
|
|
164
159
|
} else if (key === "images" && Array.isArray(value)) {
|
|
@@ -168,6 +163,7 @@ function extractFilesFromData(data, files = []) {
|
|
|
168
163
|
extractFilesFromData(value, files);
|
|
169
164
|
}
|
|
170
165
|
}
|
|
171
|
-
|
|
172
166
|
return files;
|
|
173
|
-
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=utils.js.map
|
package/export/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_TEMPLATES_FOLDER_KEY","exportPage","page","exportPagesDataKey","fileManager","files","extractFilesFromData","content","pageSettingsImages","get","filter","image","src","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","ids","push","pageData","title","path","version","status","settings","pageDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exportBlock","block","exportBlocksDataKey","preview","getFile","blockData","blockDataBuffer","exportTemplate","template","exportTemplatesDataKey","templateData","description","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, PageBlock, PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { FileManagerContext, File } from \"@webiny/api-file-manager/types\";\nimport get from \"lodash/get\";\nimport Zipper from \"./zipper\";\n\nexport const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\nexport const EXPORT_BLOCKS_FOLDER_KEY = \"WEBINY_PB_EXPORT_BLOCK\";\nexport const EXPORT_TEMPLATES_FOLDER_KEY = \"WEBINY_PB_EXPORT_TEMPLATE\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport async function exportPage(\n page: Page,\n exportPagesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromData(page.content || {});\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\") as unknown as File,\n get(page, \"settings.social.image\") as unknown as File\n ].filter(image => image && image.src);\n\n const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: imageFilesData\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: page.title,\n dataBuffer: pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\" | \"preview\">;\n files: File[];\n}\n\nexport async function exportBlock(\n block: PageBlock,\n exportBlocksDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromData(block.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n // Add block preview image file data\n if (block.preview.id) {\n imageFilesData.push(await fileManager.files.getFile(block.preview.id));\n }\n\n // Extract the block data in a json file and upload it to S3\n const blockData = {\n block: {\n name: block.name,\n content: block.content,\n preview: block.preview\n },\n files: imageFilesData\n };\n const blockDataBuffer = Buffer.from(JSON.stringify(blockData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: block.name,\n dataBuffer: blockDataBuffer\n },\n archiveFileKey: exportBlocksDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedTemplateData {\n template: Pick<PageTemplate, \"title\" | \"description\" | \"content\">;\n files: File[];\n}\n\nexport async function exportTemplate(\n template: PageTemplate,\n exportTemplatesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromData(template.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n\n // Extract the template data in a json file and upload it to S3\n const templateData = {\n template: {\n title: template.title,\n description: template.description,\n content: template.content\n },\n files: imageFilesData\n };\n const templateDataBuffer = Buffer.from(JSON.stringify(templateData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: template.title,\n dataBuffer: templateDataBuffer\n },\n archiveFileKey: exportTemplatesDataKey\n });\n\n return zipper.process();\n}\n\nexport function extractFilesFromData(data: Record<string, any>, files: any[] = []): File[] {\n // Base case: termination\n if (!data || typeof data !== \"object\") {\n return files;\n }\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAEO,MAAMA,uBAAuB,GAAG,wBAAhC;;AACA,MAAMC,wBAAwB,GAAG,wBAAjC;;AACA,MAAMC,2BAA2B,GAAG,2BAApC;;;AAOA,eAAeC,UAAf,CACHC,IADG,EAEHC,kBAFG,EAGHC,WAHG,EAI+B;EAClC;EACA,MAAMC,KAAK,GAAGC,oBAAoB,CAACJ,IAAI,CAACK,OAAL,IAAgB,EAAjB,CAAlC,CAFkC,CAGlC;;EACA,MAAMC,kBAAkB,GAAG,CACvB,IAAAC,YAAA,EAAIP,IAAJ,EAAU,wBAAV,CADuB,EAEvB,IAAAO,YAAA,EAAIP,IAAJ,EAAU,uBAAV,CAFuB,EAGzBQ,MAHyB,CAGlBC,KAAK,IAAIA,KAAK,IAAIA,KAAK,CAACC,GAHN,CAA3B;EAKA,MAAMC,OAAO,GAAG,CAAC,GAAGR,KAAJ,EAAW,GAAGG,kBAAd,EAAkCM,GAAlC,CAAsCC,SAAS,IAAIA,SAAS,CAACC,EAA7D,CAAhB,CATkC,CAUlC;;EACA,MAAMC,cAAc,GAAG,EAAvB;;EACA,IAAIJ,OAAO,CAACK,MAAR,GAAiB,CAArB,EAAwB;IACpB,MAAM,CAACC,SAAD,IAAc,MAAMf,WAAW,CAACC,KAAZ,CAAkBe,SAAlB,CAA4B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eP,IAAf,CAAd;;EACA,KAAK,IAAIG,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGE,KAAK,CAACzC,MAA1B,EAAkCuC,CAAC,EAAnC,EAAuC;IACnC,MAAM,CAACK,GAAD,EAAMC,KAAN,IAAeJ,KAAK,CAACF,CAAD,CAA1B,CADmC,CAEnC;;IACA,IAAIK,GAAG,KAAK,MAAR,IAAkBC,KAAtB,EAA6B;MACzB1D,KAAK,CAACiB,IAAN,CAAWyC,KAAX;IACH,CAFD,MAEO,IAAID,GAAG,KAAK,QAAR,IAAoBP,KAAK,CAACC,OAAN,CAAcO,KAAd,CAAxB,EAA8C;MACjD;MACA1D,KAAK,CAACiB,IAAN,CAAW,GAAGyC,KAAd;IACH,CAHM,MAGA;MACHzD,oBAAoB,CAACyD,KAAD,EAAQ1D,KAAR,CAApB;IACH;EACJ;;EACD,OAAOA,KAAP;AACH"}
|
|
1
|
+
{"version":3,"names":["_get","_interopRequireDefault","require","_zipper","EXPORT_PAGES_FOLDER_KEY","exports","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_TEMPLATES_FOLDER_KEY","EXPORT_FORMS_FOLDER_KEY","exportPage","page","exportPagesDataKey","fileManager","files","extractFilesFromData","content","pageSettingsImages","get","filter","image","src","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","pageData","title","path","version","status","settings","pageDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exportBlock","block","blockCategory","exportBlocksDataKey","blockData","category","slug","icon","description","blockDataBuffer","exportTemplate","template","exportTemplatesDataKey","templateData","tags","layout","pageCategory","dataSources","dataBindings","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport type {\n BlockCategory,\n Page,\n PageBlock,\n PageTemplate,\n PageTemplateInput\n} from \"@webiny/api-page-builder/types\";\nimport type { FileManagerContext, File } from \"@webiny/api-file-manager/types\";\nimport get from \"lodash/get\";\nimport Zipper from \"./zipper\";\n\nexport const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\nexport const EXPORT_BLOCKS_FOLDER_KEY = \"WEBINY_PB_EXPORT_BLOCK\";\nexport const EXPORT_TEMPLATES_FOLDER_KEY = \"WEBINY_PB_EXPORT_TEMPLATE\";\nexport const EXPORT_FORMS_FOLDER_KEY = \"WEBINY_FB_EXPORT_FORM\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport async function exportPage(\n page: Page,\n exportPagesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(page.content || {});\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\") as unknown as File,\n get(page, \"settings.social.image\") as unknown as File\n ].filter(image => image && image.src);\n\n const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: imageFilesData\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: page.title,\n dataBuffer: pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\">;\n category: BlockCategory;\n files: File[];\n}\n\nexport async function exportBlock(\n block: PageBlock,\n blockCategory: BlockCategory,\n exportBlocksDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(block.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the block data in a json file and upload it to S3\n const blockData = {\n block: {\n name: block.name,\n content: block.content\n },\n category: {\n name: blockCategory.name,\n slug: blockCategory.slug,\n icon: blockCategory.icon,\n description: blockCategory.description\n },\n files: imageFilesData\n };\n const blockDataBuffer = Buffer.from(JSON.stringify(blockData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: block.name,\n dataBuffer: blockDataBuffer\n },\n archiveFileKey: exportBlocksDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedTemplateData {\n template: Pick<\n PageTemplate,\n | \"title\"\n | \"slug\"\n | \"tags\"\n | \"description\"\n | \"content\"\n | \"layout\"\n | \"pageCategory\"\n | \"dataSources\"\n | \"dataBindings\"\n >;\n files: File[];\n}\n\nexport async function exportTemplate(\n template: PageTemplate,\n exportTemplatesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(template.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the template data in a json file and upload it to S3\n const templateData: { template: PageTemplateInput; files: File[] } = {\n template: {\n title: template.title,\n slug: template.slug,\n tags: template.tags,\n description: template.description,\n content: template.content,\n layout: template.layout,\n pageCategory: template.pageCategory,\n dataSources: template.dataSources,\n dataBindings: template.dataBindings\n },\n files: imageFilesData\n };\n const templateDataBuffer = Buffer.from(JSON.stringify(templateData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: template.title,\n dataBuffer: templateDataBuffer\n },\n archiveFileKey: exportTemplatesDataKey\n });\n\n return zipper.process();\n}\n\nexport function extractFilesFromData(data: Record<string, any>, files: File[] = []) {\n if (!data || typeof data !== \"object\") {\n return files;\n }\n\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;AASA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEO,MAAME,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,wBAAwB;AACxD,MAAME,wBAAwB,GAAAD,OAAA,CAAAC,wBAAA,GAAG,wBAAwB;AACzD,MAAMC,2BAA2B,GAAAF,OAAA,CAAAE,2BAAA,GAAG,2BAA2B;AAC/D,MAAMC,uBAAuB,GAAAH,OAAA,CAAAG,uBAAA,GAAG,uBAAuB;AAOvD,eAAeC,UAAUA,CAC5BC,IAAU,EACVC,kBAA0B,EAC1BC,WAA8C,EACR;EACtC;EACA,MAAMC,KAAK,GAAGC,oBAAoB,CAACJ,IAAI,CAACK,OAAO,IAAI,CAAC,CAAC,CAAC;EACtD;EACA,MAAMC,kBAAkB,GAAG,CACvB,IAAAC,YAAG,EAACP,IAAI,EAAE,wBAAwB,CAAC,EACnC,IAAAO,YAAG,EAACP,IAAI,EAAE,uBAAuB,CAAC,CACrC,CAACQ,MAAM,CAACC,KAAK,IAAIA,KAAK,IAAIA,KAAK,CAACC,GAAG,CAAC;EAErC,MAAMC,OAAO,G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EAAEzD,KAAa,GAAG,EAAE,EAAE;EAChF,IAAI,CAACyD,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACnC,OAAOzD,KAAK;EAChB;;EAEA;EACA,IAAI0D,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;IACrB,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAAC5C,MAAM,EAAE+C,CAAC,EAAE,EAAE;MAClC,MAAMC,OAAO,GAAGJ,IAAI,CAACG,CAAC,CAAC;MACvB3D,oBAAoB,CAAC4D,OAAO,EAAE7D,KAAK,CAAC;IACxC;IACA,OAAOA,KAAK;EAChB;;EAEA;EACA,MAAM8D,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACP,IAAI,CAAC;EAClC,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGE,KAAK,CAACjD,MAAM,EAAE+C,CAAC,EAAE,EAAE;IACnC,MAAM,CAACK,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACF,CAAC,CAAC;IAC7B,IAAIK,GAAG,KAAK,MAAM,IAAIC,KAAK,EAAE;MACzBlE,KAAK,CAACkB,IAAI,CAACgD,KAAK,CAAC;IACrB,CAAC,MAAM,IAAID,GAAG,KAAK,QAAQ,IAAIP,KAAK,CAACC,OAAO,CAACO,KAAK,CAAC,EAAE;MACjD;MACAlE,KAAK,CAACkB,IAAI,CAAC,GAAGgD,KAAK,CAAC;IACxB,CAAC,MAAM;MACHjE,oBAAoB,CAACiE,KAAK,EAAElE,KAAK,CAAC;IACtC;EACJ;EACA,OAAOA,KAAK;AAChB","ignoreList":[]}
|
package/export/zipper.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
|
|
4
5
|
import { Readable } from "stream";
|
|
5
|
-
import { File } from "@webiny/api-file-manager/types";
|
|
6
|
+
import type { File } from "@webiny/api-file-manager/types";
|
|
6
7
|
interface FileStreamDetails {
|
|
7
8
|
stream: Readable;
|
|
8
9
|
filename: string;
|
|
@@ -22,8 +23,8 @@ export default class Zipper {
|
|
|
22
23
|
private readonly archiveFileName;
|
|
23
24
|
config: ZipperConfig;
|
|
24
25
|
constructor(config: ZipperConfig);
|
|
25
|
-
s3DownloadStreams(): FileStreamDetails[]
|
|
26
|
-
process(): Promise<
|
|
26
|
+
s3DownloadStreams(): Promise<FileStreamDetails[]>;
|
|
27
|
+
process(): Promise<CompleteMultipartUploadOutput>;
|
|
27
28
|
}
|
|
28
29
|
export declare class ZipOfZip {
|
|
29
30
|
private readonly archiveFormat;
|
|
@@ -31,7 +32,7 @@ export declare class ZipOfZip {
|
|
|
31
32
|
keys: string[];
|
|
32
33
|
filename: string;
|
|
33
34
|
constructor(keys: string[], filename: string);
|
|
34
|
-
getFileStreams(): FileStreamDetails[]
|
|
35
|
-
process(): Promise<
|
|
35
|
+
getFileStreams(): Promise<FileStreamDetails[]>;
|
|
36
|
+
process(): Promise<CompleteMultipartUploadOutput>;
|
|
36
37
|
}
|
|
37
38
|
export {};
|
package/export/zipper.js
CHANGED
|
@@ -1,136 +1,120 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = exports.ZipOfZip = void 0;
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
9
|
var _archiver = _interopRequireDefault(require("archiver"));
|
|
15
|
-
|
|
16
10
|
var _stream = require("stream");
|
|
17
|
-
|
|
18
11
|
var path = _interopRequireWildcard(require("path"));
|
|
19
|
-
|
|
20
12
|
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
|
|
21
|
-
|
|
22
13
|
var _uniqid = _interopRequireDefault(require("uniqid"));
|
|
23
|
-
|
|
24
14
|
var _s3Stream = require("./s3Stream");
|
|
25
|
-
|
|
26
15
|
// TODO: Move "archive" in layer
|
|
16
|
+
|
|
27
17
|
class Zipper {
|
|
18
|
+
archiveFormat = "zip";
|
|
19
|
+
filesDirName = "assets";
|
|
28
20
|
constructor(config) {
|
|
29
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
|
30
|
-
(0, _defineProperty2.default)(this, "filesDirName", "assets");
|
|
31
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
|
32
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
|
33
21
|
this.config = config;
|
|
34
22
|
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
|
|
35
23
|
}
|
|
36
|
-
|
|
37
|
-
s3DownloadStreams() {
|
|
24
|
+
async s3DownloadStreams() {
|
|
38
25
|
const exportInfo = this.config.exportInfo;
|
|
39
26
|
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
|
|
40
|
-
const files = exportInfo.files.map(({
|
|
27
|
+
const files = await Promise.all(exportInfo.files.map(async ({
|
|
41
28
|
key
|
|
42
29
|
}) => {
|
|
43
30
|
return {
|
|
44
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
|
45
|
-
filename: `${prefix}\\${this.filesDirName}\\${
|
|
31
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
|
32
|
+
filename: `${prefix}\\${this.filesDirName}\\${key}`
|
|
46
33
|
};
|
|
47
|
-
});
|
|
34
|
+
}));
|
|
48
35
|
return [...files, {
|
|
49
36
|
stream: _stream.Readable.from(exportInfo.dataBuffer),
|
|
50
37
|
filename: `${prefix}\\${exportInfo.name}.json`
|
|
51
38
|
}];
|
|
52
39
|
}
|
|
53
|
-
|
|
54
|
-
process() {
|
|
40
|
+
async process() {
|
|
55
41
|
const {
|
|
56
42
|
streamPassThrough,
|
|
57
43
|
streamPassThroughUploadPromise
|
|
58
|
-
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const s3FilesStreams = this.s3DownloadStreams(); // 2. Prepare zip from the file stream.
|
|
62
|
-
|
|
63
|
-
const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
|
|
44
|
+
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
|
64
45
|
|
|
46
|
+
// 1. Read all files from S3 using stream.
|
|
47
|
+
const s3FilesStreams = await this.s3DownloadStreams();
|
|
65
48
|
|
|
49
|
+
// 2. Prepare zip from the file stream.
|
|
50
|
+
const archive = _archiver.default.create(this.archiveFormat);
|
|
51
|
+
// Handle archive events.
|
|
66
52
|
archive.on("error", error => {
|
|
67
53
|
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
|
68
|
-
});
|
|
54
|
+
});
|
|
69
55
|
|
|
56
|
+
// Append all file streams to archive.
|
|
70
57
|
s3FilesStreams.forEach(streamDetails => archive.append(streamDetails.stream, {
|
|
71
58
|
name: streamDetails.filename
|
|
72
|
-
}));
|
|
59
|
+
}));
|
|
73
60
|
|
|
74
|
-
|
|
61
|
+
// Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
|
|
62
|
+
archive.pipe(streamPassThrough);
|
|
63
|
+
// Finalize the archive (ie we are done appending files but streams have to finish yet)
|
|
75
64
|
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
|
65
|
+
archive.finalize();
|
|
76
66
|
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
// 3. Return upload stream promise.
|
|
79
68
|
return streamPassThroughUploadPromise;
|
|
80
69
|
}
|
|
81
|
-
|
|
82
70
|
}
|
|
83
|
-
|
|
84
71
|
exports.default = Zipper;
|
|
85
|
-
|
|
86
72
|
class ZipOfZip {
|
|
73
|
+
archiveFormat = "zip";
|
|
87
74
|
constructor(keys, filename) {
|
|
88
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
|
89
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
|
90
|
-
(0, _defineProperty2.default)(this, "keys", void 0);
|
|
91
|
-
(0, _defineProperty2.default)(this, "filename", void 0);
|
|
92
75
|
this.keys = keys;
|
|
93
76
|
this.filename = filename;
|
|
94
|
-
this.archiveFileName = (0, _uniqid.default)("", `-${filename}`);
|
|
77
|
+
this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
|
|
95
78
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return this.keys.map(key => {
|
|
79
|
+
async getFileStreams() {
|
|
80
|
+
return await Promise.all(this.keys.map(async key => {
|
|
99
81
|
return {
|
|
100
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
|
82
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
|
101
83
|
filename: `${path.basename(key)}`
|
|
102
84
|
};
|
|
103
|
-
});
|
|
85
|
+
}));
|
|
104
86
|
}
|
|
105
|
-
|
|
106
|
-
process() {
|
|
87
|
+
async process() {
|
|
107
88
|
const {
|
|
108
89
|
streamPassThrough,
|
|
109
90
|
streamPassThroughUploadPromise
|
|
110
|
-
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const fileStreamDetails = this.getFileStreams(); // 2. Prepare zip from the file stream.
|
|
114
|
-
|
|
115
|
-
const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
|
|
91
|
+
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
|
116
92
|
|
|
93
|
+
// 1. Read all files from S3 using stream.
|
|
94
|
+
const fileStreamDetails = await this.getFileStreams();
|
|
117
95
|
|
|
96
|
+
// 2. Prepare zip from the file stream.
|
|
97
|
+
const archive = _archiver.default.create(this.archiveFormat);
|
|
98
|
+
// Handle archive events.
|
|
118
99
|
archive.on("error", error => {
|
|
119
100
|
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
|
120
|
-
});
|
|
101
|
+
});
|
|
121
102
|
|
|
103
|
+
// Append all file streams to archive.
|
|
122
104
|
fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
|
|
123
105
|
name: streamDetails.filename
|
|
124
|
-
}));
|
|
106
|
+
}));
|
|
125
107
|
|
|
126
|
-
|
|
108
|
+
// Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
|
|
109
|
+
archive.pipe(streamPassThrough);
|
|
110
|
+
// Finalize the archive (ie we are done appending files but streams have to finish yet)
|
|
127
111
|
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
|
112
|
+
archive.finalize();
|
|
128
113
|
|
|
129
|
-
|
|
130
|
-
|
|
114
|
+
// 3. Return upload stream promise.
|
|
131
115
|
return streamPassThroughUploadPromise;
|
|
132
116
|
}
|
|
133
|
-
|
|
134
117
|
}
|
|
118
|
+
exports.ZipOfZip = ZipOfZip;
|
|
135
119
|
|
|
136
|
-
|
|
120
|
+
//# sourceMappingURL=zipper.js.map
|
package/export/zipper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","
|
|
1
|
+
{"version":3,"names":["_archiver","_interopRequireDefault","require","_stream","path","_interopRequireWildcard","_kebabCase","_uniqid","_s3Stream","Zipper","archiveFormat","filesDirName","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","Promise","all","map","key","stream","s3Stream","readStream","filename","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","on","error","Error","code","message","stack","forEach","streamDetails","append","pipe","finalize","exports","default","ZipOfZip","keys","getFileStreams","basename","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport type { ArchiverError } from \"archiver\";\nimport vending from \"archiver\";\nimport type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport type { File } from \"@webiny/api-file-manager/types\";\n\ninterface FileStreamDetails {\n stream: Readable;\n filename: string;\n}\n\ninterface ExportInfo {\n files: File[];\n name: string;\n dataBuffer: Buffer;\n}\n\nexport interface ZipperConfig {\n exportInfo: ExportInfo;\n archiveFileKey: string;\n}\n\nexport default class Zipper {\n private readonly archiveFormat = \"zip\";\n private readonly filesDirName = \"assets\";\n private readonly archiveFileName: string;\n config: ZipperConfig;\n\n constructor(config: ZipperConfig) {\n this.config = config;\n this.archiveFileName = uniqueId(\n `${this.config.archiveFileKey}/`,\n `-${kebabCase(this.config.exportInfo.name)}.zip`\n );\n }\n\n async s3DownloadStreams(): Promise<FileStreamDetails[]> {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.name)}`);\n const files = await Promise.all(\n exportInfo.files.map(async ({ key }) => {\n return {\n stream: await s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${key}`\n };\n })\n );\n\n return [\n ...files,\n {\n stream: Readable.from(exportInfo.dataBuffer),\n filename: `${prefix}\\\\${exportInfo.name}.json`\n }\n ];\n }\n\n async process(): Promise<CompleteMultipartUploadOutput> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = await this.s3DownloadStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n s3FilesStreams.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n\nexport class ZipOfZip {\n private readonly archiveFormat = \"zip\";\n private readonly archiveFileName: string;\n keys: string[];\n filename: string;\n\n constructor(keys: string[], filename: string) {\n this.keys = keys;\n this.filename = filename;\n this.archiveFileName = uniqueId(\"EXPORTS/\", `-${filename}`);\n }\n\n async getFileStreams(): Promise<FileStreamDetails[]> {\n return await Promise.all(\n this.keys.map(async key => {\n return {\n stream: await s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n })\n );\n }\n\n async process(): Promise<CompleteMultipartUploadOutput> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = await this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AARA;;AA2Be,MAAMO,MAAM,CAAC;EACPC,aAAa,GAAG,KAAK;EACrBC,YAAY,GAAG,QAAQ;EAIxCC,WAAWA,CAACC,MAAoB,EAAE;IAC9B,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,eAAe,GAAG,IAAAC,eAAQ,EAC3B,GAAG,IAAI,CAACF,MAAM,CAACG,cAAc,GAAG,EAChC,IAAI,IAAAC,kBAAS,EAAC,IAAI,CAACJ,MAAM,CAACK,UAAU,CAACC,IAAI,CAAC,MAC9C,CAAC;EACL;EAEA,MAAMC,iBAAiBA,CAAA,EAAiC;IACpD,MAAMF,UAAU,GAAG,IAAI,CAACL,MAAM,CAACK,UAAU;IACzC,MAAMG,MAAM,GAAG,IAAAN,eAAQ,EAAC,EAAE,EAAE,IAAI,IAAAE,kBAAS,EAACC,UAAU,CAACC,IAAI,CAAC,EAAE,CAAC;IAC7D,MAAMG,KAAK,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC3BN,UAAU,CAACI,KAAK,CAACG,GAAG,CAAC,OAAO;MAAEC;IAAI,CAAC,KAAK;MACpC,OAAO;QACHC,MAAM,EAAE,MAAMC,kBAAQ,CAACC,UAAU,CAACH,GAAG,CAAC;QACtCI,QAAQ,EAAE,GAAGT,MAAM,KAAK,IAAI,CAACV,YAAY,KAA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