@webiny/api-page-builder-import-export 0.0.0-unstable.da99e0b846 → 0.0.0-unstable.de38392959
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.js +12 -21
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.js +4 -2
- package/export/combine/blocksHandler.js.map +1 -1
- package/export/combine/formsHandler.js +4 -2
- package/export/combine/formsHandler.js.map +1 -1
- package/export/combine/index.js +23 -19
- package/export/combine/index.js.map +1 -1
- package/export/combine/pagesHandler.js +4 -2
- package/export/combine/pagesHandler.js.map +1 -1
- package/export/combine/templatesHandler.js +4 -2
- package/export/combine/templatesHandler.js.map +1 -1
- package/export/process/blocksHandler.js +13 -6
- 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 +11 -0
- package/export/process/exporters/PageExporter.js +58 -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 +56 -0
- package/export/process/exporters/PageTemplateExporter.js.map +1 -0
- package/export/process/formsHandler.js +8 -6
- package/export/process/formsHandler.js.map +1 -1
- package/export/process/index.js +23 -19
- package/export/process/index.js.map +1 -1
- package/export/process/pagesHandler.js +8 -6
- package/export/process/pagesHandler.js.map +1 -1
- package/export/process/templatesHandler.js +8 -6
- package/export/process/templatesHandler.js.map +1 -1
- package/export/s3Stream.d.ts +8 -8
- package/export/s3Stream.js +27 -22
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +8 -13
- package/export/utils.js +20 -37
- package/export/utils.js.map +1 -1
- package/export/zipper.d.ts +5 -5
- package/export/zipper.js +18 -22
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.js +49 -26
- package/graphql/crud/blocks.crud.js.map +1 -1
- package/graphql/crud/forms.crud.js +51 -17
- package/graphql/crud/forms.crud.js.map +1 -1
- package/graphql/crud/importExportTasks.crud.js +81 -63
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -0
- package/graphql/crud/pages.crud.js +58 -24
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.js +48 -15
- package/graphql/crud/templates.crud.js.map +1 -1
- package/graphql/crud.js +3 -1
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.js +4 -2
- package/graphql/graphql/blocks.gql.js.map +1 -1
- package/graphql/graphql/forms.gql.js +3 -1
- package/graphql/graphql/forms.gql.js.map +1 -1
- package/graphql/graphql/importExportTasks.gql.js +3 -1
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.js +3 -1
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.js +3 -1
- package/graphql/graphql/templates.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.d.ts +1 -1
- package/graphql/graphql/utils/resolve.js +3 -1
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.js +3 -1
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.js +3 -1
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +113 -1
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -1
- package/import/constants.js +3 -1
- package/import/constants.js.map +1 -1
- package/import/create/blocksHandler.js +3 -3
- package/import/create/blocksHandler.js.map +1 -1
- package/import/create/formsHandler.js +3 -1
- package/import/create/formsHandler.js.map +1 -1
- package/import/create/index.js +23 -19
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.js +3 -1
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.js +3 -1
- package/import/create/templatesHandler.js.map +1 -1
- package/import/process/blocks/blocksHandler.js +6 -6
- package/import/process/blocks/blocksHandler.js.map +1 -1
- package/import/process/blocks/importBlock.d.ts +2 -2
- package/import/process/blocks/importBlock.js +33 -27
- package/import/process/blocks/importBlock.js.map +1 -1
- package/import/process/forms/formsHandler.js +4 -2
- package/import/process/forms/formsHandler.js.map +1 -1
- package/import/process/forms/importForm.d.ts +1 -1
- package/import/process/forms/importForm.js +6 -2
- package/import/process/forms/importForm.js.map +1 -1
- package/import/process/index.js +23 -19
- package/import/process/index.js.map +1 -1
- package/import/process/pages/importPage.d.ts +1 -1
- package/import/process/pages/importPage.js +8 -6
- package/import/process/pages/importPage.js.map +1 -1
- package/import/process/pages/pagesHandler.js +3 -1
- package/import/process/pages/pagesHandler.js.map +1 -1
- package/import/process/templates/importTemplate.d.ts +1 -1
- package/import/process/templates/importTemplate.js +6 -2
- package/import/process/templates/importTemplate.js.map +1 -1
- package/import/process/templates/templatesHandler.js +3 -1
- package/import/process/templates/templatesHandler.js.map +1 -1
- package/import/utils/deleteS3Folder.js +3 -1
- package/import/utils/deleteS3Folder.js.map +1 -1
- package/import/utils/extractAndUploadZipFileContents.js +3 -2
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -1
- package/import/utils/extractZipAndUploadToS3.js +3 -1
- package/import/utils/extractZipAndUploadToS3.js.map +1 -1
- package/import/utils/getFileNameWithoutExt.js +3 -1
- package/import/utils/getFileNameWithoutExt.js.map +1 -1
- package/import/utils/index.js +3 -1
- package/import/utils/index.js.map +1 -1
- package/import/utils/initialStats.js +3 -1
- package/import/utils/initialStats.js.map +1 -1
- package/import/utils/prepareDataDirMap.js +3 -1
- package/import/utils/prepareDataDirMap.js.map +1 -1
- package/import/utils/updateFilesInData.js +5 -2
- package/import/utils/updateFilesInData.js.map +1 -1
- package/import/utils/uploadAssets.js +56 -15
- package/import/utils/uploadAssets.js.map +1 -1
- package/import/utils/uploadFilesFromS3.d.ts +1 -1
- package/import/utils/uploadFilesFromS3.js +4 -2
- package/import/utils/uploadFilesFromS3.js.map +1 -1
- package/mockSecurity.js +3 -2
- package/mockSecurity.js.map +1 -1
- package/package.json +35 -44
- package/types.js +62 -8
- package/types.js.map +1 -1
- package/import/process/blocksHandler.d.ts +0 -3
- package/import/process/blocksHandler.js +0 -175
- package/import/process/blocksHandler.js.map +0 -1
- package/import/process/pagesHandler.d.ts +0 -3
- package/import/process/pagesHandler.js +0 -180
- package/import/process/pagesHandler.js.map +0 -1
- package/import/utils.d.ts +0 -49
- package/import/utils.js +0 -641
- package/import/utils.js.map +0 -1
package/export/s3Stream.js
CHANGED
@@ -1,29 +1,26 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
5
4
|
value: true
|
6
5
|
});
|
7
6
|
exports.s3Stream = void 0;
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
10
7
|
var _stream = require("stream");
|
11
|
-
var
|
8
|
+
var _clientS = require("@webiny/aws-sdk/client-s3");
|
9
|
+
var _libStorage = require("@webiny/aws-sdk/lib-storage");
|
12
10
|
const ARCHIVE_CONTENT_TYPE = "application/zip";
|
13
11
|
class S3Stream {
|
14
12
|
constructor() {
|
15
|
-
|
16
|
-
(0, _defineProperty2.default)(this, "bucket", void 0);
|
17
|
-
this.s3 = new _s.default({
|
13
|
+
this.s3 = new _clientS.S3({
|
18
14
|
region: process.env.AWS_REGION
|
19
15
|
});
|
20
16
|
this.bucket = process.env.S3_BUCKET;
|
21
17
|
}
|
22
18
|
getPresignedUrl(key) {
|
23
|
-
return this.s3.
|
19
|
+
return (0, _clientS.getSignedUrl)(this.s3, new _clientS.GetObjectCommand({
|
24
20
|
Bucket: this.bucket,
|
25
|
-
Key: key
|
26
|
-
|
21
|
+
Key: key
|
22
|
+
}), {
|
23
|
+
expiresIn: 604800 // 1 week
|
27
24
|
});
|
28
25
|
}
|
29
26
|
|
@@ -46,13 +43,14 @@ class S3Stream {
|
|
46
43
|
return this.s3.headObject({
|
47
44
|
Bucket: this.bucket,
|
48
45
|
Key
|
49
|
-
})
|
46
|
+
});
|
50
47
|
}
|
51
|
-
readStream(Key) {
|
52
|
-
|
48
|
+
async readStream(Key) {
|
49
|
+
const response = await this.s3.send(new _clientS.GetObjectCommand({
|
53
50
|
Bucket: this.bucket,
|
54
51
|
Key
|
55
|
-
})
|
52
|
+
}));
|
53
|
+
return response.Body;
|
56
54
|
}
|
57
55
|
writeStream(Key, contentType = ARCHIVE_CONTENT_TYPE) {
|
58
56
|
const streamPassThrough = new _stream.Stream.PassThrough();
|
@@ -63,32 +61,39 @@ class S3Stream {
|
|
63
61
|
ContentType: contentType,
|
64
62
|
Key
|
65
63
|
};
|
64
|
+
const upload = new _libStorage.Upload({
|
65
|
+
client: this.s3,
|
66
|
+
params
|
67
|
+
});
|
66
68
|
return {
|
67
69
|
streamPassThrough: streamPassThrough,
|
68
70
|
/**
|
69
71
|
* We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
|
70
72
|
*/
|
71
|
-
streamPassThroughUploadPromise:
|
73
|
+
streamPassThroughUploadPromise: upload.done()
|
72
74
|
};
|
73
75
|
}
|
74
|
-
upload(params) {
|
75
|
-
|
76
|
+
async upload(params) {
|
77
|
+
await this.s3.send(new _clientS.PutObjectCommand({
|
76
78
|
ACL: "private",
|
77
|
-
Bucket: this.bucket
|
78
|
-
|
79
|
+
Bucket: this.bucket,
|
80
|
+
...params
|
81
|
+
}));
|
79
82
|
}
|
80
83
|
listObject(prefix) {
|
81
84
|
return this.s3.listObjects({
|
82
85
|
Bucket: this.bucket,
|
83
86
|
Prefix: prefix
|
84
|
-
})
|
87
|
+
});
|
85
88
|
}
|
86
89
|
deleteObject(key) {
|
87
90
|
return this.s3.deleteObject({
|
88
91
|
Key: key,
|
89
92
|
Bucket: this.bucket
|
90
|
-
})
|
93
|
+
});
|
91
94
|
}
|
92
95
|
}
|
93
96
|
const s3Stream = new S3Stream();
|
94
|
-
exports.s3Stream = s3Stream;
|
97
|
+
exports.s3Stream = s3Stream;
|
98
|
+
|
99
|
+
//# sourceMappingURL=s3Stream.js.map
|
package/export/s3Stream.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","Bucket","Key","
|
1
|
+
{"version":3,"names":["_stream","require","_clientS","_libStorage","ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","GetObjectCommand","Bucket","Key","expiresIn","isFileAccessible","getObjectHead","error","console","warn","log","headObject","readStream","response","send","Body","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","ContentType","upload","Upload","client","streamPassThroughUploadPromise","done","PutObjectCommand","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream","exports"],"sources":["s3Stream.ts"],"sourcesContent":["import { Stream, Readable } from \"stream\";\nimport {\n S3,\n ListObjectsOutput,\n DeleteObjectOutput,\n HeadObjectOutput,\n getSignedUrl,\n GetObjectCommand,\n PutObjectCommand,\n PutObjectCommandInput\n} from \"@webiny/aws-sdk/client-s3\";\nimport { Upload } from \"@webiny/aws-sdk/lib-storage\";\n\nconst ARCHIVE_CONTENT_TYPE = \"application/zip\";\n\nclass S3Stream {\n s3: S3;\n bucket: string;\n\n constructor() {\n this.s3 = new S3({\n region: process.env.AWS_REGION as string\n });\n this.bucket = process.env.S3_BUCKET as string;\n }\n\n getPresignedUrl(key?: string) {\n return getSignedUrl(\n this.s3,\n new GetObjectCommand({\n Bucket: this.bucket,\n Key: key\n }),\n {\n expiresIn: 604800 // 1 week\n }\n );\n }\n\n /**\n * We're checking if the file is accessible on S3 by getting object meta data.\n * It help us to filter files that we need to download as part of export data.\n * @param Key {string}\n */\n async isFileAccessible(Key: string): Promise<boolean> {\n try {\n await this.getObjectHead(Key);\n return true;\n } catch (error) {\n console.warn(`Error while fetching meta data for file \"${Key}\"`);\n console.log(error);\n return false;\n }\n }\n\n getObjectHead(Key: string): Promise<HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key });\n }\n\n async readStream(Key: string): Promise<Readable> {\n const response = await this.s3.send(new GetObjectCommand({ Bucket: this.bucket, Key }));\n return response.Body as Readable;\n }\n\n writeStream(Key: string, contentType: string = ARCHIVE_CONTENT_TYPE) {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: PutObjectCommandInput = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\n };\n\n const upload = new Upload({\n client: this.s3,\n params\n });\n\n return {\n streamPassThrough: streamPassThrough,\n /**\n * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.\n */\n streamPassThroughUploadPromise: upload.done()\n };\n }\n\n async upload(params: { Key: string; ContentType: string; Body: Buffer }): Promise<void> {\n await this.s3.send(\n new PutObjectCommand({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n );\n }\n\n listObject(prefix: string): Promise<ListObjectsOutput> {\n return this.s3.listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n });\n }\n\n deleteObject(key: string): Promise<DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket });\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAUA,IAAAE,WAAA,GAAAF,OAAA;AAEA,MAAMG,oBAAoB,GAAG,iBAAiB;AAE9C,MAAMC,QAAQ,CAAC;EAIXC,WAAWA,CAAA,EAAG;IACV,IAAI,CAACC,EAAE,GAAG,IAAIC,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,MAA6B,GAAG;MAClCC,GAAG,EAAE,SAAS;MACdP,IAAI,EAAEG,iBAAiB;MACvBhB,MAAM,EAAE,IAAI,CAACN,MAAM;MACnB2B,WAAW,EAAEN,WAAW;MACxBd;IACJ,CAAC;IAED,MAAMqB,MAAM,GAAG,IAAIC,kBAAM,CAAC;MACtBC,MAAM,EAAE,IAAI,CAACpC,EAAE;MACf+B;IACJ,CAAC,CAAC;IAEF,OAAO;MACHH,iBAAiB,EAAEA,iBAAiB;MACpC;AACZ;AACA;MACYS,8BAA8B,EAAEH,MAAM,CAACI,IAAI,CAAC;IAChD,CAAC;EACL;EAEA,MAAMJ,MAAMA,CAACH,MAA0D,EAAiB;IACpF,MAAM,IAAI,CAAC/B,EAAE,CAACwB,IAAI,CACd,IAAIe,yBAAgB,CAAC;MACjBP,GAAG,EAAE,SAAS;MACdpB,MAAM,EAAE,IAAI,CAACN,MAAM;MACnB,GAAGyB;IACP,CAAC,CACL,CAAC;EACL;EAEAS,UAAUA,CAACC,MAAc,EAA8B;IACnD,OAAO,IAAI,CAACzC,EAAE,CAAC0C,WAAW,CAAC;MACvB9B,MAAM,EAAE,IAAI,CAACN,MAAM;MACnBqC,MAAM,EAAEF;IACZ,CAAC,CAAC;EACN;EAEAG,YAAYA,CAACnC,GAAW,EAA+B;IACnD,OAAO,IAAI,CAACT,EAAE,CAAC4C,YAAY,CAAC;MAAE/B,GAAG,EAAEJ,GAAG;MAAEG,MAAM,EAAE,IAAI,CAACN;IAAO,CAAC,CAAC;EAClE;AACJ;AAEO,MAAMuC,QAAQ,GAAG,IAAI/C,QAAQ,CAAC,CAAC;AAACgD,OAAA,CAAAD,QAAA,GAAAA,QAAA"}
|
package/export/utils.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import { Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
|
3
|
-
import { FbForm } from "@webiny/api-form-builder/types";
|
1
|
+
import { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
|
2
|
+
import { BlockCategory, Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
|
4
3
|
import { FileManagerContext, File } from "@webiny/api-file-manager/types";
|
5
4
|
export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
6
5
|
export declare const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
@@ -10,20 +9,16 @@ export interface ExportedPageData {
|
|
10
9
|
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
11
10
|
files: File[];
|
12
11
|
}
|
13
|
-
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<
|
12
|
+
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
|
14
13
|
export interface ExportedBlockData {
|
15
|
-
block: Pick<PageBlock, "name" | "content"
|
14
|
+
block: Pick<PageBlock, "name" | "content">;
|
15
|
+
category: BlockCategory;
|
16
16
|
files: File[];
|
17
17
|
}
|
18
|
-
export declare function exportBlock(block: PageBlock, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<
|
18
|
+
export declare function exportBlock(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
|
19
19
|
export interface ExportedTemplateData {
|
20
20
|
template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory">;
|
21
21
|
files: File[];
|
22
22
|
}
|
23
|
-
export declare function exportTemplate(template: PageTemplate, exportTemplatesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<
|
24
|
-
export declare function extractFilesFromData(data: Record<string, any>, files?:
|
25
|
-
export interface ExportedFormData {
|
26
|
-
form: Pick<FbForm, "name" | "status" | "version" | "fields" | "layout" | "settings" | "triggers">;
|
27
|
-
files: File[];
|
28
|
-
}
|
29
|
-
export declare function exportForm(form: FbForm, exportFormsDataKey: string): Promise<S3.ManagedUpload.SendData>;
|
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
CHANGED
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
|
8
8
|
exports.exportBlock = exportBlock;
|
9
|
-
exports.exportForm = exportForm;
|
10
9
|
exports.exportPage = exportPage;
|
11
10
|
exports.exportTemplate = exportTemplate;
|
12
11
|
exports.extractFilesFromData = extractFilesFromData;
|
@@ -30,7 +29,9 @@ async function exportPage(page, exportPagesDataKey, fileManager) {
|
|
30
29
|
const imageFilesData = [];
|
31
30
|
if (fileIds.length > 0) {
|
32
31
|
const [filesData] = await fileManager.listFiles({
|
33
|
-
|
32
|
+
where: {
|
33
|
+
id_in: fileIds
|
34
|
+
}
|
34
35
|
});
|
35
36
|
imageFilesData.push(...filesData);
|
36
37
|
}
|
@@ -58,7 +59,7 @@ async function exportPage(page, exportPagesDataKey, fileManager) {
|
|
58
59
|
});
|
59
60
|
return zipper.process();
|
60
61
|
}
|
61
|
-
async function exportBlock(block, exportBlocksDataKey, fileManager) {
|
62
|
+
async function exportBlock(block, blockCategory, exportBlocksDataKey, fileManager) {
|
62
63
|
// Extract all files
|
63
64
|
const files = extractFilesFromData(block.content || {});
|
64
65
|
const fileIds = files.map(imageFile => imageFile.id);
|
@@ -66,21 +67,24 @@ async function exportBlock(block, exportBlocksDataKey, fileManager) {
|
|
66
67
|
const imageFilesData = [];
|
67
68
|
if (fileIds.length > 0) {
|
68
69
|
const [filesData] = await fileManager.listFiles({
|
69
|
-
|
70
|
+
where: {
|
71
|
+
id_in: fileIds
|
72
|
+
}
|
70
73
|
});
|
71
74
|
imageFilesData.push(...filesData);
|
72
75
|
}
|
73
|
-
// Add block preview image file data
|
74
|
-
if (block.preview.id) {
|
75
|
-
imageFilesData.push(await fileManager.getFile(block.preview.id));
|
76
|
-
}
|
77
76
|
|
78
77
|
// Extract the block data in a json file and upload it to S3
|
79
78
|
const blockData = {
|
80
79
|
block: {
|
81
80
|
name: block.name,
|
82
|
-
content: block.content
|
83
|
-
|
81
|
+
content: block.content
|
82
|
+
},
|
83
|
+
category: {
|
84
|
+
name: blockCategory.name,
|
85
|
+
slug: blockCategory.slug,
|
86
|
+
icon: blockCategory.icon,
|
87
|
+
description: blockCategory.description
|
84
88
|
},
|
85
89
|
files: imageFilesData
|
86
90
|
};
|
@@ -103,7 +107,9 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
103
107
|
const imageFilesData = [];
|
104
108
|
if (fileIds.length > 0) {
|
105
109
|
const [filesData] = await fileManager.listFiles({
|
106
|
-
|
110
|
+
where: {
|
111
|
+
id_in: fileIds
|
112
|
+
}
|
107
113
|
});
|
108
114
|
imageFilesData.push(...filesData);
|
109
115
|
}
|
@@ -133,10 +139,10 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
133
139
|
return zipper.process();
|
134
140
|
}
|
135
141
|
function extractFilesFromData(data, files = []) {
|
136
|
-
// Base case: termination
|
137
142
|
if (!data || typeof data !== "object") {
|
138
143
|
return files;
|
139
144
|
}
|
145
|
+
|
140
146
|
// Recursively call function for each element
|
141
147
|
if (Array.isArray(data)) {
|
142
148
|
for (let i = 0; i < data.length; i++) {
|
@@ -150,7 +156,6 @@ function extractFilesFromData(data, files = []) {
|
|
150
156
|
const tuple = Object.entries(data);
|
151
157
|
for (let i = 0; i < tuple.length; i++) {
|
152
158
|
const [key, value] = tuple[i];
|
153
|
-
// TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
|
154
159
|
if (key === "file" && value) {
|
155
160
|
files.push(value);
|
156
161
|
} else if (key === "images" && Array.isArray(value)) {
|
@@ -162,27 +167,5 @@ function extractFilesFromData(data, files = []) {
|
|
162
167
|
}
|
163
168
|
return files;
|
164
169
|
}
|
165
|
-
|
166
|
-
|
167
|
-
const formData = {
|
168
|
-
form: {
|
169
|
-
name: form.name,
|
170
|
-
status: form.status,
|
171
|
-
version: form.version,
|
172
|
-
fields: form.fields,
|
173
|
-
layout: form.layout,
|
174
|
-
settings: form.settings,
|
175
|
-
triggers: form.triggers
|
176
|
-
}
|
177
|
-
};
|
178
|
-
const formDataBuffer = Buffer.from(JSON.stringify(formData));
|
179
|
-
const zipper = new _zipper.default({
|
180
|
-
exportInfo: {
|
181
|
-
files: [],
|
182
|
-
name: form.name,
|
183
|
-
dataBuffer: formDataBuffer
|
184
|
-
},
|
185
|
-
archiveFileKey: exportFormsDataKey
|
186
|
-
});
|
187
|
-
return zipper.process();
|
188
|
-
}
|
170
|
+
|
171
|
+
//# 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","EXPORT_FORMS_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","slug","tags","description","layout","pageCategory","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value","exportForm","form","exportFormsDataKey","formData","fields","triggers","formDataBuffer"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, PageBlock, PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { FbForm } from \"@webiny/api-form-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\";\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<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.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.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.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<\n PageTemplate,\n \"title\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\" | \"pageCategory\"\n >;\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.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 slug: template.slug,\n tags: template.tags,\n description: template.description,\n content: template.content,\n layout: template.layout,\n pageCategory: template.pageCategory\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\nexport interface ExportedFormData {\n form: Pick<\n FbForm,\n \"name\" | \"status\" | \"version\" | \"fields\" | \"layout\" | \"settings\" | \"triggers\"\n >;\n files: File[];\n}\n\nexport async function exportForm(\n form: FbForm,\n exportFormsDataKey: string\n): Promise<S3.ManagedUpload.SendData> {\n // Extract the form data in a json file and upload it to S3\n const formData = {\n form: {\n name: form.name,\n status: form.status,\n version: form.version,\n fields: form.fields,\n layout: form.layout,\n settings: form.settings,\n triggers: form.triggers\n }\n };\n const formDataBuffer = Buffer.from(JSON.stringify(formData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: [],\n name: form.name,\n dataBuffer: formDataBuffer\n },\n archiveFileKey: exportFormsDataKey\n });\n\n return zipper.process();\n}\n"],"mappings":";;;;;;;;;;;;AAIA;AACA;AAEO,MAAMA,uBAAuB,GAAG,wBAAwB;AAAC;AACzD,MAAMC,wBAAwB,GAAG,wBAAwB;AAAC;AAC1D,MAAMC,2BAA2B,GAAG,2BAA2B;AAAC;AAChE,MAAMC,uBAAuB,GAAG,uBAAuB;AAAC;AAOxD,eAAeC,UAAU,CAC5BC,IAAU,EACVC,kBAA0B,EAC1BC,WAA8C,EACZ;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,EACQ;EAClC;EACA,MAAMC,QAAQ,GAAG;IACbF,IAAI,EAAE;MACFhC,IAAI,EAAEgC,IAAI,CAAChC,IAAI;MACfV,MAAM,EAAE0C,IAAI,CAAC1C,MAAM;MACnBD,OAAO,EAAE2C,IAAI,CAAC3C,OAAO;MACrB8C,MAAM,EAAEH,IAAI,CAACG,MAAM;MACnBjB,MAAM,EAAEc,IAAI,CAACd,MAAM;MACnB3B,QAAQ,EAAEyC,IAAI,CAACzC,QAAQ;MACvB6C,QAAQ,EAAEJ,IAAI,CAACI;IACnB;EACJ,CAAC;EACD,MAAMC,cAAc,GAAG5C,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACsC,QAAQ,CAAC,CAAC;EAE5D,MAAMrC,MAAM,GAAG,IAAIC,eAAM,CAAC;IACtBC,UAAU,EAAE;MACR/B,KAAK,EAAE,EAAE;MACTgC,IAAI,EAAEgC,IAAI,CAAChC,IAAI;MACfC,UAAU,EAAEoC;IAChB,CAAC;IACDnC,cAAc,EAAE+B;EACpB,CAAC,CAAC;EAEF,OAAOpC,MAAM,CAACM,OAAO,EAAE;AAC3B"}
|
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","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { BlockCategory, 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\";\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\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\" | \"pageCategory\"\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 = {\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 },\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":";;;;;;;;;;;AAGA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEO,MAAME,uBAAuB,GAAG,wBAAwB;AAACC,OAAA,CAAAD,uBAAA,GAAAA,uBAAA;AACzD,MAAME,wBAAwB,GAAG,wBAAwB;AAACD,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAC1D,MAAMC,2BAA2B,GAAG,2BAA2B;AAACF,OAAA,CAAAE,2BAAA,GAAAA,2BAAA;AAChE,MAAMC,uBAAuB,GAAG,uBAAuB;AAACH,OAAA,CAAAG,uBAAA,GAAAA,uBAAA;AAOxD,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,KA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EAAE;EAChF,IAAI,CAACuD,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACnC,OAAOvD,KAAK;EAChB;;EAEA;EACA,IAAIwD,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;IACrB,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAAC1C,MAAM,EAAE6C,CAAC,EAAE,EAAE;MAClC,MAAMC,OAAO,GAAGJ,IAAI,CAACG,CAAC,CAAC;MACvBzD,oBAAoB,CAAC0D,OAAO,EAAE3D,KAAK,CAAC;IACxC;IACA,OAAOA,KAAK;EAChB;;EAEA;EACA,MAAM4D,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACP,IAAI,CAAC;EAClC,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGE,KAAK,CAAC/C,MAAM,EAAE6C,CAAC,EAAE,EAAE;IACnC,MAAM,CAACK,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACF,CAAC,CAAC;IAC7B,IAAIK,GAAG,KAAK,MAAM,IAAIC,KAAK,EAAE;MACzBhE,KAAK,CAACkB,IAAI,CAAC8C,KAAK,CAAC;IACrB,CAAC,MAAM,IAAID,GAAG,KAAK,QAAQ,IAAIP,KAAK,CAACC,OAAO,CAACO,KAAK,CAAC,EAAE;MACjD;MACAhE,KAAK,CAACkB,IAAI,CAAC,GAAG8C,KAAK,CAAC;IACxB,CAAC,MAAM;MACH/D,oBAAoB,CAAC+D,KAAK,EAAEhE,KAAK,CAAC;IACtC;EACJ;EACA,OAAOA,KAAK;AAChB"}
|
package/export/zipper.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
|
-
import
|
3
|
+
import { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
|
4
4
|
import { Readable } from "stream";
|
5
5
|
import { File } from "@webiny/api-file-manager/types";
|
6
6
|
interface FileStreamDetails {
|
@@ -22,8 +22,8 @@ export default class Zipper {
|
|
22
22
|
private readonly archiveFileName;
|
23
23
|
config: ZipperConfig;
|
24
24
|
constructor(config: ZipperConfig);
|
25
|
-
s3DownloadStreams(): FileStreamDetails[]
|
26
|
-
process(): Promise<
|
25
|
+
s3DownloadStreams(): Promise<FileStreamDetails[]>;
|
26
|
+
process(): Promise<CompleteMultipartUploadOutput>;
|
27
27
|
}
|
28
28
|
export declare class ZipOfZip {
|
29
29
|
private readonly archiveFormat;
|
@@ -31,7 +31,7 @@ export declare class ZipOfZip {
|
|
31
31
|
keys: string[];
|
32
32
|
filename: string;
|
33
33
|
constructor(keys: string[], filename: string);
|
34
|
-
getFileStreams(): FileStreamDetails[]
|
35
|
-
process(): Promise<
|
34
|
+
getFileStreams(): Promise<FileStreamDetails[]>;
|
35
|
+
process(): Promise<CompleteMultipartUploadOutput>;
|
36
36
|
}
|
37
37
|
export {};
|
package/export/zipper.js
CHANGED
@@ -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
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
26
|
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
|
30
|
-
const files = exportInfo.files.map(({
|
27
|
+
const files = await Promise.all(exportInfo.files.map(async ({
|
31
28
|
key
|
32
29
|
}) => {
|
33
30
|
return {
|
34
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
31
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
35
32
|
filename: `${prefix}\\${this.filesDirName}\\${key}`
|
36
33
|
};
|
37
|
-
});
|
34
|
+
}));
|
38
35
|
return [...files, {
|
39
36
|
stream: _stream.Readable.from(exportInfo.dataBuffer),
|
40
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);
|
@@ -73,31 +70,28 @@ class Zipper {
|
|
73
70
|
}
|
74
71
|
exports.default = Zipper;
|
75
72
|
class ZipOfZip {
|
73
|
+
archiveFormat = "zip";
|
76
74
|
constructor(keys, filename) {
|
77
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
78
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
79
|
-
(0, _defineProperty2.default)(this, "keys", void 0);
|
80
|
-
(0, _defineProperty2.default)(this, "filename", void 0);
|
81
75
|
this.keys = keys;
|
82
76
|
this.filename = filename;
|
83
77
|
this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
|
84
78
|
}
|
85
|
-
getFileStreams() {
|
86
|
-
return this.keys.map(key => {
|
79
|
+
async getFileStreams() {
|
80
|
+
return await Promise.all(this.keys.map(async key => {
|
87
81
|
return {
|
88
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
82
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
89
83
|
filename: `${path.basename(key)}`
|
90
84
|
};
|
91
|
-
});
|
85
|
+
}));
|
92
86
|
}
|
93
|
-
process() {
|
87
|
+
async process() {
|
94
88
|
const {
|
95
89
|
streamPassThrough,
|
96
90
|
streamPassThroughUploadPromise
|
97
91
|
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
98
92
|
|
99
93
|
// 1. Read all files from S3 using stream.
|
100
|
-
const fileStreamDetails = this.getFileStreams();
|
94
|
+
const fileStreamDetails = await this.getFileStreams();
|
101
95
|
|
102
96
|
// 2. Prepare zip from the file stream.
|
103
97
|
const archive = _archiver.default.create(this.archiveFormat);
|
@@ -121,4 +115,6 @@ class ZipOfZip {
|
|
121
115
|
return streamPassThroughUploadPromise;
|
122
116
|
}
|
123
117
|
}
|
124
|
-
exports.ZipOfZip = ZipOfZip;
|
118
|
+
exports.ZipOfZip = ZipOfZip;
|
119
|
+
|
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 vending, { ArchiverError } from \"archiver\";\nimport { 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 { 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":";;;;;;;;AACA,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;AAPA;;AA0Be,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,EAC1B,GAAE,IAAI,CAACF,MAAM,CAACG,cAAe,GAAE,EAC/B,IAAG,IAAAC,kBAAS,EAAC,IAAI,CAACJ,MAAM,CAACK,UAAU,CAACC,IAAI,CAAE,MAC/C,CAAC;EACL;EAEA,MAAMC,iBAAiBA,CAAA,EAAiC;IACpD,MAAMF,UAAU,GAAG,IAAI,CAACL,MAAM,CAACK,UAAU;IACzC,MAAMG,MAAM,GAAG,IAAAN,eAAQ,EAAC,EAAE,EAAG,IAAG,IAAAE,kBAAS,EAACC,UAAU,CAACC,IAAI,CAAE,EAAC,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,EAAG,GAAET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