@webiny/api-page-builder-import-export 0.0.0-unstable.1e66d121db → 0.0.0-unstable.611c5af35e
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 +2 -6
- package/client.js.map +1 -1
- package/exportPages/combine/index.js +11 -19
- package/exportPages/combine/index.js.map +1 -1
- package/exportPages/process/index.js +19 -35
- package/exportPages/process/index.js.map +1 -1
- package/exportPages/s3Stream.js +1 -20
- package/exportPages/s3Stream.js.map +1 -1
- package/exportPages/utils.js +18 -31
- package/exportPages/utils.js.map +1 -1
- package/exportPages/zipper.js +29 -41
- package/exportPages/zipper.js.map +1 -1
- package/graphql/crud/pageImportExportTasks.crud.js +9 -57
- package/graphql/crud/pageImportExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.js +21 -39
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud.js +0 -5
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/pageImportExportTasks.gql.js +1 -6
- package/graphql/graphql/pageImportExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.js +1 -6
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.js +0 -3
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.js +0 -4
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.js +0 -5
- package/graphql/index.js.map +1 -1
- package/importPages/create/index.js +9 -20
- package/importPages/create/index.js.map +1 -1
- package/importPages/process/index.js +24 -29
- package/importPages/process/index.js.map +1 -1
- package/importPages/utils.js +44 -126
- package/importPages/utils.js.map +1 -1
- package/mockSecurity.js +0 -2
- package/mockSecurity.js.map +1 -1
- package/package.json +23 -23
- package/types.js +0 -5
- package/types.js.map +1 -1
package/importPages/utils.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
@@ -9,44 +8,25 @@ exports.importPage = importPage;
|
|
9
8
|
exports.initialStats = initialStats;
|
10
9
|
exports.readExtractAndUploadZipFileContents = readExtractAndUploadZipFileContents;
|
11
10
|
exports.uploadPageAssets = void 0;
|
12
|
-
|
13
11
|
var _uniqid = _interopRequireDefault(require("uniqid"));
|
14
|
-
|
15
12
|
var _dotPropImmutable = _interopRequireDefault(require("dot-prop-immutable"));
|
16
|
-
|
17
13
|
var _fs = require("fs");
|
18
|
-
|
19
14
|
var _fsExtra = require("fs-extra");
|
20
|
-
|
21
15
|
var _util = require("util");
|
22
|
-
|
23
16
|
var _stream = require("stream");
|
24
|
-
|
25
17
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
26
|
-
|
27
18
|
var _path = _interopRequireDefault(require("path"));
|
28
|
-
|
29
19
|
var _yauzl = _interopRequireDefault(require("yauzl"));
|
30
|
-
|
31
20
|
var _chunk = _interopRequireDefault(require("lodash/chunk"));
|
32
|
-
|
33
21
|
var _loadJsonFile = _interopRequireDefault(require("load-json-file"));
|
34
|
-
|
35
22
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
36
|
-
|
37
23
|
var _downloadInstallFiles = require("@webiny/api-page-builder/graphql/crud/install/utils/downloadInstallFiles");
|
38
|
-
|
39
24
|
var _types = require("../types");
|
40
|
-
|
41
25
|
var _s3Stream = require("../exportPages/s3Stream");
|
42
|
-
|
43
26
|
const streamPipeline = (0, _util.promisify)(_stream.pipeline);
|
44
27
|
const INSTALL_DIR = "/tmp";
|
45
|
-
|
46
28
|
const INSTALL_EXTRACT_DIR = _path.default.join(INSTALL_DIR, "apiPageBuilderImportPage");
|
47
|
-
|
48
29
|
const FILES_COUNT_IN_EACH_BATCH = 15;
|
49
|
-
|
50
30
|
function updateImageInPageSettings(params) {
|
51
31
|
const {
|
52
32
|
settings,
|
@@ -55,22 +35,16 @@ function updateImageInPageSettings(params) {
|
|
55
35
|
} = params;
|
56
36
|
let newSettings = settings;
|
57
37
|
const srcPrefixWithoutTrailingSlash = srcPrefix.endsWith("/") ? srcPrefix.slice(0, -1) : srcPrefix;
|
58
|
-
|
59
38
|
if (_dotPropImmutable.default.get(newSettings, "general.image.src")) {
|
60
39
|
var _settings$general, _settings$general$ima;
|
61
|
-
|
62
40
|
newSettings = _dotPropImmutable.default.set(newSettings, "general.image.src", `${srcPrefixWithoutTrailingSlash}/${fileIdToKeyMap.get(((_settings$general = settings.general) === null || _settings$general === void 0 ? void 0 : (_settings$general$ima = _settings$general.image) === null || _settings$general$ima === void 0 ? void 0 : _settings$general$ima.id) || "")}`);
|
63
41
|
}
|
64
|
-
|
65
42
|
if (_dotPropImmutable.default.get(newSettings, "social.image.src")) {
|
66
43
|
var _settings$social, _settings$social$imag;
|
67
|
-
|
68
44
|
newSettings = _dotPropImmutable.default.set(newSettings, "social.image.src", `${srcPrefixWithoutTrailingSlash}/${fileIdToKeyMap.get(((_settings$social = settings.social) === null || _settings$social === void 0 ? void 0 : (_settings$social$imag = _settings$social.image) === null || _settings$social$imag === void 0 ? void 0 : _settings$social$imag.id) || "")}`);
|
69
45
|
}
|
70
|
-
|
71
46
|
return newSettings;
|
72
47
|
}
|
73
|
-
|
74
48
|
function updateFilesInPageData({
|
75
49
|
data,
|
76
50
|
fileIdToKeyMap,
|
@@ -79,9 +53,8 @@ function updateFilesInPageData({
|
|
79
53
|
// BASE CASE: Termination point
|
80
54
|
if (!data || typeof data !== "object") {
|
81
55
|
return;
|
82
|
-
}
|
83
|
-
|
84
|
-
|
56
|
+
}
|
57
|
+
// Recursively call function if data is array
|
85
58
|
if (Array.isArray(data)) {
|
86
59
|
for (let i = 0; i < data.length; i++) {
|
87
60
|
const element = data[i];
|
@@ -91,16 +64,12 @@ function updateFilesInPageData({
|
|
91
64
|
srcPrefix
|
92
65
|
});
|
93
66
|
}
|
94
|
-
|
95
67
|
return;
|
96
|
-
}
|
97
|
-
|
98
|
-
|
68
|
+
}
|
69
|
+
// Main logic
|
99
70
|
const tuple = Object.entries(data);
|
100
|
-
|
101
71
|
for (let i = 0; i < tuple.length; i++) {
|
102
72
|
const [key, value] = tuple[i];
|
103
|
-
|
104
73
|
if (key === "file" && value && fileIdToKeyMap.has(value.id)) {
|
105
74
|
value.key = fileIdToKeyMap.get(value.id);
|
106
75
|
value.name = fileIdToKeyMap.get(value.id);
|
@@ -114,52 +83,50 @@ function updateFilesInPageData({
|
|
114
83
|
}
|
115
84
|
}
|
116
85
|
}
|
117
|
-
|
118
86
|
const uploadPageAssets = async params => {
|
119
87
|
const {
|
120
88
|
context,
|
121
89
|
filesData,
|
122
90
|
fileUploadsData
|
123
|
-
} = params;
|
124
|
-
|
91
|
+
} = params;
|
92
|
+
// Save uploaded file key against static id for later use.
|
125
93
|
const fileIdToKeyMap = new Map();
|
126
94
|
/**
|
127
95
|
* This function contains logic of file download from S3.
|
128
96
|
* Current we're not mocking zip file download from S3 in tests at the moment.
|
129
97
|
* So, we're manually mocking it in case of test just by returning an empty object.
|
130
98
|
*/
|
131
|
-
|
132
99
|
if (process.env.NODE_ENV === "test") {
|
133
100
|
return {
|
134
101
|
fileIdToKeyMap
|
135
102
|
};
|
136
103
|
}
|
104
|
+
console.log("INSIDE uploadPageAssets");
|
137
105
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
106
|
+
// Save files meta data against old key for later use.
|
107
|
+
const fileKeyToFileMap = new Map();
|
108
|
+
// Initialize maps.
|
142
109
|
for (let i = 0; i < filesData.length; i++) {
|
143
110
|
const file = filesData[i];
|
144
|
-
fileKeyToFileMap.set(file.key, file);
|
111
|
+
fileKeyToFileMap.set(file.key, file);
|
145
112
|
|
113
|
+
// Initialize the value
|
146
114
|
fileIdToKeyMap.set(file.id, file.type);
|
147
115
|
}
|
148
|
-
|
149
116
|
const fileUploadResults = await uploadFilesFromS3({
|
150
117
|
fileKeyToFileMap,
|
151
118
|
oldKeyToNewKeyMap: fileUploadsData.assets
|
152
|
-
});
|
119
|
+
});
|
153
120
|
|
121
|
+
// Create files in File Manager
|
154
122
|
const createFilesInput = fileUploadResults.map(uploadResult => {
|
155
123
|
const newKey = uploadResult.Key;
|
156
124
|
const file = fileKeyToFileMap.get(getOldFileKey(newKey));
|
157
|
-
|
158
125
|
if (!file) {
|
159
126
|
return null;
|
160
|
-
}
|
161
|
-
|
127
|
+
}
|
162
128
|
|
129
|
+
// Update the file map with newly uploaded file.
|
163
130
|
fileIdToKeyMap.set(file.id, newKey);
|
164
131
|
return {
|
165
132
|
key: newKey,
|
@@ -170,10 +137,9 @@ const uploadPageAssets = async params => {
|
|
170
137
|
tags: file.tags
|
171
138
|
};
|
172
139
|
}).filter(Boolean);
|
173
|
-
const createFilesPromises = [];
|
174
|
-
|
140
|
+
const createFilesPromises = [];
|
141
|
+
// Gives an array of chunks (each consists of FILES_COUNT_IN_EACH_BATCH items).
|
175
142
|
const createFilesInputChunks = (0, _chunk.default)(createFilesInput, FILES_COUNT_IN_EACH_BATCH);
|
176
|
-
|
177
143
|
for (let i = 0; i < createFilesInputChunks.length; i++) {
|
178
144
|
const createFilesInputChunk = createFilesInputChunks[i];
|
179
145
|
createFilesPromises.push(
|
@@ -183,49 +149,44 @@ const uploadPageAssets = async params => {
|
|
183
149
|
*/
|
184
150
|
context.fileManager.files.createFilesInBatch(createFilesInputChunk));
|
185
151
|
}
|
186
|
-
|
187
152
|
await Promise.all(createFilesPromises);
|
188
153
|
return {
|
189
154
|
fileIdToKeyMap
|
190
155
|
};
|
191
156
|
};
|
192
|
-
|
193
157
|
exports.uploadPageAssets = uploadPageAssets;
|
194
|
-
|
195
158
|
async function importPage({
|
196
159
|
pageKey,
|
197
160
|
context,
|
198
161
|
fileUploadsData
|
199
162
|
}) {
|
200
|
-
const log = console.log;
|
163
|
+
const log = console.log;
|
201
164
|
|
165
|
+
// Making Directory for page in which we're going to extract the page data file.
|
202
166
|
const PAGE_EXTRACT_DIR = _path.default.join(INSTALL_EXTRACT_DIR, pageKey);
|
203
|
-
|
204
167
|
(0, _fsExtra.ensureDirSync)(PAGE_EXTRACT_DIR);
|
205
|
-
|
206
168
|
const pageDataFileKey = _dotPropImmutable.default.get(fileUploadsData, `data`);
|
207
|
-
|
208
169
|
const PAGE_DATA_FILE_PATH = _path.default.join(PAGE_EXTRACT_DIR, _path.default.basename(pageDataFileKey));
|
209
|
-
|
210
|
-
|
211
|
-
|
170
|
+
log(`Downloading Page data file: ${pageDataFileKey} at "${PAGE_DATA_FILE_PATH}"`);
|
171
|
+
// Download and save page data file in disk.
|
212
172
|
await new Promise((resolve, reject) => {
|
213
173
|
_s3Stream.s3Stream.readStream(pageDataFileKey).on("error", reject).pipe((0, _fs.createWriteStream)(PAGE_DATA_FILE_PATH)).on("error", reject).on("finish", resolve);
|
214
|
-
});
|
174
|
+
});
|
215
175
|
|
176
|
+
// Load the page data file from disk.
|
216
177
|
log(`Load file ${pageDataFileKey}`);
|
217
178
|
const {
|
218
179
|
page,
|
219
180
|
files
|
220
|
-
} = await (0, _loadJsonFile.default)(PAGE_DATA_FILE_PATH);
|
181
|
+
} = await (0, _loadJsonFile.default)(PAGE_DATA_FILE_PATH);
|
221
182
|
|
183
|
+
// Only update page data if there are files.
|
222
184
|
if (files && Array.isArray(files) && files.length > 0) {
|
223
185
|
// Upload page assets.
|
224
186
|
const {
|
225
187
|
fileIdToKeyMap
|
226
188
|
} = await uploadPageAssets({
|
227
189
|
context,
|
228
|
-
|
229
190
|
/**
|
230
191
|
* TODO @ts-refactor @ashutosh figure out correct types.
|
231
192
|
*/
|
@@ -248,47 +209,40 @@ async function importPage({
|
|
248
209
|
srcPrefix
|
249
210
|
});
|
250
211
|
}
|
251
|
-
|
252
212
|
log("Removing Directory for page...");
|
253
213
|
await (0, _downloadInstallFiles.deleteFile)(pageKey);
|
254
214
|
log(`Remove page contents from S3...`);
|
255
215
|
await deleteS3Folder(_path.default.dirname(fileUploadsData.data));
|
256
216
|
return page;
|
257
217
|
}
|
258
|
-
|
259
218
|
async function uploadFilesFromS3({
|
260
219
|
fileKeyToFileMap,
|
261
220
|
oldKeyToNewKeyMap
|
262
221
|
}) {
|
263
222
|
const oldKeysForAssets = Object.keys(oldKeyToNewKeyMap);
|
264
|
-
const promises = [];
|
265
|
-
|
223
|
+
const promises = [];
|
224
|
+
// Upload all assets.
|
266
225
|
for (let i = 0; i < oldKeysForAssets.length; i++) {
|
267
226
|
const oldKey = oldKeysForAssets[i];
|
268
|
-
const tempNewKey = oldKeyToNewKeyMap[oldKey];
|
269
|
-
|
270
|
-
const readStream = _s3Stream.s3Stream.readStream(tempNewKey); // Get file meta data.
|
271
|
-
|
227
|
+
const tempNewKey = oldKeyToNewKeyMap[oldKey];
|
272
228
|
|
229
|
+
// Read file.
|
230
|
+
const readStream = _s3Stream.s3Stream.readStream(tempNewKey);
|
231
|
+
// Get file meta data.
|
273
232
|
const fileMetaData = fileKeyToFileMap.get(oldKey);
|
274
|
-
|
275
233
|
if (fileMetaData) {
|
276
234
|
const newKey = (0, _uniqid.default)("", `-${fileMetaData.key}`);
|
277
|
-
|
278
235
|
const {
|
279
236
|
streamPassThrough,
|
280
237
|
streamPassThroughUploadPromise: promise
|
281
238
|
} = _s3Stream.s3Stream.writeStream(newKey, fileMetaData.type);
|
282
|
-
|
283
239
|
readStream.pipe(streamPassThrough);
|
284
240
|
promises.push(promise);
|
285
241
|
console.log(`Successfully queued file "${newKey}"`);
|
286
242
|
}
|
287
243
|
}
|
288
|
-
|
289
244
|
return Promise.all(promises);
|
290
245
|
}
|
291
|
-
|
292
246
|
function getOldFileKey(key) {
|
293
247
|
/*
|
294
248
|
* Because we know the naming convention, we can extract the old key from new key.
|
@@ -300,13 +254,10 @@ function getOldFileKey(key) {
|
|
300
254
|
return key;
|
301
255
|
}
|
302
256
|
}
|
303
|
-
|
304
257
|
const FILE_CONTENT_TYPE = "application/octet-stream";
|
305
|
-
|
306
258
|
function getFileNameWithoutExt(fileName) {
|
307
259
|
return _path.default.basename(fileName).replace(_path.default.extname(fileName), "");
|
308
260
|
}
|
309
|
-
|
310
261
|
/**
|
311
262
|
* Function will read the given zip file from S3 via stream, extract its content and upload it to S3 bucket.
|
312
263
|
* @param zipFileUrl
|
@@ -315,82 +266,70 @@ function getFileNameWithoutExt(fileName) {
|
|
315
266
|
async function readExtractAndUploadZipFileContents(zipFileUrl) {
|
316
267
|
const log = console.log;
|
317
268
|
const pageImportDataList = [];
|
318
|
-
|
319
269
|
const zipFileName = _path.default.basename(zipFileUrl).split("?")[0];
|
320
|
-
|
321
270
|
const response = await (0, _nodeFetch.default)(zipFileUrl);
|
322
|
-
|
323
271
|
if (!response.ok) {
|
324
272
|
throw new _error.default(`Unable to downloading file: "${zipFileUrl}"`, response.statusText);
|
325
273
|
}
|
326
|
-
|
327
274
|
const readStream = response.body;
|
328
|
-
const uniquePath = (0, _uniqid.default)("IMPORT_PAGES/");
|
329
|
-
|
275
|
+
const uniquePath = (0, _uniqid.default)("IMPORT_PAGES/");
|
276
|
+
// Read export file and download it in the disk
|
330
277
|
const ZIP_FILE_PATH = _path.default.join(INSTALL_DIR, zipFileName);
|
331
|
-
|
332
278
|
const writeStream = (0, _fs.createWriteStream)(ZIP_FILE_PATH);
|
333
279
|
await streamPipeline(readStream, writeStream);
|
334
|
-
log(`Downloaded file "${zipFileName}" at ${ZIP_FILE_PATH}`);
|
280
|
+
log(`Downloaded file "${zipFileName}" at ${ZIP_FILE_PATH}`);
|
335
281
|
|
282
|
+
// Extract the downloaded zip file
|
336
283
|
const zipFilePaths = await extractZipToDisk(ZIP_FILE_PATH);
|
337
284
|
log(`Removing ZIP file "${zipFileUrl}" from ${ZIP_FILE_PATH}`);
|
338
|
-
await (0, _downloadInstallFiles.deleteFile)(ZIP_FILE_PATH);
|
285
|
+
await (0, _downloadInstallFiles.deleteFile)(ZIP_FILE_PATH);
|
339
286
|
|
287
|
+
// Extract each page zip and upload their content's to S3
|
340
288
|
for (let i = 0; i < zipFilePaths.length; i++) {
|
341
289
|
const currentPath = zipFilePaths[i];
|
342
290
|
const dataMap = await extractZipAndUploadToS3(currentPath, uniquePath);
|
343
291
|
pageImportDataList.push(dataMap);
|
344
292
|
}
|
345
|
-
|
346
293
|
log("Removing all ZIP files located at ", _path.default.dirname(zipFilePaths[0]));
|
347
294
|
await (0, _downloadInstallFiles.deleteFile)(_path.default.dirname(zipFilePaths[0]));
|
348
295
|
return pageImportDataList;
|
349
296
|
}
|
350
|
-
|
351
297
|
const ASSETS_DIR_NAME = "/assets";
|
352
|
-
|
353
298
|
function preparePageDataDirMap({
|
354
299
|
map,
|
355
300
|
filePath,
|
356
301
|
newKey
|
357
302
|
}) {
|
358
303
|
const dirname = _path.default.dirname(filePath);
|
359
|
-
|
360
304
|
const fileName = _path.default.basename(filePath);
|
361
305
|
/*
|
362
306
|
* We want to use dot (.) as part of object key rather than creating nested object(s).
|
363
307
|
* Also, the file name might contain dots in it beside the extension, so, we are escaping them all.
|
364
308
|
*/
|
365
|
-
|
366
|
-
|
367
309
|
const oldKey = fileName.replace(/\./g, "\\.");
|
368
310
|
const isAsset = dirname.endsWith(ASSETS_DIR_NAME);
|
369
|
-
|
370
311
|
if (isAsset) {
|
371
312
|
map = _dotPropImmutable.default.set(map, `assets.${oldKey}`, newKey);
|
372
313
|
} else {
|
373
314
|
// We only need to know the newKey for data file.
|
374
315
|
map = _dotPropImmutable.default.set(map, `data`, newKey);
|
375
316
|
}
|
376
|
-
|
377
317
|
return map;
|
378
318
|
}
|
379
|
-
|
380
319
|
async function deleteS3Folder(key) {
|
381
320
|
// Append trailing slash i.e "/" to key to make sure we only delete a specific folder.
|
382
321
|
if (!key.endsWith("/")) {
|
383
322
|
key = `${key}/`;
|
384
323
|
}
|
385
|
-
|
386
324
|
const response = await _s3Stream.s3Stream.listObject(key);
|
387
325
|
const keys = (response.Contents || []).map(c => c.Key).filter(Boolean);
|
388
326
|
console.log(`Found ${keys.length} files.`);
|
389
327
|
const deleteFilePromises = keys.map(key => _s3Stream.s3Stream.deleteObject(key));
|
390
328
|
await Promise.all(deleteFilePromises);
|
391
329
|
console.log(`Successfully deleted ${deleteFilePromises.length} files.`);
|
392
|
-
}
|
330
|
+
}
|
393
331
|
|
332
|
+
// export const zeroPad = version => `${version}`.padStart(5, "0");
|
394
333
|
|
395
334
|
function initialStats(total) {
|
396
335
|
return {
|
@@ -401,17 +340,13 @@ function initialStats(total) {
|
|
401
340
|
total
|
402
341
|
};
|
403
342
|
}
|
404
|
-
|
405
343
|
function extractZipToDisk(exportFileZipPath) {
|
406
344
|
return new Promise((resolve, reject) => {
|
407
345
|
const pageZipFilePaths = [];
|
408
346
|
const uniqueFolderNameForExport = getFileNameWithoutExt(exportFileZipPath);
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
347
|
+
const EXPORT_FILE_EXTRACTION_PATH = _path.default.join(INSTALL_DIR, uniqueFolderNameForExport);
|
348
|
+
// Make sure DIR exists
|
413
349
|
(0, _fsExtra.ensureDirSync)(EXPORT_FILE_EXTRACTION_PATH);
|
414
|
-
|
415
350
|
_yauzl.default.open(exportFileZipPath, {
|
416
351
|
lazyEntries: true
|
417
352
|
}, function (err, zipFile) {
|
@@ -420,26 +355,22 @@ function extractZipToDisk(exportFileZipPath) {
|
|
420
355
|
reject(err);
|
421
356
|
return;
|
422
357
|
}
|
423
|
-
|
424
358
|
if (!zipFile) {
|
425
359
|
console.log("ERROR: Missing zip file resource for path: " + exportFileZipPath);
|
426
360
|
reject("Missing Zip File Resource.");
|
427
361
|
return;
|
428
362
|
}
|
429
|
-
|
430
363
|
console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);
|
431
364
|
zipFile.on("end", function (err) {
|
432
365
|
if (err) {
|
433
366
|
console.warn("ERROR: Failed on END event for file: ", exportFileZipPath, err);
|
434
367
|
reject(err);
|
435
368
|
}
|
436
|
-
|
437
369
|
resolve(pageZipFilePaths);
|
438
370
|
});
|
439
371
|
zipFile.readEntry();
|
440
372
|
zipFile.on("entry", function (entry) {
|
441
373
|
console.info(`Processing entry: "${entry.fileName}"`);
|
442
|
-
|
443
374
|
if (/\/$/.test(entry.fileName)) {
|
444
375
|
// Directory file names end with '/'.
|
445
376
|
// Note that entries for directories themselves are optional.
|
@@ -453,15 +384,12 @@ function extractZipToDisk(exportFileZipPath) {
|
|
453
384
|
reject(err);
|
454
385
|
return;
|
455
386
|
}
|
456
|
-
|
457
387
|
if (!readStream) {
|
458
388
|
console.log("ERROR: Missing Read Stream Resource when extracting to disk.");
|
459
389
|
reject("Missing Read Stream Resource.");
|
460
390
|
return;
|
461
391
|
}
|
462
|
-
|
463
392
|
const filePath = _path.default.join(EXPORT_FILE_EXTRACTION_PATH, entry.fileName);
|
464
|
-
|
465
393
|
readStream.on("end", function () {
|
466
394
|
pageZipFilePaths.push(filePath);
|
467
395
|
zipFile.readEntry();
|
@@ -475,7 +403,6 @@ function extractZipToDisk(exportFileZipPath) {
|
|
475
403
|
});
|
476
404
|
});
|
477
405
|
}
|
478
|
-
|
479
406
|
function extractZipAndUploadToS3(pageDataZipFilePath, uniquePath) {
|
480
407
|
return new Promise((resolve, reject) => {
|
481
408
|
const filePaths = [];
|
@@ -486,7 +413,6 @@ function extractZipAndUploadToS3(pageDataZipFilePath, uniquePath) {
|
|
486
413
|
assets: {},
|
487
414
|
data: ""
|
488
415
|
};
|
489
|
-
|
490
416
|
_yauzl.default.open(pageDataZipFilePath, {
|
491
417
|
lazyEntries: true
|
492
418
|
}, function (err, zipFile) {
|
@@ -495,20 +421,17 @@ function extractZipAndUploadToS3(pageDataZipFilePath, uniquePath) {
|
|
495
421
|
reject(err);
|
496
422
|
return;
|
497
423
|
}
|
498
|
-
|
499
424
|
if (!zipFile) {
|
500
425
|
console.log("ERROR: Probably failed to extract zip: " + pageDataZipFilePath);
|
501
426
|
reject("Missing Zip File Resource.");
|
502
427
|
return;
|
503
428
|
}
|
504
|
-
|
505
429
|
console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);
|
506
430
|
zipFile.on("end", function (err) {
|
507
431
|
if (err) {
|
508
432
|
console.warn('ERROR: Failed on "END" for file: ', pageDataZipFilePath, err);
|
509
433
|
reject(err);
|
510
434
|
}
|
511
|
-
|
512
435
|
Promise.all(fileUploadPromises).then(res => {
|
513
436
|
res.forEach(r => {
|
514
437
|
console.info("Done uploading... ", r);
|
@@ -519,7 +442,6 @@ function extractZipAndUploadToS3(pageDataZipFilePath, uniquePath) {
|
|
519
442
|
zipFile.readEntry();
|
520
443
|
zipFile.on("entry", function (entry) {
|
521
444
|
console.info(`Processing entry: "${entry.fileName}"`);
|
522
|
-
|
523
445
|
if (/\/$/.test(entry.fileName)) {
|
524
446
|
// Directory file names end with '/'.
|
525
447
|
// Note that entries for directories themselves are optional.
|
@@ -533,30 +455,26 @@ function extractZipAndUploadToS3(pageDataZipFilePath, uniquePath) {
|
|
533
455
|
reject(err);
|
534
456
|
return;
|
535
457
|
}
|
536
|
-
|
537
458
|
if (!readStream) {
|
538
459
|
console.log("ERROR: Missing Read Stream while importing pages.");
|
539
460
|
reject("Missing Read Strea Resource.");
|
540
461
|
return;
|
541
462
|
}
|
542
|
-
|
543
463
|
readStream.on("end", function () {
|
544
464
|
filePaths.push(entry.fileName);
|
545
465
|
zipFile.readEntry();
|
546
466
|
});
|
547
|
-
const newKey = `${uniquePath}/${uniquePageKey}/${entry.fileName}`;
|
548
|
-
|
467
|
+
const newKey = `${uniquePath}/${uniquePageKey}/${entry.fileName}`;
|
468
|
+
// Modify in place
|
549
469
|
dataMap = preparePageDataDirMap({
|
550
470
|
map: dataMap,
|
551
471
|
filePath: entry.fileName,
|
552
472
|
newKey
|
553
473
|
});
|
554
|
-
|
555
474
|
const {
|
556
475
|
streamPassThrough,
|
557
476
|
streamPassThroughUploadPromise: promise
|
558
477
|
} = _s3Stream.s3Stream.writeStream(newKey, FILE_CONTENT_TYPE);
|
559
|
-
|
560
478
|
streamPipeline(readStream, streamPassThrough).then(() => {
|
561
479
|
fileUploadPromises.push(promise);
|
562
480
|
}).catch(error => {
|