@webiny/api-page-builder-import-export 0.0.0-unstable.d65ec29d44 → 0.0.0-unstable.da99e0b846

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.
Files changed (112) hide show
  1. package/export/combine/formsHandler.d.ts +6 -0
  2. package/export/combine/formsHandler.js +99 -0
  3. package/export/combine/formsHandler.js.map +1 -0
  4. package/export/combine/index.js +5 -0
  5. package/export/combine/index.js.map +1 -1
  6. package/export/process/formsHandler.d.ts +6 -0
  7. package/export/process/formsHandler.js +187 -0
  8. package/export/process/formsHandler.js.map +1 -0
  9. package/export/process/index.js +5 -0
  10. package/export/process/index.js.map +1 -1
  11. package/export/s3Stream.d.ts +5 -2
  12. package/export/s3Stream.js.map +1 -1
  13. package/export/utils.d.ts +8 -1
  14. package/export/utils.js +34 -6
  15. package/export/utils.js.map +1 -1
  16. package/export/zipper.js +2 -2
  17. package/export/zipper.js.map +1 -1
  18. package/graphql/crud/blocks.crud.js +1 -2
  19. package/graphql/crud/blocks.crud.js.map +1 -1
  20. package/graphql/crud/forms.crud.d.ts +4 -0
  21. package/graphql/crud/forms.crud.js +129 -0
  22. package/graphql/crud/forms.crud.js.map +1 -0
  23. package/graphql/crud.js +2 -1
  24. package/graphql/crud.js.map +1 -1
  25. package/graphql/graphql/forms.gql.d.ts +4 -0
  26. package/graphql/graphql/forms.gql.js +60 -0
  27. package/graphql/graphql/forms.gql.js.map +1 -0
  28. package/graphql/graphql.js +2 -1
  29. package/graphql/graphql.js.map +1 -1
  30. package/graphql/types.d.ts +23 -0
  31. package/graphql/types.js.map +1 -1
  32. package/import/constants.d.ts +3 -0
  33. package/import/constants.js +14 -0
  34. package/import/constants.js.map +1 -0
  35. package/import/create/blocksHandler.js +4 -3
  36. package/import/create/blocksHandler.js.map +1 -1
  37. package/import/create/formsHandler.d.ts +3 -0
  38. package/import/create/formsHandler.js +103 -0
  39. package/import/create/formsHandler.js.map +1 -0
  40. package/import/create/index.js +5 -0
  41. package/import/create/index.js.map +1 -1
  42. package/import/create/pagesHandler.js +3 -2
  43. package/import/create/pagesHandler.js.map +1 -1
  44. package/import/create/templatesHandler.js +2 -1
  45. package/import/create/templatesHandler.js.map +1 -1
  46. package/import/process/blocks/blocksHandler.d.ts +3 -0
  47. package/import/process/blocks/blocksHandler.js +169 -0
  48. package/import/process/blocks/blocksHandler.js.map +1 -0
  49. package/import/process/blocks/importBlock.d.ts +11 -0
  50. package/import/process/blocks/importBlock.js +92 -0
  51. package/import/process/blocks/importBlock.js.map +1 -0
  52. package/import/process/blocksHandler.js +26 -20
  53. package/import/process/blocksHandler.js.map +1 -1
  54. package/import/process/forms/formsHandler.d.ts +3 -0
  55. package/import/process/forms/formsHandler.js +176 -0
  56. package/import/process/forms/formsHandler.js.map +1 -0
  57. package/import/process/forms/importForm.d.ts +9 -0
  58. package/import/process/forms/importForm.js +43 -0
  59. package/import/process/forms/importForm.js.map +1 -0
  60. package/import/process/index.js +8 -3
  61. package/import/process/index.js.map +1 -1
  62. package/import/process/pages/importPage.d.ts +11 -0
  63. package/import/process/pages/importPage.js +92 -0
  64. package/import/process/pages/importPage.js.map +1 -0
  65. package/import/process/pages/pagesHandler.d.ts +3 -0
  66. package/import/process/pages/pagesHandler.js +183 -0
  67. package/import/process/pages/pagesHandler.js.map +1 -0
  68. package/import/process/pagesHandler.js +29 -26
  69. package/import/process/pagesHandler.js.map +1 -1
  70. package/import/process/templates/importTemplate.d.ts +11 -0
  71. package/import/process/templates/importTemplate.js +66 -0
  72. package/import/process/templates/importTemplate.js.map +1 -0
  73. package/import/process/{templatesHandler.d.ts → templates/templatesHandler.d.ts} +2 -2
  74. package/import/process/{templatesHandler.js → templates/templatesHandler.js} +8 -7
  75. package/import/process/templates/templatesHandler.js.map +1 -0
  76. package/import/utils/deleteS3Folder.d.ts +1 -0
  77. package/import/utils/deleteS3Folder.js +19 -0
  78. package/import/utils/deleteS3Folder.js.map +1 -0
  79. package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
  80. package/import/utils/extractAndUploadZipFileContents.js +122 -0
  81. package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
  82. package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
  83. package/import/utils/extractZipAndUploadToS3.js +98 -0
  84. package/import/utils/extractZipAndUploadToS3.js.map +1 -0
  85. package/import/utils/getFileNameWithoutExt.d.ts +1 -0
  86. package/import/utils/getFileNameWithoutExt.js +11 -0
  87. package/import/utils/getFileNameWithoutExt.js.map +1 -0
  88. package/import/utils/index.d.ts +9 -0
  89. package/import/utils/index.js +104 -0
  90. package/import/utils/index.js.map +1 -0
  91. package/import/utils/initialStats.d.ts +7 -0
  92. package/import/utils/initialStats.js +16 -0
  93. package/import/utils/initialStats.js.map +1 -0
  94. package/import/utils/prepareDataDirMap.d.ts +6 -0
  95. package/import/utils/prepareDataDirMap.js +29 -0
  96. package/import/utils/prepareDataDirMap.js.map +1 -0
  97. package/import/utils/updateFilesInData.d.ts +8 -0
  98. package/import/utils/updateFilesInData.js +48 -0
  99. package/import/utils/updateFilesInData.js.map +1 -0
  100. package/import/utils/uploadAssets.d.ts +10 -0
  101. package/import/utils/uploadAssets.js +51 -0
  102. package/import/utils/uploadAssets.js.map +1 -0
  103. package/import/utils/uploadFilesFromS3.d.ts +3 -0
  104. package/import/utils/uploadFilesFromS3.js +19 -0
  105. package/import/utils/uploadFilesFromS3.js.map +1 -0
  106. package/import/utils.d.ts +1 -8
  107. package/import/utils.js +137 -103
  108. package/import/utils.js.map +1 -1
  109. package/package.json +23 -22
  110. package/types.d.ts +21 -0
  111. package/types.js.map +1 -1
  112. package/import/process/templatesHandler.js.map +0 -1
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.extractAndUploadZipFileContents = extractAndUploadZipFileContents;
8
+ var _stream = require("stream");
9
+ var _util = require("util");
10
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
11
+ var _path = _interopRequireDefault(require("path"));
12
+ var _yauzl = _interopRequireDefault(require("yauzl"));
13
+ var _fs = require("fs");
14
+ var _uniqid = _interopRequireDefault(require("uniqid"));
15
+ var _error = _interopRequireDefault(require("@webiny/error"));
16
+ var _downloadInstallFiles = require("@webiny/api-page-builder/graphql/crud/install/utils/downloadInstallFiles");
17
+ var _extractZipAndUploadToS = require("./extractZipAndUploadToS3");
18
+ var _getFileNameWithoutExt = require("./getFileNameWithoutExt");
19
+ var _constants = require("../constants");
20
+ var _fsExtra = require("fs-extra");
21
+ const streamPipeline = (0, _util.promisify)(_stream.pipeline);
22
+
23
+ /**
24
+ * Function will read the given zip file from S3 via stream, extract its content and upload it to S3 bucket.
25
+ * @param zipFileUrl
26
+ * @return ImportData S3 file keys for all uploaded assets group by page/block.
27
+ */
28
+ async function extractAndUploadZipFileContents(zipFileUrl) {
29
+ const log = console.log;
30
+ const importDataList = [];
31
+ const zipFileName = _path.default.basename(zipFileUrl).split("?")[0];
32
+ const response = await (0, _nodeFetch.default)(zipFileUrl);
33
+ const readStream = response.body;
34
+ if (!response.ok || !readStream) {
35
+ throw new _error.default(`Unable to downloading file: "${zipFileUrl}"`, response.statusText);
36
+ }
37
+ const uniquePath = (0, _uniqid.default)("IMPORTS/");
38
+ // Read export file and download it in the disk
39
+ const ZIP_FILE_PATH = _path.default.join(_constants.INSTALL_DIR, zipFileName);
40
+ const writeStream = (0, _fs.createWriteStream)(ZIP_FILE_PATH);
41
+ // @ts-ignore
42
+ await streamPipeline(readStream, writeStream);
43
+ log(`Downloaded file "${zipFileName}" at ${ZIP_FILE_PATH}`);
44
+
45
+ // Extract the downloaded zip file
46
+ const zipFilePaths = await extractZipToDisk(ZIP_FILE_PATH);
47
+ log(`Removing ZIP file "${zipFileUrl}" from ${ZIP_FILE_PATH}`);
48
+ await (0, _downloadInstallFiles.deleteFile)(ZIP_FILE_PATH);
49
+
50
+ // Extract each page/block zip and upload their content's to S3
51
+ for (let i = 0; i < zipFilePaths.length; i++) {
52
+ const currentPath = zipFilePaths[i];
53
+ const dataMap = await (0, _extractZipAndUploadToS.extractZipAndUploadToS3)(currentPath, uniquePath);
54
+ importDataList.push(dataMap);
55
+ }
56
+ log("Removing all ZIP files located at ", _path.default.dirname(zipFilePaths[0]));
57
+ await (0, _downloadInstallFiles.deleteFile)(_path.default.dirname(zipFilePaths[0]));
58
+ return importDataList;
59
+ }
60
+ function extractZipToDisk(exportFileZipPath) {
61
+ return new Promise((resolve, reject) => {
62
+ const zipFilePaths = [];
63
+ const uniqueFolderNameForExport = (0, _getFileNameWithoutExt.getFileNameWithoutExt)(exportFileZipPath);
64
+ const EXPORT_FILE_EXTRACTION_PATH = _path.default.join(_constants.INSTALL_DIR, uniqueFolderNameForExport);
65
+ // Make sure DIR exists
66
+ (0, _fsExtra.ensureDirSync)(EXPORT_FILE_EXTRACTION_PATH);
67
+ _yauzl.default.open(exportFileZipPath, {
68
+ lazyEntries: true
69
+ }, function (err, zipFile) {
70
+ if (err) {
71
+ console.warn("ERROR: Failed to extract zip: ", exportFileZipPath, err);
72
+ reject(err);
73
+ return;
74
+ }
75
+ if (!zipFile) {
76
+ console.log("ERROR: Missing zip file resource for path: " + exportFileZipPath);
77
+ reject("Missing Zip File Resource.");
78
+ return;
79
+ }
80
+ console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);
81
+ zipFile.on("end", function (err) {
82
+ if (err) {
83
+ console.warn("ERROR: Failed on END event for file: ", exportFileZipPath, err);
84
+ reject(err);
85
+ }
86
+ resolve(zipFilePaths);
87
+ });
88
+ zipFile.readEntry();
89
+ zipFile.on("entry", function (entry) {
90
+ console.info(`Processing entry: "${entry.fileName}"`);
91
+ if (/\/$/.test(entry.fileName)) {
92
+ // Directory file names end with '/'.
93
+ // Note that entries for directories themselves are optional.
94
+ // An entry's fileName implicitly requires its parent directories to exist.
95
+ zipFile.readEntry();
96
+ } else {
97
+ // file entry
98
+ zipFile.openReadStream(entry, function (err, readStream) {
99
+ if (err) {
100
+ console.warn("ERROR: Failed to openReadStream for file: ", entry.fileName, err);
101
+ reject(err);
102
+ return;
103
+ }
104
+ if (!readStream) {
105
+ console.log("ERROR: Missing Read Stream Resource when extracting to disk.");
106
+ reject("Missing Read Stream Resource.");
107
+ return;
108
+ }
109
+ const filePath = _path.default.join(EXPORT_FILE_EXTRACTION_PATH, entry.fileName);
110
+ readStream.on("end", function () {
111
+ zipFilePaths.push(filePath);
112
+ zipFile.readEntry();
113
+ });
114
+ streamPipeline(readStream, (0, _fs.createWriteStream)(filePath)).catch(error => {
115
+ reject(error);
116
+ });
117
+ });
118
+ }
119
+ });
120
+ });
121
+ });
122
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["streamPipeline","promisify","pipeline","extractAndUploadZipFileContents","zipFileUrl","log","console","importDataList","zipFileName","path","basename","split","response","fetch","readStream","body","ok","WebinyError","statusText","uniquePath","uniqueId","ZIP_FILE_PATH","join","INSTALL_DIR","writeStream","createWriteStream","zipFilePaths","extractZipToDisk","deleteFile","i","length","currentPath","dataMap","extractZipAndUploadToS3","push","dirname","exportFileZipPath","Promise","resolve","reject","uniqueFolderNameForExport","getFileNameWithoutExt","EXPORT_FILE_EXTRACTION_PATH","ensureDirSync","yauzl","open","lazyEntries","err","zipFile","warn","info","entryCount","on","readEntry","entry","fileName","test","openReadStream","filePath","catch","error"],"sources":["extractAndUploadZipFileContents.ts"],"sourcesContent":["import { pipeline } from \"stream\";\nimport { promisify } from \"util\";\nimport fetch from \"node-fetch\";\nimport path from \"path\";\nimport yauzl from \"yauzl\";\nimport { createWriteStream } from \"fs\";\nimport uniqueId from \"uniqid\";\nimport WebinyError from \"@webiny/error\";\nimport { deleteFile } from \"@webiny/api-page-builder/graphql/crud/install/utils/downloadInstallFiles\";\nimport { extractZipAndUploadToS3 } from \"~/import/utils/extractZipAndUploadToS3\";\nimport { getFileNameWithoutExt } from \"~/import/utils/getFileNameWithoutExt\";\nimport { ImportData } from \"~/types\";\nimport { INSTALL_DIR } from \"~/import/constants\";\nimport { ensureDirSync } from \"fs-extra\";\n\nconst streamPipeline = promisify(pipeline);\n\n/**\n * Function will read the given zip file from S3 via stream, extract its content and upload it to S3 bucket.\n * @param zipFileUrl\n * @return ImportData S3 file keys for all uploaded assets group by page/block.\n */\nexport async function extractAndUploadZipFileContents(zipFileUrl: string): Promise<ImportData[]> {\n const log = console.log;\n const importDataList = [];\n\n const zipFileName = path.basename(zipFileUrl).split(\"?\")[0];\n\n const response = await fetch(zipFileUrl);\n const readStream = response.body;\n if (!response.ok || !readStream) {\n throw new WebinyError(`Unable to downloading file: \"${zipFileUrl}\"`, response.statusText);\n }\n\n const uniquePath = uniqueId(\"IMPORTS/\");\n // Read export file and download it in the disk\n const ZIP_FILE_PATH = path.join(INSTALL_DIR, zipFileName);\n\n const writeStream = createWriteStream(ZIP_FILE_PATH);\n // @ts-ignore\n await streamPipeline(readStream, writeStream);\n log(`Downloaded file \"${zipFileName}\" at ${ZIP_FILE_PATH}`);\n\n // Extract the downloaded zip file\n const zipFilePaths = await extractZipToDisk(ZIP_FILE_PATH);\n\n log(`Removing ZIP file \"${zipFileUrl}\" from ${ZIP_FILE_PATH}`);\n await deleteFile(ZIP_FILE_PATH);\n\n // Extract each page/block zip and upload their content's to S3\n for (let i = 0; i < zipFilePaths.length; i++) {\n const currentPath = zipFilePaths[i];\n const dataMap = await extractZipAndUploadToS3(currentPath, uniquePath);\n importDataList.push(dataMap);\n }\n log(\"Removing all ZIP files located at \", path.dirname(zipFilePaths[0]));\n await deleteFile(path.dirname(zipFilePaths[0]));\n\n return importDataList;\n}\n\nfunction extractZipToDisk(exportFileZipPath: string): Promise<string[]> {\n return new Promise((resolve, reject) => {\n const zipFilePaths: string[] = [];\n const uniqueFolderNameForExport = getFileNameWithoutExt(exportFileZipPath);\n const EXPORT_FILE_EXTRACTION_PATH = path.join(INSTALL_DIR, uniqueFolderNameForExport);\n // Make sure DIR exists\n ensureDirSync(EXPORT_FILE_EXTRACTION_PATH);\n\n yauzl.open(exportFileZipPath, { lazyEntries: true }, function (err, zipFile) {\n if (err) {\n console.warn(\"ERROR: Failed to extract zip: \", exportFileZipPath, err);\n reject(err);\n return;\n }\n if (!zipFile) {\n console.log(\"ERROR: Missing zip file resource for path: \" + exportFileZipPath);\n reject(\"Missing Zip File Resource.\");\n return;\n }\n\n console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);\n\n zipFile.on(\"end\", function (err) {\n if (err) {\n console.warn(\"ERROR: Failed on END event for file: \", exportFileZipPath, err);\n reject(err);\n }\n resolve(zipFilePaths);\n });\n\n zipFile.readEntry();\n\n zipFile.on(\"entry\", function (entry) {\n console.info(`Processing entry: \"${entry.fileName}\"`);\n if (/\\/$/.test(entry.fileName)) {\n // Directory file names end with '/'.\n // Note that entries for directories themselves are optional.\n // An entry's fileName implicitly requires its parent directories to exist.\n zipFile.readEntry();\n } else {\n // file entry\n zipFile.openReadStream(entry, function (err, readStream) {\n if (err) {\n console.warn(\n \"ERROR: Failed to openReadStream for file: \",\n entry.fileName,\n err\n );\n reject(err);\n return;\n }\n if (!readStream) {\n console.log(\n \"ERROR: Missing Read Stream Resource when extracting to disk.\"\n );\n reject(\"Missing Read Stream Resource.\");\n return;\n }\n\n const filePath = path.join(EXPORT_FILE_EXTRACTION_PATH, entry.fileName);\n\n readStream.on(\"end\", function () {\n zipFilePaths.push(filePath);\n zipFile.readEntry();\n });\n\n streamPipeline(readStream, createWriteStream(filePath)).catch(error => {\n reject(error);\n });\n });\n }\n });\n });\n });\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA,MAAMA,cAAc,GAAG,IAAAC,eAAS,EAACC,gBAAQ,CAAC;;AAE1C;AACA;AACA;AACA;AACA;AACO,eAAeC,+BAA+B,CAACC,UAAkB,EAAyB;EAC7F,MAAMC,GAAG,GAAGC,OAAO,CAACD,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,CAAC;MACzB,CAAC,CAAC;MAEFsB,OAAO,CAACK,SAAS,EAAE;MAEnBL,OAAO,CAACI,EAAE,CAAC,OAAO,EAAE,UAAUE,KAAK,EAAE;QACjChD,OAAO,CAAC4C,IAAI,CAAE,sBAAqBI,KAAK,CAACC,QAAS,GAAE,CAAC;QACrD,IAAI,KAAK,CAACC,IAAI,CAACF,KAAK,CAACC,QAAQ,CAAC,EAAE;UAC5B;UACA;UACA;UACAP,OAAO,CAACK,SAAS,EAAE;QACvB,CAAC,MAAM;UACH;UACAL,OAAO,CAACS,cAAc,CAACH,KAAK,EAAE,UAAUP,GAAG,EAAEjC,UAAU,EAAE;YACrD,IAAIiC,GAAG,EAAE;cACLzC,OAAO,CAAC2C,IAAI,CACR,4CAA4C,EAC5CK,KAAK,CAACC,QAAQ,EACdR,GAAG,CACN;cACDR,MAAM,CAACQ,GAAG,CAAC;cACX;YACJ;YACA,IAAI,CAACjC,UAAU,EAAE;cACbR,OAAO,CAACD,GAAG,CACP,8DAA8D,CACjE;cACDkC,MAAM,CAAC,+BAA+B,CAAC;cACvC;YACJ;YAEA,MAAMmB,QAAQ,GAAGjD,aAAI,CAACa,IAAI,CAACoB,2BAA2B,EAAEY,KAAK,CAACC,QAAQ,CAAC;YAEvEzC,UAAU,CAACsC,EAAE,CAAC,KAAK,EAAE,YAAY;cAC7B1B,YAAY,CAACQ,IAAI,CAACwB,QAAQ,CAAC;cAC3BV,OAAO,CAACK,SAAS,EAAE;YACvB,CAAC,CAAC;YAEFrD,cAAc,CAACc,UAAU,EAAE,IAAAW,qBAAiB,EAACiC,QAAQ,CAAC,CAAC,CAACC,KAAK,CAACC,KAAK,IAAI;cACnErB,MAAM,CAACqB,KAAK,CAAC;YACjB,CAAC,CAAC;UACN,CAAC,CAAC;QACN;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN"}
@@ -0,0 +1,2 @@
1
+ import { ImportData } from "../../types";
2
+ export declare function extractZipAndUploadToS3(dataZipFilePath: string, uniquePath: string): Promise<ImportData>;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.extractZipAndUploadToS3 = extractZipAndUploadToS3;
8
+ var _yauzl = _interopRequireDefault(require("yauzl"));
9
+ var _stream = require("stream");
10
+ var _util = require("util");
11
+ var _s3Stream = require("../../export/s3Stream");
12
+ var _getFileNameWithoutExt = require("./getFileNameWithoutExt");
13
+ var _prepareDataDirMap = require("./prepareDataDirMap");
14
+ const FILE_CONTENT_TYPE = "application/octet-stream";
15
+ const streamPipeline = (0, _util.promisify)(_stream.pipeline);
16
+ function extractZipAndUploadToS3(dataZipFilePath, uniquePath) {
17
+ return new Promise((resolve, reject) => {
18
+ const filePaths = [];
19
+ const fileUploadPromises = [];
20
+ const uniqueKey = (0, _getFileNameWithoutExt.getFileNameWithoutExt)(dataZipFilePath);
21
+ let dataMap = {
22
+ key: uniqueKey,
23
+ assets: {},
24
+ data: ""
25
+ };
26
+ _yauzl.default.open(dataZipFilePath, {
27
+ lazyEntries: true
28
+ }, function (err, zipFile) {
29
+ if (err) {
30
+ console.warn("ERROR: Failed to extract zip: ", dataZipFilePath, err);
31
+ reject(err);
32
+ return;
33
+ }
34
+ if (!zipFile) {
35
+ console.log("ERROR: Probably failed to extract zip: " + dataZipFilePath);
36
+ reject("Missing Zip File Resource.");
37
+ return;
38
+ }
39
+ console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);
40
+ zipFile.on("end", function (err) {
41
+ if (err) {
42
+ console.warn('ERROR: Failed on "END" for file: ', dataZipFilePath, err);
43
+ reject(err);
44
+ }
45
+ Promise.all(fileUploadPromises).then(res => {
46
+ res.forEach(r => {
47
+ console.info("Done uploading... ", r);
48
+ });
49
+ resolve(dataMap);
50
+ });
51
+ });
52
+ zipFile.readEntry();
53
+ zipFile.on("entry", function (entry) {
54
+ console.info(`Processing entry: "${entry.fileName}"`);
55
+ if (/\/$/.test(entry.fileName)) {
56
+ // Directory file names end with '/'.
57
+ // Note that entries for directories themselves are optional.
58
+ // An entry's fileName implicitly requires its parent directories to exist.
59
+ zipFile.readEntry();
60
+ } else {
61
+ // file entry
62
+ zipFile.openReadStream(entry, function (err, readStream) {
63
+ if (err) {
64
+ console.warn("ERROR: Failed while performing [openReadStream] for file: ", entry.fileName, err);
65
+ reject(err);
66
+ return;
67
+ }
68
+ if (!readStream) {
69
+ console.log("ERROR: Missing Read Stream while importing.");
70
+ reject("Missing Read Strea Resource.");
71
+ return;
72
+ }
73
+ readStream.on("end", function () {
74
+ filePaths.push(entry.fileName);
75
+ zipFile.readEntry();
76
+ });
77
+ const newKey = `${uniquePath}/${uniqueKey}/${entry.fileName}`;
78
+ // Modify in place
79
+ dataMap = (0, _prepareDataDirMap.prepareDataDirMap)({
80
+ map: dataMap,
81
+ filePath: entry.fileName,
82
+ newKey
83
+ });
84
+ const {
85
+ streamPassThrough,
86
+ streamPassThroughUploadPromise: promise
87
+ } = _s3Stream.s3Stream.writeStream(newKey, FILE_CONTENT_TYPE);
88
+ streamPipeline(readStream, streamPassThrough).then(() => {
89
+ fileUploadPromises.push(promise);
90
+ }).catch(error => {
91
+ reject(error);
92
+ });
93
+ });
94
+ }
95
+ });
96
+ });
97
+ });
98
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FILE_CONTENT_TYPE","streamPipeline","promisify","pipeline","extractZipAndUploadToS3","dataZipFilePath","uniquePath","Promise","resolve","reject","filePaths","fileUploadPromises","uniqueKey","getFileNameWithoutExt","dataMap","key","assets","data","yauzl","open","lazyEntries","err","zipFile","console","warn","log","info","entryCount","on","all","then","res","forEach","r","readEntry","entry","fileName","test","openReadStream","readStream","push","newKey","prepareDataDirMap","map","filePath","streamPassThrough","streamPassThroughUploadPromise","promise","s3Stream","writeStream","catch","error"],"sources":["extractZipAndUploadToS3.ts"],"sourcesContent":["import yauzl from \"yauzl\";\nimport { pipeline } from \"stream\";\nimport { promisify } from \"util\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { s3Stream } from \"~/export/s3Stream\";\nimport { getFileNameWithoutExt } from \"./getFileNameWithoutExt\";\nimport { ImportData } from \"~/types\";\nimport { prepareDataDirMap } from \"~/import/utils/prepareDataDirMap\";\n\nconst FILE_CONTENT_TYPE = \"application/octet-stream\";\nconst streamPipeline = promisify(pipeline);\n\nexport function extractZipAndUploadToS3(\n dataZipFilePath: string,\n uniquePath: string\n): Promise<ImportData> {\n return new Promise((resolve, reject) => {\n const filePaths = [];\n const fileUploadPromises: Promise<S3.ManagedUpload.SendData>[] = [];\n const uniqueKey = getFileNameWithoutExt(dataZipFilePath);\n let dataMap: ImportData = {\n key: uniqueKey,\n assets: {},\n data: \"\"\n };\n yauzl.open(dataZipFilePath, { lazyEntries: true }, function (err, zipFile) {\n if (err) {\n console.warn(\"ERROR: Failed to extract zip: \", dataZipFilePath, err);\n reject(err);\n return;\n }\n if (!zipFile) {\n console.log(\"ERROR: Probably failed to extract zip: \" + dataZipFilePath);\n reject(\"Missing Zip File Resource.\");\n return;\n }\n console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);\n zipFile.on(\"end\", function (err) {\n if (err) {\n console.warn('ERROR: Failed on \"END\" for file: ', dataZipFilePath, err);\n reject(err);\n }\n\n Promise.all(fileUploadPromises).then(res => {\n res.forEach(r => {\n console.info(\"Done uploading... \", r);\n });\n resolve(dataMap);\n });\n });\n\n zipFile.readEntry();\n\n zipFile.on(\"entry\", function (entry) {\n console.info(`Processing entry: \"${entry.fileName}\"`);\n if (/\\/$/.test(entry.fileName)) {\n // Directory file names end with '/'.\n // Note that entries for directories themselves are optional.\n // An entry's fileName implicitly requires its parent directories to exist.\n zipFile.readEntry();\n } else {\n // file entry\n zipFile.openReadStream(entry, function (err, readStream) {\n if (err) {\n console.warn(\n \"ERROR: Failed while performing [openReadStream] for file: \",\n entry.fileName,\n err\n );\n reject(err);\n return;\n }\n if (!readStream) {\n console.log(\"ERROR: Missing Read Stream while importing.\");\n reject(\"Missing Read Strea Resource.\");\n return;\n }\n readStream.on(\"end\", function () {\n filePaths.push(entry.fileName);\n zipFile.readEntry();\n });\n\n const newKey = `${uniquePath}/${uniqueKey}/${entry.fileName}`;\n // Modify in place\n dataMap = prepareDataDirMap({\n map: dataMap,\n filePath: entry.fileName,\n newKey\n });\n\n const { streamPassThrough, streamPassThroughUploadPromise: promise } =\n s3Stream.writeStream(newKey, FILE_CONTENT_TYPE);\n\n streamPipeline(readStream, streamPassThrough)\n .then(() => {\n fileUploadPromises.push(promise);\n })\n .catch(error => {\n reject(error);\n });\n });\n }\n });\n });\n });\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA;AACA;AAEA;AAEA,MAAMA,iBAAiB,GAAG,0BAA0B;AACpD,MAAMC,cAAc,GAAG,IAAAC,eAAS,EAACC,gBAAQ,CAAC;AAEnC,SAASC,uBAAuB,CACnCC,eAAuB,EACvBC,UAAkB,EACC;EACnB,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACpC,MAAMC,SAAS,GAAG,EAAE;IACpB,MAAMC,kBAAwD,GAAG,EAAE;IACnE,MAAMC,SAAS,GAAG,IAAAC,4CAAqB,EAACR,eAAe,CAAC;IACxD,IAAIS,OAAmB,GAAG;MACtBC,GAAG,EAAEH,SAAS;MACdI,MAAM,EAAE,CAAC,CAAC;MACVC,IAAI,EAAE;IACV,CAAC;IACDC,cAAK,CAACC,IAAI,CAACd,eAAe,EAAE;MAAEe,WAAW,EAAE;IAAK,CAAC,EAAE,UAAUC,GAAG,EAAEC,OAAO,EAAE;MACvE,IAAID,GAAG,EAAE;QACLE,OAAO,CAACC,IAAI,CAAC,gCAAgC,EAAEnB,eAAe,EAAEgB,GAAG,CAAC;QACpEZ,MAAM,CAACY,GAAG,CAAC;QACX;MACJ;MACA,IAAI,CAACC,OAAO,EAAE;QACVC,OAAO,CAACE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C;cAC1DhB,MAAM,CAAC,8BAA8B,CAAC;cACtC;YACJ;YACA8B,UAAU,CAACX,EAAE,CAAC,KAAK,EAAE,YAAY;cAC7BlB,SAAS,CAAC8B,IAAI,CAACL,KAAK,CAACC,QAAQ,CAAC;cAC9Bd,OAAO,CAACY,SAAS,EAAE;YACvB,CAAC,CAAC;YAEF,MAAMO,MAAM,GAAI,GAAEnC,UAAW,IAAGM,SAAU,IAAGuB,KAAK,CAACC,QAAS,EAAC;YAC7D;YACAtB,OAAO,GAAG,IAAA4B,oCAAiB,EAAC;cACxBC,GAAG,EAAE7B,OAAO;cACZ8B,QAAQ,EAAET,KAAK,CAACC,QAAQ;cACxBK;YACJ,CAAC,CAAC;YAEF,MAAM;cAAEI,iBAAiB;cAAEC,8BAA8B,EAAEC;YAAQ,CAAC,GAChEC,kBAAQ,CAACC,WAAW,CAACR,MAAM,EAAEzC,iBAAiB,CAAC;YAEnDC,cAAc,CAACsC,UAAU,EAAEM,iBAAiB,CAAC,CACxCf,IAAI,CAAC,MAAM;cACRnB,kBAAkB,CAAC6B,IAAI,CAACO,OAAO,CAAC;YACpC,CAAC,CAAC,CACDG,KAAK,CAACC,KAAK,IAAI;cACZ1C,MAAM,CAAC0C,KAAK,CAAC;YACjB,CAAC,CAAC;UACV,CAAC,CAAC;QACN;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN"}
@@ -0,0 +1 @@
1
+ export declare function getFileNameWithoutExt(fileName: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getFileNameWithoutExt = getFileNameWithoutExt;
8
+ var _path = _interopRequireDefault(require("path"));
9
+ function getFileNameWithoutExt(fileName) {
10
+ return _path.default.basename(fileName).replace(_path.default.extname(fileName), "");
11
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getFileNameWithoutExt","fileName","path","basename","replace","extname"],"sources":["getFileNameWithoutExt.ts"],"sourcesContent":["import path from \"path\";\n\nexport function getFileNameWithoutExt(fileName: string): string {\n return path.basename(fileName).replace(path.extname(fileName), \"\");\n}\n"],"mappings":";;;;;;;AAAA;AAEO,SAASA,qBAAqB,CAACC,QAAgB,EAAU;EAC5D,OAAOC,aAAI,CAACC,QAAQ,CAACF,QAAQ,CAAC,CAACG,OAAO,CAACF,aAAI,CAACG,OAAO,CAACJ,QAAQ,CAAC,EAAE,EAAE,CAAC;AACtE"}
@@ -0,0 +1,9 @@
1
+ export * from "./initialStats";
2
+ export * from "./uploadFilesFromS3";
3
+ export * from "./uploadAssets";
4
+ export * from "./updateFilesInData";
5
+ export * from "./prepareDataDirMap";
6
+ export * from "./getFileNameWithoutExt";
7
+ export * from "./extractZipAndUploadToS3";
8
+ export * from "./extractAndUploadZipFileContents";
9
+ export * from "./deleteS3Folder";
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _initialStats = require("./initialStats");
7
+ Object.keys(_initialStats).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _initialStats[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _initialStats[key];
14
+ }
15
+ });
16
+ });
17
+ var _uploadFilesFromS = require("./uploadFilesFromS3");
18
+ Object.keys(_uploadFilesFromS).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _uploadFilesFromS[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _uploadFilesFromS[key];
25
+ }
26
+ });
27
+ });
28
+ var _uploadAssets = require("./uploadAssets");
29
+ Object.keys(_uploadAssets).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _uploadAssets[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _uploadAssets[key];
36
+ }
37
+ });
38
+ });
39
+ var _updateFilesInData = require("./updateFilesInData");
40
+ Object.keys(_updateFilesInData).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _updateFilesInData[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _updateFilesInData[key];
47
+ }
48
+ });
49
+ });
50
+ var _prepareDataDirMap = require("./prepareDataDirMap");
51
+ Object.keys(_prepareDataDirMap).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _prepareDataDirMap[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _prepareDataDirMap[key];
58
+ }
59
+ });
60
+ });
61
+ var _getFileNameWithoutExt = require("./getFileNameWithoutExt");
62
+ Object.keys(_getFileNameWithoutExt).forEach(function (key) {
63
+ if (key === "default" || key === "__esModule") return;
64
+ if (key in exports && exports[key] === _getFileNameWithoutExt[key]) return;
65
+ Object.defineProperty(exports, key, {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _getFileNameWithoutExt[key];
69
+ }
70
+ });
71
+ });
72
+ var _extractZipAndUploadToS = require("./extractZipAndUploadToS3");
73
+ Object.keys(_extractZipAndUploadToS).forEach(function (key) {
74
+ if (key === "default" || key === "__esModule") return;
75
+ if (key in exports && exports[key] === _extractZipAndUploadToS[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function () {
79
+ return _extractZipAndUploadToS[key];
80
+ }
81
+ });
82
+ });
83
+ var _extractAndUploadZipFileContents = require("./extractAndUploadZipFileContents");
84
+ Object.keys(_extractAndUploadZipFileContents).forEach(function (key) {
85
+ if (key === "default" || key === "__esModule") return;
86
+ if (key in exports && exports[key] === _extractAndUploadZipFileContents[key]) return;
87
+ Object.defineProperty(exports, key, {
88
+ enumerable: true,
89
+ get: function () {
90
+ return _extractAndUploadZipFileContents[key];
91
+ }
92
+ });
93
+ });
94
+ var _deleteS3Folder = require("./deleteS3Folder");
95
+ Object.keys(_deleteS3Folder).forEach(function (key) {
96
+ if (key === "default" || key === "__esModule") return;
97
+ if (key in exports && exports[key] === _deleteS3Folder[key]) return;
98
+ Object.defineProperty(exports, key, {
99
+ enumerable: true,
100
+ get: function () {
101
+ return _deleteS3Folder[key];
102
+ }
103
+ });
104
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./initialStats\";\nexport * from \"./uploadFilesFromS3\";\nexport * from \"./uploadAssets\";\nexport * from \"./updateFilesInData\";\nexport * from \"./prepareDataDirMap\";\nexport * from \"./getFileNameWithoutExt\";\nexport * from \"./extractZipAndUploadToS3\";\nexport * from \"./extractAndUploadZipFileContents\";\nexport * from \"./deleteS3Folder\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,7 @@
1
+ export declare function initialStats(total: number): {
2
+ pending: number;
3
+ processing: number;
4
+ completed: number;
5
+ failed: number;
6
+ total: number;
7
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initialStats = initialStats;
7
+ var _types = require("../../types");
8
+ function initialStats(total) {
9
+ return {
10
+ [_types.ImportExportTaskStatus.PENDING]: total,
11
+ [_types.ImportExportTaskStatus.PROCESSING]: 0,
12
+ [_types.ImportExportTaskStatus.COMPLETED]: 0,
13
+ [_types.ImportExportTaskStatus.FAILED]: 0,
14
+ total
15
+ };
16
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["initialStats","total","ImportExportTaskStatus","PENDING","PROCESSING","COMPLETED","FAILED"],"sources":["initialStats.ts"],"sourcesContent":["import { ImportExportTaskStatus } from \"~/types\";\n\nexport function initialStats(total: number) {\n return {\n [ImportExportTaskStatus.PENDING]: total,\n [ImportExportTaskStatus.PROCESSING]: 0,\n [ImportExportTaskStatus.COMPLETED]: 0,\n [ImportExportTaskStatus.FAILED]: 0,\n total\n };\n}\n"],"mappings":";;;;;;AAAA;AAEO,SAASA,YAAY,CAACC,KAAa,EAAE;EACxC,OAAO;IACH,CAACC,6BAAsB,CAACC,OAAO,GAAGF,KAAK;IACvC,CAACC,6BAAsB,CAACE,UAAU,GAAG,CAAC;IACtC,CAACF,6BAAsB,CAACG,SAAS,GAAG,CAAC;IACrC,CAACH,6BAAsB,CAACI,MAAM,GAAG,CAAC;IAClCL;EACJ,CAAC;AACL"}
@@ -0,0 +1,6 @@
1
+ import { ImportData } from "../../types";
2
+ export declare function prepareDataDirMap({ map, filePath, newKey }: {
3
+ map: ImportData;
4
+ filePath: string;
5
+ newKey: string;
6
+ }): ImportData;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.prepareDataDirMap = prepareDataDirMap;
8
+ var _dotPropImmutable = _interopRequireDefault(require("dot-prop-immutable"));
9
+ var _constants = require("../constants");
10
+ function prepareDataDirMap({
11
+ map,
12
+ filePath,
13
+ newKey
14
+ }) {
15
+ const isAsset = filePath.includes(_constants.ASSETS_DIR_NAME);
16
+ if (isAsset) {
17
+ /*
18
+ * We want to use dot (.) as part of object key rather than creating nested object(s).
19
+ * Also, the file name might contain dots in it beside the extension, so, we are escaping them all.
20
+ */
21
+ const assetKey = filePath.split(`${_constants.ASSETS_DIR_NAME}/`).pop();
22
+ const oldKey = assetKey.replace(/\./g, "\\.");
23
+ map = _dotPropImmutable.default.set(map, `assets.${oldKey}`, newKey);
24
+ } else {
25
+ // We only need to know the newKey for data file.
26
+ map = _dotPropImmutable.default.set(map, `data`, newKey);
27
+ }
28
+ return map;
29
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["prepareDataDirMap","map","filePath","newKey","isAsset","includes","ASSETS_DIR_NAME","assetKey","split","pop","oldKey","replace","dotProp","set"],"sources":["prepareDataDirMap.ts"],"sourcesContent":["import dotProp from \"dot-prop-immutable\";\nimport { ImportData } from \"~/types\";\nimport { ASSETS_DIR_NAME } from \"~/import/constants\";\n\nexport function prepareDataDirMap({\n map,\n filePath,\n newKey\n}: {\n map: ImportData;\n filePath: string;\n newKey: string;\n}): ImportData {\n const isAsset = filePath.includes(ASSETS_DIR_NAME);\n\n if (isAsset) {\n /*\n * We want to use dot (.) as part of object key rather than creating nested object(s).\n * Also, the file name might contain dots in it beside the extension, so, we are escaping them all.\n */\n const assetKey = filePath.split(`${ASSETS_DIR_NAME}/`).pop() as string;\n const oldKey = assetKey.replace(/\\./g, \"\\\\.\");\n\n map = dotProp.set(map, `assets.${oldKey}`, newKey);\n } else {\n // We only need to know the newKey for data file.\n map = dotProp.set(map, `data`, newKey);\n }\n\n return map;\n}\n"],"mappings":";;;;;;;AAAA;AAEA;AAEO,SAASA,iBAAiB,CAAC;EAC9BC,GAAG;EACHC,QAAQ;EACRC;AAKJ,CAAC,EAAc;EACX,MAAMC,OAAO,GAAGF,QAAQ,CAACG,QAAQ,CAACC,0BAAe,CAAC;EAElD,IAAIF,OAAO,EAAE;IACT;AACR;AACA;AACA;IACQ,MAAMG,QAAQ,GAAGL,QAAQ,CAACM,KAAK,CAAE,GAAEF,0BAAgB,GAAE,CAAC,CAACG,GAAG,EAAY;IACtE,MAAMC,MAAM,GAAGH,QAAQ,CAACI,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;IAE7CV,GAAG,GAAGW,yBAAO,CAACC,GAAG,CAACZ,GAAG,EAAG,UAASS,MAAO,EAAC,EAAEP,MAAM,CAAC;EACtD,CAAC,MAAM;IACH;IACAF,GAAG,GAAGW,yBAAO,CAACC,GAAG,CAACZ,GAAG,EAAG,MAAK,EAAEE,MAAM,CAAC;EAC1C;EAEA,OAAOF,GAAG;AACd"}
@@ -0,0 +1,8 @@
1
+ import { FileInput } from "@webiny/api-file-manager/types";
2
+ interface UpdateFilesInDataParams {
3
+ data: Record<string, any>;
4
+ fileIdToNewFileMap: Map<string, FileInput>;
5
+ srcPrefix: string;
6
+ }
7
+ export declare function updateFilesInData({ data, fileIdToNewFileMap, srcPrefix }: UpdateFilesInDataParams): void;
8
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateFilesInData = updateFilesInData;
7
+ function updateFilesInData({
8
+ data,
9
+ fileIdToNewFileMap,
10
+ srcPrefix
11
+ }) {
12
+ if (!data || typeof data !== "object") {
13
+ return;
14
+ }
15
+ // Recursively call function if data is array
16
+ if (Array.isArray(data)) {
17
+ for (let i = 0; i < data.length; i++) {
18
+ const element = data[i];
19
+ updateFilesInData({
20
+ data: element,
21
+ fileIdToNewFileMap,
22
+ srcPrefix
23
+ });
24
+ }
25
+ return;
26
+ }
27
+ // Main logic
28
+ const tuple = Object.entries(data);
29
+ for (let i = 0; i < tuple.length; i++) {
30
+ const [key, value] = tuple[i];
31
+ if (key === "file" && value && fileIdToNewFileMap.has(value.id)) {
32
+ const newFile = fileIdToNewFileMap.get(value.id);
33
+ if (!newFile) {
34
+ continue;
35
+ }
36
+ const cleanSrcPrefix = srcPrefix.endsWith("/") ? srcPrefix.slice(0, -1) : srcPrefix;
37
+ value.key = newFile.key;
38
+ value.name = newFile.name;
39
+ value.src = `${cleanSrcPrefix}/${newFile.key}`;
40
+ } else {
41
+ updateFilesInData({
42
+ data: value,
43
+ srcPrefix,
44
+ fileIdToNewFileMap
45
+ });
46
+ }
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["updateFilesInData","data","fileIdToNewFileMap","srcPrefix","Array","isArray","i","length","element","tuple","Object","entries","key","value","has","id","newFile","get","cleanSrcPrefix","endsWith","slice","name","src"],"sources":["updateFilesInData.ts"],"sourcesContent":["import { FileInput } from \"@webiny/api-file-manager/types\";\n\ninterface UpdateFilesInDataParams {\n data: Record<string, any>;\n fileIdToNewFileMap: Map<string, FileInput>;\n srcPrefix: string;\n}\n\nexport function updateFilesInData({\n data,\n fileIdToNewFileMap,\n srcPrefix\n}: UpdateFilesInDataParams) {\n if (!data || typeof data !== \"object\") {\n return;\n }\n // Recursively call function if data is array\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n updateFilesInData({ data: element, fileIdToNewFileMap, srcPrefix });\n }\n return;\n }\n // Main logic\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n\n if (key === \"file\" && value && fileIdToNewFileMap.has(value.id)) {\n const newFile = fileIdToNewFileMap.get(value.id);\n if (!newFile) {\n continue;\n }\n\n const cleanSrcPrefix = srcPrefix.endsWith(\"/\") ? srcPrefix.slice(0, -1) : srcPrefix;\n\n value.key = newFile.key;\n value.name = newFile.name;\n value.src = `${cleanSrcPrefix}/${newFile.key}`;\n } else {\n updateFilesInData({ data: value, src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IAAI;MACzBR,KAAK,CAACS,GAAG,GAAI,GAAEJ,cAAe,IAAGF,OAAO,CAACJ,GAAI,EAAC;IAClD,CAAC,MAAM;MACHZ,iBAAiB,CAAC;QAAEC,IAAI,EAAEY,KAAK;QAAEV,SAAS;QAAED;MAAmB,CAAC,CAAC;IACrE;EACJ;AACJ"}
@@ -0,0 +1,10 @@
1
+ import { PbImportExportContext } from "../../graphql/types";
2
+ import { File, FileInput } from "@webiny/api-file-manager/types";
3
+ import { FileUploadsData } from "../../types";
4
+ interface UploadAssetsParams {
5
+ context: PbImportExportContext;
6
+ files: File[];
7
+ fileUploadsData: FileUploadsData;
8
+ }
9
+ export declare const uploadAssets: (params: UploadAssetsParams) => Promise<Map<string, FileInput>>;
10
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.uploadAssets = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _mdbid = _interopRequireDefault(require("mdbid"));
10
+ var _uploadFilesFromS = require("./uploadFilesFromS3");
11
+ // @ts-ignore
12
+
13
+ const uploadAssets = async params => {
14
+ const {
15
+ context,
16
+ files,
17
+ fileUploadsData
18
+ } = params;
19
+ const oldIdToNewFileMap = new Map();
20
+
21
+ /**
22
+ * This function contains logic of file download from S3.
23
+ * Current we're not mocking zip file download from S3 in tests at the moment.
24
+ * So, we're manually mocking it in case of test just by returning an empty object.
25
+ */
26
+ if (process.env.NODE_ENV === "test") {
27
+ return oldIdToNewFileMap;
28
+ }
29
+
30
+ // A map of temporary file keys (created during ZIP upload) to permanent file keys.
31
+ const uploadFileMap = new Map();
32
+
33
+ // Array of file inputs, to insert into the DB.
34
+ const createFilesInput = [];
35
+ for (const oldFile of files) {
36
+ const id = (0, _mdbid.default)();
37
+ // We replace the old file ID with a new one.
38
+ const newKey = `${id}/${oldFile.key.replace(`${oldFile.id}/`, "")}`;
39
+ const newFile = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, oldFile), {}, {
40
+ id,
41
+ key: newKey
42
+ });
43
+ createFilesInput.push(newFile);
44
+ oldIdToNewFileMap.set(oldFile.id, newFile);
45
+ uploadFileMap.set(fileUploadsData.assets[oldFile.key], newFile);
46
+ }
47
+ await (0, _uploadFilesFromS.uploadFilesFromS3)(uploadFileMap);
48
+ await context.fileManager.createFilesInBatch(createFilesInput);
49
+ return oldIdToNewFileMap;
50
+ };
51
+ exports.uploadAssets = uploadAssets;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["uploadAssets","params","context","files","fileUploadsData","oldIdToNewFileMap","Map","process","env","NODE_ENV","uploadFileMap","createFilesInput","oldFile","id","mdbid","newKey","key","replace","newFile","push","set","assets","uploadFilesFromS3","fileManager","createFilesInBatch"],"sources":["uploadAssets.ts"],"sourcesContent":["// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { PbImportExportContext } from \"~/graphql/types\";\nimport { File, FileInput } from \"@webiny/api-file-manager/types\";\nimport { UploadFileMap, uploadFilesFromS3 } from \"~/import/utils/uploadFilesFromS3\";\nimport { FileUploadsData } from \"~/types\";\n\ninterface UploadAssetsParams {\n context: PbImportExportContext;\n files: File[];\n fileUploadsData: FileUploadsData;\n}\n\nexport const uploadAssets = async (params: UploadAssetsParams) => {\n const { context, files, fileUploadsData } = params;\n\n const oldIdToNewFileMap = new Map<string, FileInput>();\n\n /**\n * This function contains logic of file download from S3.\n * Current we're not mocking zip file download from S3 in tests at the moment.\n * So, we're manually mocking it in case of test just by returning an empty object.\n */\n if (process.env.NODE_ENV === \"test\") {\n return oldIdToNewFileMap;\n }\n\n // A map of temporary file keys (created during ZIP upload) to permanent file keys.\n const uploadFileMap: UploadFileMap = new Map();\n\n // Array of file inputs, to insert into the DB.\n const createFilesInput: FileInput[] = [];\n\n for (const oldFile of files) {\n const id = mdbid();\n // We replace the old file ID with a new one.\n const newKey = `${id}/${oldFile.key.replace(`${oldFile.id}/`, \"\")}`;\n const newFile: FileInput = { ...oldFile, id, key: newKey };\n\n createFilesInput.push(newFile);\n oldIdToNewFileMap.set(oldFile.id, newFile);\n uploadFileMap.set(fileUploadsData.assets[oldFile.key], newFile);\n }\n\n await uploadFilesFromS3(uploadFileMap);\n\n await context.fileManager.createFilesInBatch(createFilesInput);\n\n return oldIdToNewFileMap;\n};\n"],"mappings":";;;;;;;;AACA;AAGA;AAJA;;AAaO,MAAMA,YAAY,GAAG,MAAOC,MAA0B,IAAK;EAC9D,MAAM;IAAEC,OAAO;IAAEC,KAAK;IAAEC;EAAgB,CAAC,GAAGH,MAAM;EAElD,MAAMI,iBAAiB,GAAG,IAAIC,GAAG,EAAqB;;EAEtD;AACJ;AACA;AACA;AACA;EACI,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;IACjC,OAAOJ,iBAAiB;EAC5B;;EAEA;EACA,MAAMK,aAA4B,GAAG,IAAIJ,GAAG,EAAE;;EAE9C;EACA,MAAMK,gBAA6B,GAAG,EAAE;EAExC,KAAK,MAAMC,OAAO,IAAIT,KAAK,EAAE;IACzB,MAAMU,EAAE,GAAG,IAAAC,cAAK,GAAE;IAClB;IACA,MAAMC,MAAM,GAAI,GAAEF,EAAG,IAAGD,OAAO,CAACI,GAAG,CAACC,OAAO,CAAE,GAAEL,OAAO,CAACC,EAAG,GAAE,EAAE,EAAE,CAAE,EAAC;IACnE,MAAMK,OAAkB,+DAAQN,OAAO;MAAEC,EAAE;MAAEG,GAAG,EAAED;IAAM,EAAE;IAE1DJ,gBAAgB,CAACQ,IAAI,CAACD,OAAO,CAAC;IAC9Bb,iBAAiB,CAACe,GAAG,CAACR,OAAO,CAACC,EAAE,EAAEK,OAAO,CAAC;IAC1CR,aAAa,CAACU,GAAG,CAAChB,eAAe,CAACiB,MAAM,CAACT,OAAO,CAACI,GAAG,CAAC,EAAEE,OAAO,CAAC;EACnE;EAEA,MAAM,IAAAI,mCAAiB,EAACZ,aAAa,CAAC;EAEtC,MAAMR,OAAO,CAACqB,WAAW,CAACC,kBAAkB,CAACb,gBAAgB,CAAC;EAE9D,OAAON,iBAAiB;AAC5B,CAAC;AAAC"}
@@ -0,0 +1,3 @@
1
+ import { FileInput } from "@webiny/api-file-manager/types";
2
+ export declare type UploadFileMap = Map<string, FileInput>;
3
+ export declare function uploadFilesFromS3(fileMap: UploadFileMap): Promise<import("aws-sdk/clients/s3").ManagedUpload.SendData[]>;