@webiny/api-page-builder-import-export 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.7c9e8fbfd6
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 +2 -2
- package/client.js +12 -21
- package/client.js.map +1 -1
- 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/{exportPages → export}/combine/index.d.ts +4 -3
- 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/{exportPages → export}/process/index.d.ts +5 -7
- 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/{exportPages → export}/s3Stream.js +27 -23
- 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 +12 -10
- package/{exportPages → export}/zipper.js +26 -29
- 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 +2 -2
- package/graphql/crud/pages.crud.js +238 -117
- package/graphql/crud/pages.crud.js.map +1 -1
- 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 -3
- package/graphql/crud.js.map +1 -1
- 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 +103 -20
- package/graphql/graphql/pages.gql.js.map +1 -1
- 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 +16 -5
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +7 -3
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +5 -2
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +237 -37
- 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 +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/{importPages → import}/process/index.d.ts +6 -4
- 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 +3 -2
- 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 +83 -65
- package/types.js +69 -17
- 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/exportPages/combine/index.js +0 -106
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -192
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/s3Stream.d.ts +0 -31
- package/exportPages/s3Stream.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -100
- package/exportPages/utils.js.map +0 -1
- package/exportPages/zipper.js.map +0 -1
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js +0 -363
- package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js +0 -75
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- package/importPages/create/index.d.ts +0 -22
- package/importPages/create/index.js +0 -107
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -180
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.d.ts +0 -50
- package/importPages/utils.js +0 -488
- package/importPages/utils.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
|
|
2
|
+
import type { BlockCategory, Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
|
|
3
|
+
import type { FileManagerContext, File } from "@webiny/api-file-manager/types";
|
|
4
|
+
export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
|
5
|
+
export declare const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
|
6
|
+
export declare const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
|
|
7
|
+
export declare const EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
|
|
8
|
+
export interface ExportedPageData {
|
|
9
|
+
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
|
10
|
+
files: File[];
|
|
11
|
+
}
|
|
12
|
+
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
|
|
13
|
+
export interface ExportedBlockData {
|
|
14
|
+
block: Pick<PageBlock, "name" | "content">;
|
|
15
|
+
category: BlockCategory;
|
|
16
|
+
files: File[];
|
|
17
|
+
}
|
|
18
|
+
export declare function exportBlock(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
|
|
19
|
+
export interface ExportedTemplateData {
|
|
20
|
+
template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory" | "dataSources" | "dataBindings">;
|
|
21
|
+
files: File[];
|
|
22
|
+
}
|
|
23
|
+
export declare function exportTemplate(template: PageTemplate, exportTemplatesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
|
|
24
|
+
export declare function extractFilesFromData(data: Record<string, any>, files?: File[]): File[];
|
package/export/utils.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
|
|
8
|
+
exports.exportBlock = exportBlock;
|
|
9
|
+
exports.exportPage = exportPage;
|
|
10
|
+
exports.exportTemplate = exportTemplate;
|
|
11
|
+
exports.extractFilesFromData = extractFilesFromData;
|
|
12
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
13
|
+
var _zipper = _interopRequireDefault(require("./zipper"));
|
|
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";
|
|
18
|
+
async function exportPage(page, exportPagesDataKey, fileManager) {
|
|
19
|
+
// Extract all files
|
|
20
|
+
const files = extractFilesFromData(page.content || {});
|
|
21
|
+
// Extract images from page settings
|
|
22
|
+
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
|
23
|
+
const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);
|
|
24
|
+
// Get file data for all images
|
|
25
|
+
const imageFilesData = [];
|
|
26
|
+
if (fileIds.length > 0) {
|
|
27
|
+
const [filesData] = await fileManager.listFiles({
|
|
28
|
+
where: {
|
|
29
|
+
id_in: fileIds
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
imageFilesData.push(...filesData);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Extract the page data in a json file and upload it to S3
|
|
36
|
+
const pageData = {
|
|
37
|
+
page: {
|
|
38
|
+
content: page.content,
|
|
39
|
+
title: page.title,
|
|
40
|
+
path: page.path,
|
|
41
|
+
version: page.version,
|
|
42
|
+
status: page.status,
|
|
43
|
+
settings: page.settings
|
|
44
|
+
},
|
|
45
|
+
files: imageFilesData
|
|
46
|
+
};
|
|
47
|
+
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
|
48
|
+
const zipper = new _zipper.default({
|
|
49
|
+
exportInfo: {
|
|
50
|
+
files: imageFilesData,
|
|
51
|
+
name: page.title,
|
|
52
|
+
dataBuffer: pageDataBuffer
|
|
53
|
+
},
|
|
54
|
+
archiveFileKey: exportPagesDataKey
|
|
55
|
+
});
|
|
56
|
+
return zipper.process();
|
|
57
|
+
}
|
|
58
|
+
async function exportBlock(block, blockCategory, exportBlocksDataKey, fileManager) {
|
|
59
|
+
// Extract all files
|
|
60
|
+
const files = extractFilesFromData(block.content || {});
|
|
61
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
|
62
|
+
// Get file data for all images
|
|
63
|
+
const imageFilesData = [];
|
|
64
|
+
if (fileIds.length > 0) {
|
|
65
|
+
const [filesData] = await fileManager.listFiles({
|
|
66
|
+
where: {
|
|
67
|
+
id_in: fileIds
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
imageFilesData.push(...filesData);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Extract the block data in a json file and upload it to S3
|
|
74
|
+
const blockData = {
|
|
75
|
+
block: {
|
|
76
|
+
name: block.name,
|
|
77
|
+
content: block.content
|
|
78
|
+
},
|
|
79
|
+
category: {
|
|
80
|
+
name: blockCategory.name,
|
|
81
|
+
slug: blockCategory.slug,
|
|
82
|
+
icon: blockCategory.icon,
|
|
83
|
+
description: blockCategory.description
|
|
84
|
+
},
|
|
85
|
+
files: imageFilesData
|
|
86
|
+
};
|
|
87
|
+
const blockDataBuffer = Buffer.from(JSON.stringify(blockData));
|
|
88
|
+
const zipper = new _zipper.default({
|
|
89
|
+
exportInfo: {
|
|
90
|
+
files: imageFilesData,
|
|
91
|
+
name: block.name,
|
|
92
|
+
dataBuffer: blockDataBuffer
|
|
93
|
+
},
|
|
94
|
+
archiveFileKey: exportBlocksDataKey
|
|
95
|
+
});
|
|
96
|
+
return zipper.process();
|
|
97
|
+
}
|
|
98
|
+
async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
99
|
+
// Extract all files
|
|
100
|
+
const files = extractFilesFromData(template.content || {});
|
|
101
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
|
102
|
+
// Get file data for all images
|
|
103
|
+
const imageFilesData = [];
|
|
104
|
+
if (fileIds.length > 0) {
|
|
105
|
+
const [filesData] = await fileManager.listFiles({
|
|
106
|
+
where: {
|
|
107
|
+
id_in: fileIds
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
imageFilesData.push(...filesData);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Extract the template data in a json file and upload it to S3
|
|
114
|
+
const templateData = {
|
|
115
|
+
template: {
|
|
116
|
+
title: template.title,
|
|
117
|
+
slug: template.slug,
|
|
118
|
+
tags: template.tags,
|
|
119
|
+
description: template.description,
|
|
120
|
+
content: template.content,
|
|
121
|
+
layout: template.layout,
|
|
122
|
+
pageCategory: template.pageCategory,
|
|
123
|
+
dataSources: template.dataSources,
|
|
124
|
+
dataBindings: template.dataBindings
|
|
125
|
+
},
|
|
126
|
+
files: imageFilesData
|
|
127
|
+
};
|
|
128
|
+
const templateDataBuffer = Buffer.from(JSON.stringify(templateData));
|
|
129
|
+
const zipper = new _zipper.default({
|
|
130
|
+
exportInfo: {
|
|
131
|
+
files: imageFilesData,
|
|
132
|
+
name: template.title,
|
|
133
|
+
dataBuffer: templateDataBuffer
|
|
134
|
+
},
|
|
135
|
+
archiveFileKey: exportTemplatesDataKey
|
|
136
|
+
});
|
|
137
|
+
return zipper.process();
|
|
138
|
+
}
|
|
139
|
+
function extractFilesFromData(data, files = []) {
|
|
140
|
+
if (!data || typeof data !== "object") {
|
|
141
|
+
return files;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Recursively call function for each element
|
|
145
|
+
if (Array.isArray(data)) {
|
|
146
|
+
for (let i = 0; i < data.length; i++) {
|
|
147
|
+
const element = data[i];
|
|
148
|
+
extractFilesFromData(element, files);
|
|
149
|
+
}
|
|
150
|
+
return files;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Main
|
|
154
|
+
const tuple = Object.entries(data);
|
|
155
|
+
for (let i = 0; i < tuple.length; i++) {
|
|
156
|
+
const [key, value] = tuple[i];
|
|
157
|
+
if (key === "file" && value) {
|
|
158
|
+
files.push(value);
|
|
159
|
+
} else if (key === "images" && Array.isArray(value)) {
|
|
160
|
+
// Handle case for "images-list" component
|
|
161
|
+
files.push(...value);
|
|
162
|
+
} else {
|
|
163
|
+
extractFilesFromData(value, files);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return files;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,GAAG,CAAC,GAAGR,KAAK,EAAE,GAA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AChF,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":[]}
|
|
@@ -1,16 +1,17 @@
|
|
|
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 {
|
|
6
|
+
import type { File } from "@webiny/api-file-manager/types";
|
|
6
7
|
interface FileStreamDetails {
|
|
7
8
|
stream: Readable;
|
|
8
9
|
filename: string;
|
|
9
10
|
}
|
|
10
11
|
interface ExportInfo {
|
|
11
|
-
files:
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
files: File[];
|
|
13
|
+
name: string;
|
|
14
|
+
dataBuffer: Buffer;
|
|
14
15
|
}
|
|
15
16
|
export interface ZipperConfig {
|
|
16
17
|
exportInfo: ExportInfo;
|
|
@@ -22,15 +23,16 @@ 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;
|
|
30
31
|
private readonly archiveFileName;
|
|
31
32
|
keys: string[];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
filename: string;
|
|
34
|
+
constructor(keys: string[], filename: string);
|
|
35
|
+
getFileStreams(): Promise<FileStreamDetails[]>;
|
|
36
|
+
process(): Promise<CompleteMultipartUploadOutput>;
|
|
35
37
|
}
|
|
36
38
|
export {};
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = exports.ZipOfZip = void 0;
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
9
|
var _archiver = _interopRequireDefault(require("archiver"));
|
|
11
10
|
var _stream = require("stream");
|
|
12
11
|
var path = _interopRequireWildcard(require("path"));
|
|
@@ -16,38 +15,36 @@ var _s3Stream = require("./s3Stream");
|
|
|
16
15
|
// TODO: Move "archive" in layer
|
|
17
16
|
|
|
18
17
|
class Zipper {
|
|
18
|
+
archiveFormat = "zip";
|
|
19
|
+
filesDirName = "assets";
|
|
19
20
|
constructor(config) {
|
|
20
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
|
21
|
-
(0, _defineProperty2.default)(this, "filesDirName", "assets");
|
|
22
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
|
23
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
|
24
21
|
this.config = config;
|
|
25
|
-
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.
|
|
22
|
+
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
|
|
26
23
|
}
|
|
27
|
-
s3DownloadStreams() {
|
|
24
|
+
async s3DownloadStreams() {
|
|
28
25
|
const exportInfo = this.config.exportInfo;
|
|
29
|
-
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.
|
|
30
|
-
const files = exportInfo.files.map(({
|
|
26
|
+
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
|
|
27
|
+
const files = await Promise.all(exportInfo.files.map(async ({
|
|
31
28
|
key
|
|
32
29
|
}) => {
|
|
33
30
|
return {
|
|
34
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
|
35
|
-
filename: `${prefix}\\${this.filesDirName}\\${
|
|
31
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
|
32
|
+
filename: `${prefix}\\${this.filesDirName}\\${key}`
|
|
36
33
|
};
|
|
37
|
-
});
|
|
34
|
+
}));
|
|
38
35
|
return [...files, {
|
|
39
|
-
stream: _stream.Readable.from(exportInfo.
|
|
40
|
-
filename: `${prefix}\\${exportInfo.
|
|
36
|
+
stream: _stream.Readable.from(exportInfo.dataBuffer),
|
|
37
|
+
filename: `${prefix}\\${exportInfo.name}.json`
|
|
41
38
|
}];
|
|
42
39
|
}
|
|
43
|
-
process() {
|
|
40
|
+
async process() {
|
|
44
41
|
const {
|
|
45
42
|
streamPassThrough,
|
|
46
43
|
streamPassThroughUploadPromise
|
|
47
44
|
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
|
48
45
|
|
|
49
46
|
// 1. Read all files from S3 using stream.
|
|
50
|
-
const s3FilesStreams = this.s3DownloadStreams();
|
|
47
|
+
const s3FilesStreams = await this.s3DownloadStreams();
|
|
51
48
|
|
|
52
49
|
// 2. Prepare zip from the file stream.
|
|
53
50
|
const archive = _archiver.default.create(this.archiveFormat);
|
|
@@ -72,31 +69,29 @@ class Zipper {
|
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
exports.default = Zipper;
|
|
75
|
-
const PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;
|
|
76
72
|
class ZipOfZip {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
|
80
|
-
(0, _defineProperty2.default)(this, "keys", void 0);
|
|
73
|
+
archiveFormat = "zip";
|
|
74
|
+
constructor(keys, filename) {
|
|
81
75
|
this.keys = keys;
|
|
82
|
-
this.
|
|
76
|
+
this.filename = filename;
|
|
77
|
+
this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
|
|
83
78
|
}
|
|
84
|
-
getFileStreams() {
|
|
85
|
-
return this.keys.map(key => {
|
|
79
|
+
async getFileStreams() {
|
|
80
|
+
return await Promise.all(this.keys.map(async key => {
|
|
86
81
|
return {
|
|
87
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
|
82
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
|
88
83
|
filename: `${path.basename(key)}`
|
|
89
84
|
};
|
|
90
|
-
});
|
|
85
|
+
}));
|
|
91
86
|
}
|
|
92
|
-
process() {
|
|
87
|
+
async process() {
|
|
93
88
|
const {
|
|
94
89
|
streamPassThrough,
|
|
95
90
|
streamPassThroughUploadPromise
|
|
96
91
|
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
|
97
92
|
|
|
98
93
|
// 1. Read all files from S3 using stream.
|
|
99
|
-
const fileStreamDetails = this.getFileStreams();
|
|
94
|
+
const fileStreamDetails = await this.getFileStreams();
|
|
100
95
|
|
|
101
96
|
// 2. Prepare zip from the file stream.
|
|
102
97
|
const archive = _archiver.default.create(this.archiveFormat);
|
|
@@ -120,4 +115,6 @@ class ZipOfZip {
|
|
|
120
115
|
return streamPassThroughUploadPromise;
|
|
121
116
|
}
|
|
122
117
|
}
|
|
123
|
-
exports.ZipOfZip = ZipOfZip;
|
|
118
|
+
exports.ZipOfZip = ZipOfZip;
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=zipper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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;EACL;EAEA,MAAMQ,OAAOA,CAAA,EAA2C;IACpD,MAAM;MAAEC,iBAAiB;MAAEC;IAA+B,CAAC,GAAGR,kBAAQ,CAACS,WAAW,CAC9E,IAAI,CAACvB,eACT,CAAC;;IAED;IACA,MAAM6C,iBAAiB,GAAG,MAAM,IAAI,CAACF,cAAc,CAAC,CAAC;;IAErD;IACA,MAAMlB,OAAO,GAAGC,iBAAO,CAACC,MAAM,CAAC,IAAI,CAAC/B,aAAa,CAAC;IAClD;IACA6B,OAAO,CAACG,EAAE,CAAC,OAAO,EAAGC,KAAoB,IAAK;MAC1C,MAAM,IAAIC,KAAK,CACX,GAAGD,KAAK,CAACxB,IAAI,IAAIwB,KAAK,CAACE,IAAI,IAAIF,KAAK,CAACG,OAAO,IAAIH,KAAK,CAACvC,IAAI,IAAIuC,KAAK,CAACI,KAAK,EAC7E,CAAC;IACL,CAAC,CAAC;;IAEF;IACAY,iBAAiB,CAACX,OAAO,CAAEC,aAAgC,IACvDV,OAAO,CAACW,MAAM,CAACD,aAAa,CAACtB,MAAM,EAAE;MAAER,IAAI,EAAE8B,aAAa,CAACnB;IAAS,CAAC,CACzE,CAAC;;IAED;IACAS,OAAO,CAACY,IAAI,CAAChB,iBAAiB,CAAC;IAC/B;IACA;IACAI,OAAO,CAACa,QAAQ,CAAC,CAAC;;IAElB;IACA,OAAOhB,8BAA8B;EACzC;AACJ;AAACiB,OAAA,CAAAE,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _pubsub = require("@webiny/pubsub");
|
|
10
|
+
var _api = require("@webiny/api");
|
|
11
|
+
var _types = require("../../types");
|
|
12
|
+
var _client = require("../../client");
|
|
13
|
+
var _utils = require("../../import/utils");
|
|
14
|
+
var _utils2 = require("@webiny/utils");
|
|
15
|
+
var _PageBlocksPermissions = require("@webiny/api-page-builder/graphql/crud/permissions/PageBlocksPermissions");
|
|
16
|
+
const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
|
17
|
+
const EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
|
|
18
|
+
const IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
|
|
19
|
+
var _default = exports.default = new _api.ContextPlugin(context => {
|
|
20
|
+
const pageBlocksPermissions = new _PageBlocksPermissions.PageBlocksPermissions({
|
|
21
|
+
getPermissions: () => context.security.getPermissions("pb.block"),
|
|
22
|
+
getIdentity: context.security.getIdentity,
|
|
23
|
+
fullAccessPermissionName: "pb.*"
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Export
|
|
27
|
+
const onBlocksBeforeExport = (0, _pubsub.createTopic)("PageBuilder.onBlocksBeforeExport");
|
|
28
|
+
const onBlocksAfterExport = (0, _pubsub.createTopic)("PageBuilder.onBlocksAfterExport");
|
|
29
|
+
|
|
30
|
+
// Import
|
|
31
|
+
const onBlocksBeforeImport = (0, _pubsub.createTopic)("PageBuilder.onBlocksBeforeImport");
|
|
32
|
+
const onBlocksAfterImport = (0, _pubsub.createTopic)("PageBuilder.onBlocksAfterImport");
|
|
33
|
+
const importExportCrud = {
|
|
34
|
+
onBlocksBeforeExport,
|
|
35
|
+
onBlocksAfterExport,
|
|
36
|
+
onBlocksBeforeImport,
|
|
37
|
+
onBlocksAfterImport,
|
|
38
|
+
async importBlocks(params) {
|
|
39
|
+
const {
|
|
40
|
+
zipFileUrl
|
|
41
|
+
} = params;
|
|
42
|
+
await pageBlocksPermissions.ensure({
|
|
43
|
+
rwd: "w"
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Create a task for import block
|
|
47
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
|
48
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
|
49
|
+
input: {
|
|
50
|
+
zipFileUrl
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Import Blocks
|
|
55
|
+
* ImportBlocks
|
|
56
|
+
* importBlocks
|
|
57
|
+
*/
|
|
58
|
+
await onBlocksBeforeImport.publish({
|
|
59
|
+
params
|
|
60
|
+
});
|
|
61
|
+
await (0, _client.invokeHandlerClient)({
|
|
62
|
+
context,
|
|
63
|
+
name: IMPORT_BLOCKS_CREATE_HANDLER,
|
|
64
|
+
payload: {
|
|
65
|
+
zipFileUrl,
|
|
66
|
+
task,
|
|
67
|
+
type: "block",
|
|
68
|
+
identity: context.security.getIdentity()
|
|
69
|
+
},
|
|
70
|
+
description: "Import Blocks - create"
|
|
71
|
+
});
|
|
72
|
+
await onBlocksAfterImport.publish({
|
|
73
|
+
params
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
task
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
async exportBlocks(params) {
|
|
80
|
+
const {
|
|
81
|
+
ids: initialBlockIds,
|
|
82
|
+
where
|
|
83
|
+
} = params;
|
|
84
|
+
await pageBlocksPermissions.ensure({
|
|
85
|
+
rwd: "w"
|
|
86
|
+
});
|
|
87
|
+
let blockIds = initialBlockIds || [];
|
|
88
|
+
// If no ids are provided then it means we want to export all blocks
|
|
89
|
+
if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
|
|
90
|
+
const blocks = await context.pageBuilder.listPageBlocks({
|
|
91
|
+
where
|
|
92
|
+
});
|
|
93
|
+
// Save block ids
|
|
94
|
+
blockIds = blocks.map(block => block.id);
|
|
95
|
+
}
|
|
96
|
+
if (blockIds.length === 0) {
|
|
97
|
+
throw new _error.default("Cannot export blocks - no blocks found for provided inputs.", "EMPTY_EXPORT_NO_BLOCKS_FOUND");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Create the main task for blocks export.
|
|
101
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
|
102
|
+
status: _types.ImportExportTaskStatus.PENDING
|
|
103
|
+
});
|
|
104
|
+
const exportBlocksDataKey = `${EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;
|
|
105
|
+
// For each block create a sub task and invoke the process handler.
|
|
106
|
+
for (let i = 0; i < blockIds.length; i++) {
|
|
107
|
+
const blockId = blockIds[i];
|
|
108
|
+
// Create sub task.
|
|
109
|
+
await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
|
|
110
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
|
111
|
+
input: {
|
|
112
|
+
blockId,
|
|
113
|
+
exportBlocksDataKey
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// Update main task status.
|
|
118
|
+
await context.pageBuilder.importExportTask.updateTask(task.id, {
|
|
119
|
+
status: _types.ImportExportTaskStatus.PROCESSING,
|
|
120
|
+
stats: (0, _utils.initialStats)(blockIds.length),
|
|
121
|
+
input: {
|
|
122
|
+
exportBlocksDataKey
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Export Blocks
|
|
128
|
+
* ExportBlocks
|
|
129
|
+
* exportBlocks
|
|
130
|
+
*/
|
|
131
|
+
await onBlocksBeforeExport.publish({
|
|
132
|
+
params
|
|
133
|
+
});
|
|
134
|
+
// Invoke handler.
|
|
135
|
+
await (0, _client.invokeHandlerClient)({
|
|
136
|
+
context,
|
|
137
|
+
name: EXPORT_BLOCKS_PROCESS_HANDLER,
|
|
138
|
+
payload: {
|
|
139
|
+
taskId: task.id,
|
|
140
|
+
subTaskIndex: 1,
|
|
141
|
+
type: "block",
|
|
142
|
+
identity: context.security.getIdentity()
|
|
143
|
+
},
|
|
144
|
+
description: "Export blocks - process"
|
|
145
|
+
});
|
|
146
|
+
await onBlocksAfterExport.publish({
|
|
147
|
+
params
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
task
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
// Modify context
|
|
155
|
+
context.pageBuilder.blocks = importExportCrud;
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=blocks.crud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_pubsub","_api","_types","_client","_utils","_utils2","_PageBlocksPermissions","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_BLOCKS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_BLOCKS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","_default","exports","default","ContextPlugin","context","pageBlocksPermissions","PageBlocksPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","onBlocksBeforeExport","createTopic","onBlocksAfterExport","onBlocksBeforeImport","onBlocksAfterImport","importExportCrud","importBlocks","params","zipFileUrl","ensure","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","publish","invokeHandlerClient","name","payload","type","identity","description","exportBlocks","ids","initialBlockIds","where","blockIds","Array","isArray","length","blocks","listPageBlocks","map","block","id","WebinyError","exportBlocksDataKey","i","blockId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["blocks.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type {\n BlocksImportExportCrud,\n PbImportExportContext,\n OnBlocksBeforeExportTopicParams,\n OnBlocksAfterExportTopicParams,\n OnBlocksBeforeImportTopicParams,\n OnBlocksAfterImportTopicParams\n} from \"~/types\";\nimport { ImportExportTaskStatus } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport type { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport type { Payload as ExportBlocksProcessHandlerPayload } from \"~/export/process\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { PageBlocksPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PageBlocksPermissions\";\n\nconst EXPORT_BLOCKS_FOLDER_KEY = \"WEBINY_PB_EXPORT_BLOCK\";\nconst EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const pageBlocksPermissions = new PageBlocksPermissions({\n getPermissions: () => context.security.getPermissions(\"pb.block\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n // Export\n const onBlocksBeforeExport = createTopic<OnBlocksBeforeExportTopicParams>(\n \"PageBuilder.onBlocksBeforeExport\"\n );\n const onBlocksAfterExport = createTopic<OnBlocksAfterExportTopicParams>(\n \"PageBuilder.onBlocksAfterExport\"\n );\n\n // Import\n const onBlocksBeforeImport = createTopic<OnBlocksBeforeImportTopicParams>(\n \"PageBuilder.onBlocksBeforeImport\"\n );\n const onBlocksAfterImport = createTopic<OnBlocksAfterImportTopicParams>(\n \"PageBuilder.onBlocksAfterImport\"\n );\n\n const importExportCrud: BlocksImportExportCrud = {\n onBlocksBeforeExport,\n onBlocksAfterExport,\n onBlocksBeforeImport,\n onBlocksAfterImport,\n async importBlocks(params) {\n const { zipFileUrl } = params;\n await pageBlocksPermissions.ensure({ rwd: \"w\" });\n\n // Create a task for import block\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n zipFileUrl\n }\n });\n /**\n * Import Blocks\n * ImportBlocks\n * importBlocks\n */\n await onBlocksBeforeImport.publish({ params });\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_BLOCKS_CREATE_HANDLER,\n payload: {\n zipFileUrl,\n task,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Import Blocks - create\"\n });\n await onBlocksAfterImport.publish({ params });\n\n return {\n task\n };\n },\n\n async exportBlocks(params) {\n const { ids: initialBlockIds, where } = params;\n await pageBlocksPermissions.ensure({ rwd: \"w\" });\n\n let blockIds: string[] = initialBlockIds || [];\n // If no ids are provided then it means we want to export all blocks\n if (\n !initialBlockIds ||\n (Array.isArray(initialBlockIds) && initialBlockIds.length === 0)\n ) {\n const blocks = await context.pageBuilder.listPageBlocks({ where });\n // Save block ids\n blockIds = blocks.map(block => block.id);\n }\n\n if (blockIds.length === 0) {\n throw new WebinyError(\n \"Cannot export blocks - no blocks found for provided inputs.\",\n \"EMPTY_EXPORT_NO_BLOCKS_FOUND\"\n );\n }\n\n // Create the main task for blocks export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportBlocksDataKey = `${EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;\n // For each block create a sub task and invoke the process handler.\n for (let i = 0; i < blockIds.length; i++) {\n const blockId = blockIds[i];\n // Create sub task.\n await context.pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n input: {\n blockId,\n exportBlocksDataKey\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(blockIds.length),\n input: {\n exportBlocksDataKey\n }\n });\n\n /**\n * Export Blocks\n * ExportBlocks\n * exportBlocks\n */\n await onBlocksBeforeExport.publish({ params });\n // Invoke handler.\n await invokeHandlerClient<ExportBlocksProcessHandlerPayload>({\n context,\n name: EXPORT_BLOCKS_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Export blocks - process\"\n });\n await onBlocksAfterExport.publish({ params });\n\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.blocks = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,sBAAA,GAAAP,OAAA;AAEA,MAAMQ,wBAAwB,GAAG,wBAAwB;AACzD,MAAMC,6BAA6B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AAClF,MAAMC,4BAA4B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAElE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,qBAAqB,GAAG,IAAIC,4CAAqB,CAAC;IACpDC,cAAc,EAAEA,CAAA,KAAMH,OAAO,CAACI,QAAQ,CAACD,cAAc,CAAC,UAAU,CAAC;IACjEE,WAAW,EAAEL,OAAO,CAACI,QAAQ,CAACC,WAAW;IACzCC,wBAAwB,EAAE;EAC9B,CAAC,CAAC;;EAEF;EACA,MAAMC,oBAAoB,GAAG,IAAAC,mBAAW,EACpC,kCACJ,CAAC;EACD,MAAMC,mBAAmB,GAAG,IAAAD,mBAAW,EACnC,iCACJ,CAAC;;EAED;EACA,MAAME,oBAAoB,GAAG,IAAAF,mBAAW,EACpC,kCACJ,CAAC;EACD,MAAMG,mBAAmB,GAAG,IAAAH,mBAAW,EACnC,iCACJ,CAAC;EAED,MAAMI,gBAAwC,GAAG;IAC7CL,oBAAoB;IACpBE,mBAAmB;IACnBC,oBAAoB;IACpBC,mBAAmB;IACnB,MAAME,YAAYA,CAACC,MAAM,EAAE;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