@webiny/api-page-builder-import-export 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.d16f688daf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +2 -2
- package/client.js +6 -2
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +106 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/{exportPages → export}/combine/index.d.ts +3 -2
- package/export/combine/index.js +30 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +6 -0
- package/export/combine/pagesHandler.js +106 -0
- package/export/combine/pagesHandler.js.map +1 -0
- package/export/process/blocksHandler.d.ts +6 -0
- package/export/process/blocksHandler.js +176 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/{exportPages → export}/process/index.d.ts +4 -6
- package/export/process/index.js +27 -0
- package/export/process/index.js.map +1 -0
- package/export/process/pagesHandler.d.ts +6 -0
- package/export/process/pagesHandler.js +204 -0
- package/export/process/pagesHandler.js.map +1 -0
- package/{exportPages → export}/s3Stream.d.ts +0 -0
- package/{exportPages → export}/s3Stream.js +20 -1
- package/{exportPages → export}/s3Stream.js.map +1 -1
- package/export/utils.d.ts +16 -0
- package/export/utils.js +135 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +6 -5
- package/{exportPages → export}/zipper.js +49 -36
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +155 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +105 -57
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +2 -2
- package/graphql/crud/pages.crud.js +53 -33
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +9 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +57 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +23 -18
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +8 -9
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.d.ts +1 -1
- package/graphql/graphql/utils/resolve.js +3 -0
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.js +8 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +5 -0
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +43 -23
- package/graphql/types.js.map +1 -1
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +110 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/{importPages → import}/create/index.d.ts +5 -4
- package/import/create/index.js +30 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +110 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/process/blocksHandler.d.ts +3 -0
- package/import/process/blocksHandler.js +175 -0
- package/import/process/blocksHandler.js.map +1 -0
- package/{importPages → import}/process/index.d.ts +4 -3
- package/import/process/index.js +27 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pagesHandler.d.ts +3 -0
- package/import/process/pagesHandler.js +180 -0
- package/import/process/pagesHandler.js.map +1 -0
- package/{importPages → import}/utils.d.ts +19 -20
- package/{importPages → import}/utils.js +229 -76
- package/import/utils.js.map +1 -0
- package/mockSecurity.js +2 -0
- package/mockSecurity.js.map +1 -1
- package/package.json +23 -23
- package/types.d.ts +62 -65
- package/types.js +22 -17
- package/types.js.map +1 -1
- package/exportPages/combine/index.js +0 -106
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -192
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -100
- package/exportPages/utils.js.map +0 -1
- package/exportPages/zipper.js.map +0 -1
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- package/importPages/create/index.js +0 -107
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -180
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.js.map +0 -1
@@ -0,0 +1,204 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.pagesHandler = void 0;
|
7
|
+
|
8
|
+
var _types = require("../../types");
|
9
|
+
|
10
|
+
var _client = require("../../client");
|
11
|
+
|
12
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
13
|
+
|
14
|
+
var _utils = require("../utils");
|
15
|
+
|
16
|
+
var _mockSecurity = require("../../mockSecurity");
|
17
|
+
|
18
|
+
var _utils2 = require("@webiny/utils");
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Handles the export pages process workflow.
|
22
|
+
*/
|
23
|
+
const pagesHandler = async (configuration, payload, context) => {
|
24
|
+
const log = console.log;
|
25
|
+
let subTask;
|
26
|
+
let noPendingTask = true;
|
27
|
+
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
28
|
+
log("RUNNING Export Pages Process Handler");
|
29
|
+
const {
|
30
|
+
pageBuilder,
|
31
|
+
fileManager
|
32
|
+
} = context;
|
33
|
+
const {
|
34
|
+
taskId,
|
35
|
+
subTaskIndex,
|
36
|
+
type,
|
37
|
+
identity
|
38
|
+
} = payload; // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
39
|
+
// and this Lambda is invoked internally, without credentials.
|
40
|
+
|
41
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
42
|
+
|
43
|
+
try {
|
44
|
+
/*
|
45
|
+
* Note: We're not going to DB for finding the next sub-task to process,
|
46
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
47
|
+
*/
|
48
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
49
|
+
/**
|
50
|
+
* Base condition!!
|
51
|
+
* Bail out early, if task not found or task's status is not "pending".
|
52
|
+
*/
|
53
|
+
|
54
|
+
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
55
|
+
noPendingTask = true;
|
56
|
+
return {
|
57
|
+
data: "",
|
58
|
+
error: null
|
59
|
+
};
|
60
|
+
} else {
|
61
|
+
noPendingTask = false;
|
62
|
+
}
|
63
|
+
|
64
|
+
log(`Fetched sub task => ${subTask.id}`);
|
65
|
+
const {
|
66
|
+
input
|
67
|
+
} = subTask;
|
68
|
+
const {
|
69
|
+
pageId,
|
70
|
+
exportPagesDataKey,
|
71
|
+
revisionType
|
72
|
+
} = input;
|
73
|
+
/**
|
74
|
+
* At the moment, we only export a single revision of the page.
|
75
|
+
* It could be "published" or "latest" depending upon user input.
|
76
|
+
*
|
77
|
+
* Note: In case of no "published" revision available, we use the latest revision.
|
78
|
+
*/
|
79
|
+
|
80
|
+
let page;
|
81
|
+
|
82
|
+
try {
|
83
|
+
if (revisionType === _types.ExportRevisionType.PUBLISHED) {
|
84
|
+
// Get "published" page.
|
85
|
+
page = await pageBuilder.getPublishedPageById({
|
86
|
+
id: pageId
|
87
|
+
});
|
88
|
+
} else {
|
89
|
+
// Get "latest" page.
|
90
|
+
page = await pageBuilder.getPage(pageId);
|
91
|
+
}
|
92
|
+
} catch (e) {
|
93
|
+
// If we're looking for "published" page and doesn't found it, get latest page.
|
94
|
+
if (revisionType === _types.ExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
|
95
|
+
page = await pageBuilder.getPage(pageId);
|
96
|
+
} else {
|
97
|
+
throw e;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
if (!page) {
|
102
|
+
log(`Unable to load page "${pageId}"`);
|
103
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load page "${pageId}"`);
|
104
|
+
}
|
105
|
+
|
106
|
+
log(`Processing page key "${pageId}" | version ${page.version} | ${page.status}`); // Mark task status as PROCESSING
|
107
|
+
|
108
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
109
|
+
status: _types.ImportExportTaskStatus.PROCESSING
|
110
|
+
}); // Update stats in main task
|
111
|
+
|
112
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
113
|
+
prevStatus: prevStatusOfSubTask,
|
114
|
+
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
115
|
+
});
|
116
|
+
prevStatusOfSubTask = subTask.status;
|
117
|
+
log(`Extracting page data and uploading to storage...`); // Extract Page
|
118
|
+
|
119
|
+
const pageDataZip = await (0, _utils.exportPage)(page, exportPagesDataKey, fileManager);
|
120
|
+
log(`Finish uploading zip...`); // Update task record in DB
|
121
|
+
|
122
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
123
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
124
|
+
data: {
|
125
|
+
message: `Finish uploading data for page "${page.id}" v${page.version} (${page.status}).`,
|
126
|
+
key: pageDataZip.Key
|
127
|
+
}
|
128
|
+
}); // Update stats in main task
|
129
|
+
|
130
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
131
|
+
prevStatus: prevStatusOfSubTask,
|
132
|
+
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
133
|
+
});
|
134
|
+
prevStatusOfSubTask = subTask.status;
|
135
|
+
} catch (e) {
|
136
|
+
log("[EXPORT_PAGES_PROCESS] Error => ", e);
|
137
|
+
|
138
|
+
if (subTask && subTask.id) {
|
139
|
+
/**
|
140
|
+
* In case of error, we'll update the task status to "failed",
|
141
|
+
* so that, client can show notify the user appropriately.
|
142
|
+
*/
|
143
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
144
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
145
|
+
error: {
|
146
|
+
name: e.name,
|
147
|
+
message: e.message,
|
148
|
+
stack: e.stack,
|
149
|
+
code: "EXPORT_FAILED"
|
150
|
+
}
|
151
|
+
}); // Update stats in main task
|
152
|
+
|
153
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
154
|
+
prevStatus: prevStatusOfSubTask,
|
155
|
+
nextStatus: _types.ImportExportTaskStatus.FAILED
|
156
|
+
});
|
157
|
+
prevStatusOfSubTask = subTask.status;
|
158
|
+
}
|
159
|
+
|
160
|
+
return {
|
161
|
+
data: null,
|
162
|
+
error: {
|
163
|
+
message: e.message
|
164
|
+
}
|
165
|
+
};
|
166
|
+
} finally {
|
167
|
+
// Base condition!
|
168
|
+
if (noPendingTask) {
|
169
|
+
log(`No pending sub-task for task ${taskId}`); // Combine individual page zip files.
|
170
|
+
|
171
|
+
await (0, _client.invokeHandlerClient)({
|
172
|
+
context,
|
173
|
+
name: configuration.handlers.combine,
|
174
|
+
payload: {
|
175
|
+
taskId,
|
176
|
+
type,
|
177
|
+
identity: context.security.getIdentity()
|
178
|
+
},
|
179
|
+
description: "Export pages - combine"
|
180
|
+
});
|
181
|
+
} else {
|
182
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`); // We want to continue with Self invocation no matter if current page error out.
|
183
|
+
|
184
|
+
await (0, _client.invokeHandlerClient)({
|
185
|
+
context,
|
186
|
+
name: configuration.handlers.process,
|
187
|
+
payload: {
|
188
|
+
taskId,
|
189
|
+
type,
|
190
|
+
subTaskIndex: subTaskIndex + 1,
|
191
|
+
identity: context.security.getIdentity()
|
192
|
+
},
|
193
|
+
description: "Export pages - process - subtask"
|
194
|
+
});
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
return {
|
199
|
+
data: "",
|
200
|
+
error: null
|
201
|
+
};
|
202
|
+
};
|
203
|
+
|
204
|
+
exports.pagesHandler = pagesHandler;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["pagesHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","pageBuilder","fileManager","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","pageId","exportPagesDataKey","revisionType","page","ExportRevisionType","PUBLISHED","getPublishedPageById","getPage","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","pageDataZip","exportPage","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["pagesHandler.ts"],"sourcesContent":["import { ExportRevisionType, ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportPage } from \"~/export/utils\";\nimport { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/export/process\";\n\n/**\n * Handles the export pages process workflow.\n */\nexport const pagesHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Pages Process Handler\");\n const { pageBuilder, fileManager } = context;\n const { taskId, subTaskIndex, type, identity } = payload;\n // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks\n // and this Lambda is invoked internally, without credentials.\n mockSecurity(identity as SecurityIdentity, context);\n\n try {\n /*\n * Note: We're not going to DB for finding the next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n subTask = await pageBuilder.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\n /**\n * Base condition!!\n * Bail out early, if task not found or task's status is not \"pending\".\n */\n if (!subTask || subTask.status !== ImportExportTaskStatus.PENDING) {\n noPendingTask = true;\n return {\n data: \"\",\n error: null\n };\n } else {\n noPendingTask = false;\n }\n\n log(`Fetched sub task => ${subTask.id}`);\n\n const { input } = subTask;\n const { pageId, exportPagesDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the page.\n * It could be \"published\" or \"latest\" depending upon user input.\n *\n * Note: In case of no \"published\" revision available, we use the latest revision.\n */\n let page;\n try {\n if (revisionType === ExportRevisionType.PUBLISHED) {\n // Get \"published\" page.\n page = await pageBuilder.getPublishedPageById({ id: pageId });\n } else {\n // Get \"latest\" page.\n page = await pageBuilder.getPage(pageId);\n }\n } catch (e) {\n // If we're looking for \"published\" page and doesn't found it, get latest page.\n if (revisionType === ExportRevisionType.PUBLISHED && e instanceof NotFoundError) {\n page = await pageBuilder.getPage(pageId);\n } else {\n throw e;\n }\n }\n\n if (!page) {\n log(`Unable to load page \"${pageId}\"`);\n throw new NotFoundError(`Unable to load page \"${pageId}\"`);\n }\n\n log(`Processing page key \"${pageId}\" | version ${page.version} | ${page.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting page data and uploading to storage...`);\n // Extract Page\n const pageDataZip = await exportPage(page, exportPagesDataKey, fileManager);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for page \"${page.id}\" v${page.version} (${page.status}).`,\n key: pageDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_PAGES_PROCESS] Error => \", e);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual page zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current page error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n type,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AAGA;AACA;AACA;AACO,MAAMA,YA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uBuC;MAFgB,CAAjD,CAAN;MAIAxC,mBAAmB,GAAGF,OAAO,CAACe,MAA9B;IACH;;IAED,OAAO;MACHC,IAAI,EAAE,IADH;MAEHC,KAAK,EAAE;QACHsB,OAAO,EAAEX,CAAC,CAACW;MADR;IAFJ,CAAP;EAMH,CArHD,SAqHU;IACN;IACA,IAAItC,aAAJ,EAAmB;MACfH,GAAG,CAAE,gCAA+BS,MAAO,EAAxC,CAAH,CADe,CAEf;;MACA,MAAM,IAAAuC,2BAAA,EAAoC;QACtCjD,OADsC;QAEtC8C,IAAI,EAAEhD,aAAa,CAACoD,QAAd,CAAuBC,OAFS;QAGtCpD,OAAO,EAAE;UACLW,MADK;UAELE,IAFK;UAGLC,QAAQ,EAAEb,OAAO,CAACoD,QAAR,CAAiBC,WAAjB;QAHL,CAH6B;QAQtCC,WAAW,EAAE;MARyB,CAApC,CAAN;IAUH,CAbD,MAaO;MACHpD,OAAO,CAACD,GAAR,CAAa,8BAA6BU,YAAY,GAAG,CAAE,GAA3D,EADG,CAEH;;MACA,MAAM,IAAAsC,2BAAA,EAA6B;QAC/BjD,OAD+B;QAE/B8C,IAAI,EAAEhD,aAAa,CAACoD,QAAd,CAAuBK,OAFE;QAG/BxD,OAAO,EAAE;UACLW,MADK;UAELE,IAFK;UAGLD,YAAY,EAAEA,YAAY,GAAG,CAHxB;UAILE,QAAQ,EAAEb,OAAO,CAACoD,QAAR,CAAiBC,WAAjB;QAJL,CAHsB;QAS/BC,WAAW,EAAE;MATkB,CAA7B,CAAN;IAWH;EACJ;;EACD,OAAO;IACHnC,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CAzKM"}
|
File without changes
|
@@ -1,15 +1,22 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
5
6
|
value: true
|
6
7
|
});
|
7
8
|
exports.s3Stream = void 0;
|
9
|
+
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
+
|
9
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13
|
+
|
10
14
|
var _stream = require("stream");
|
15
|
+
|
11
16
|
var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
|
17
|
+
|
12
18
|
const ARCHIVE_CONTENT_TYPE = "application/zip";
|
19
|
+
|
13
20
|
class S3Stream {
|
14
21
|
constructor() {
|
15
22
|
(0, _defineProperty2.default)(this, "s3", void 0);
|
@@ -19,19 +26,22 @@ class S3Stream {
|
|
19
26
|
});
|
20
27
|
this.bucket = process.env.S3_BUCKET;
|
21
28
|
}
|
29
|
+
|
22
30
|
getPresignedUrl(key) {
|
23
31
|
return this.s3.getSignedUrl("getObject", {
|
24
32
|
Bucket: this.bucket,
|
25
33
|
Key: key,
|
26
34
|
Expires: 604800 // 1 week
|
35
|
+
|
27
36
|
});
|
28
37
|
}
|
29
|
-
|
30
38
|
/**
|
31
39
|
* We're checking if the file is accessible on S3 by getting object meta data.
|
32
40
|
* It help us to filter files that we need to download as part of export data.
|
33
41
|
* @param Key {string}
|
34
42
|
*/
|
43
|
+
|
44
|
+
|
35
45
|
async isFileAccessible(Key) {
|
36
46
|
try {
|
37
47
|
await this.getObjectHead(Key);
|
@@ -42,18 +52,21 @@ class S3Stream {
|
|
42
52
|
return false;
|
43
53
|
}
|
44
54
|
}
|
55
|
+
|
45
56
|
getObjectHead(Key) {
|
46
57
|
return this.s3.headObject({
|
47
58
|
Bucket: this.bucket,
|
48
59
|
Key
|
49
60
|
}).promise();
|
50
61
|
}
|
62
|
+
|
51
63
|
readStream(Key) {
|
52
64
|
return this.s3.getObject({
|
53
65
|
Bucket: this.bucket,
|
54
66
|
Key
|
55
67
|
}).createReadStream();
|
56
68
|
}
|
69
|
+
|
57
70
|
writeStream(Key, contentType = ARCHIVE_CONTENT_TYPE) {
|
58
71
|
const streamPassThrough = new _stream.Stream.PassThrough();
|
59
72
|
const params = {
|
@@ -65,30 +78,36 @@ class S3Stream {
|
|
65
78
|
};
|
66
79
|
return {
|
67
80
|
streamPassThrough: streamPassThrough,
|
81
|
+
|
68
82
|
/**
|
69
83
|
* We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
|
70
84
|
*/
|
71
85
|
streamPassThroughUploadPromise: this.s3.upload(params).promise()
|
72
86
|
};
|
73
87
|
}
|
88
|
+
|
74
89
|
upload(params) {
|
75
90
|
return this.s3.upload((0, _objectSpread2.default)({
|
76
91
|
ACL: "private",
|
77
92
|
Bucket: this.bucket
|
78
93
|
}, params)).promise();
|
79
94
|
}
|
95
|
+
|
80
96
|
listObject(prefix) {
|
81
97
|
return this.s3.listObjects({
|
82
98
|
Bucket: this.bucket,
|
83
99
|
Prefix: prefix
|
84
100
|
}).promise();
|
85
101
|
}
|
102
|
+
|
86
103
|
deleteObject(key) {
|
87
104
|
return this.s3.deleteObject({
|
88
105
|
Key: key,
|
89
106
|
Bucket: this.bucket
|
90
107
|
}).promise();
|
91
108
|
}
|
109
|
+
|
92
110
|
}
|
111
|
+
|
93
112
|
const s3Stream = new S3Stream();
|
94
113
|
exports.s3Stream = s3Stream;
|
@@ -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","Expires","isFileAccessible","getObjectHead","error","console","warn","log","headObject","promise","readStream","getObject","createReadStream","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","Body","ContentType","streamPassThroughUploadPromise","upload","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream"],"sources":["s3Stream.ts"],"sourcesContent":["import { Stream, PassThrough, Readable } from \"stream\";\nimport S3 from \"aws-sdk/clients/s3\";\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 this.s3.getSignedUrl(\"getObject\", {\n Bucket: this.bucket,\n Key: key,\n Expires: 604800 // 1 week\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<S3.HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key }).promise();\n }\n\n readStream(Key: string): Readable {\n return this.s3.getObject({ Bucket: this.bucket, Key }).createReadStream();\n }\n\n writeStream(\n Key: string,\n contentType: string = ARCHIVE_CONTENT_TYPE\n ): {\n streamPassThrough: PassThrough;\n streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;\n } {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: S3.PutObjectRequest = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\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: this.s3.upload(params).promise()\n };\n }\n\n upload(params: {\n Key: string;\n ContentType: string;\n Body: Buffer;\n }): Promise<S3.ManagedUpload.SendData> {\n return this.s3\n .upload({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n .promise();\n }\n\n listObject(prefix: string): Promise<S3.ListObjectsOutput> {\n return this.s3\n .listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n })\n .promise();\n }\n\n deleteObject(key: string): Promise<S3.DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket }).promise();\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":"
|
1
|
+
{"version":3,"names":["ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","Bucket","Key","Expires","isFileAccessible","getObjectHead","error","console","warn","log","headObject","promise","readStream","getObject","createReadStream","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","Body","ContentType","streamPassThroughUploadPromise","upload","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream"],"sources":["s3Stream.ts"],"sourcesContent":["import { Stream, PassThrough, Readable } from \"stream\";\nimport S3 from \"aws-sdk/clients/s3\";\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 this.s3.getSignedUrl(\"getObject\", {\n Bucket: this.bucket,\n Key: key,\n Expires: 604800 // 1 week\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<S3.HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key }).promise();\n }\n\n readStream(Key: string): Readable {\n return this.s3.getObject({ Bucket: this.bucket, Key }).createReadStream();\n }\n\n writeStream(\n Key: string,\n contentType: string = ARCHIVE_CONTENT_TYPE\n ): {\n streamPassThrough: PassThrough;\n streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;\n } {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: S3.PutObjectRequest = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\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: this.s3.upload(params).promise()\n };\n }\n\n upload(params: {\n Key: string;\n ContentType: string;\n Body: Buffer;\n }): Promise<S3.ManagedUpload.SendData> {\n return this.s3\n .upload({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n .promise();\n }\n\n listObject(prefix: string): Promise<S3.ListObjectsOutput> {\n return this.s3\n .listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n })\n .promise();\n }\n\n deleteObject(key: string): Promise<S3.DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket }).promise();\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA,MAAMA,oBAAoB,GAAG,iBAA7B;;AAEA,MAAMC,QAAN,CAAe;EAIXC,WAAW,GAAG;IAAA;IAAA;IACV,KAAKC,EAAL,GAAU,IAAIC,UAAJ,CAAO;MACbC,MAAM,EAAEC,OAAO,CAACC,GAAR,CAAYC;IADP,CAAP,CAAV;IAGA,KAAKC,MAAL,GAAcH,OAAO,CAACC,GAAR,CAAYG,SAA1B;EACH;;EAEDC,eAAe,CAACC,GAAD,EAAc;IACzB,OAAO,KAAKT,EAAL,CAAQU,YAAR,CAAqB,WAArB,EAAkC;MACrCC,MAAM,EAAE,KAAKL,MADwB;MAErCM,GAAG,EAAEH,GAFgC;MAGrCI,OAAO,EAAE,MAH4B,CAGrB;;IAHqB,CAAlC,CAAP;EAKH;EAED;AACJ;AACA;AACA;AACA;;;EAC0B,MAAhBC,gBAAgB,CAACF,GAAD,EAAgC;IAClD,IAAI;MACA,MAAM,KAAKG,aAAL,CAAmBH,GAAnB,CAAN;MACA,OAAO,IAAP;IACH,CAHD,CAGE,OAAOI,KAAP,EAAc;MACZC,OAAO,CAACC,IAAR,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,GAAD,EAA8C;IACtD,OAAO,KAAKT,EAAL,CAAQwC,YAAR,CAAqB;MAAE5B,GAAG,EAAEH,GAAP;MAAYE,MAAM,EAAE,KAAKL;IAAzB,CAArB,EAAwDe,OAAxD,EAAP;EACH;;AA9FU;;AAiGR,MAAMoB,QAAQ,GAAG,IAAI3C,QAAJ,EAAjB"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import S3 from "aws-sdk/clients/s3";
|
2
|
+
import { Page, PageBlock } from "@webiny/api-page-builder/types";
|
3
|
+
import { FileManagerContext, File } from "@webiny/api-file-manager/types";
|
4
|
+
export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
5
|
+
export declare const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
6
|
+
export interface ExportedPageData {
|
7
|
+
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
8
|
+
files: File[];
|
9
|
+
}
|
10
|
+
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
11
|
+
export interface ExportedBlockData {
|
12
|
+
block: Pick<PageBlock, "name" | "content" | "preview">;
|
13
|
+
files: File[];
|
14
|
+
}
|
15
|
+
export declare function exportBlock(block: PageBlock, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
16
|
+
export declare function extractFilesFromData(data: Record<string, any>, files?: any[]): File[];
|
package/export/utils.js
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
|
9
|
+
exports.exportBlock = exportBlock;
|
10
|
+
exports.exportPage = exportPage;
|
11
|
+
exports.extractFilesFromData = extractFilesFromData;
|
12
|
+
|
13
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
14
|
+
|
15
|
+
var _zipper = _interopRequireDefault(require("./zipper"));
|
16
|
+
|
17
|
+
const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
18
|
+
exports.EXPORT_PAGES_FOLDER_KEY = EXPORT_PAGES_FOLDER_KEY;
|
19
|
+
const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
20
|
+
exports.EXPORT_BLOCKS_FOLDER_KEY = EXPORT_BLOCKS_FOLDER_KEY;
|
21
|
+
|
22
|
+
async function exportPage(page, exportPagesDataKey, fileManager) {
|
23
|
+
// Extract all files
|
24
|
+
const files = extractFilesFromData(page.content || {}); // Extract images from page settings
|
25
|
+
|
26
|
+
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
27
|
+
const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id); // Get file data for all images
|
28
|
+
|
29
|
+
const imageFilesData = [];
|
30
|
+
|
31
|
+
if (fileIds.length > 0) {
|
32
|
+
const [filesData] = await fileManager.files.listFiles({
|
33
|
+
ids: fileIds
|
34
|
+
});
|
35
|
+
imageFilesData.push(...filesData);
|
36
|
+
} // Extract the page data in a json file and upload it to S3
|
37
|
+
|
38
|
+
|
39
|
+
const pageData = {
|
40
|
+
page: {
|
41
|
+
content: page.content,
|
42
|
+
title: page.title,
|
43
|
+
path: page.path,
|
44
|
+
version: page.version,
|
45
|
+
status: page.status,
|
46
|
+
settings: page.settings
|
47
|
+
},
|
48
|
+
files: imageFilesData
|
49
|
+
};
|
50
|
+
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
51
|
+
const zipper = new _zipper.default({
|
52
|
+
exportInfo: {
|
53
|
+
files: imageFilesData,
|
54
|
+
name: page.title,
|
55
|
+
dataBuffer: pageDataBuffer
|
56
|
+
},
|
57
|
+
archiveFileKey: exportPagesDataKey
|
58
|
+
});
|
59
|
+
return zipper.process();
|
60
|
+
}
|
61
|
+
|
62
|
+
async function exportBlock(block, exportBlocksDataKey, fileManager) {
|
63
|
+
// Extract all files
|
64
|
+
const files = extractFilesFromData(block.content || {});
|
65
|
+
const fileIds = files.map(imageFile => imageFile.id); // Get file data for all images
|
66
|
+
|
67
|
+
const imageFilesData = [];
|
68
|
+
|
69
|
+
if (fileIds.length > 0) {
|
70
|
+
const [filesData] = await fileManager.files.listFiles({
|
71
|
+
ids: fileIds
|
72
|
+
});
|
73
|
+
imageFilesData.push(...filesData);
|
74
|
+
} // Add block preview image file data
|
75
|
+
|
76
|
+
|
77
|
+
if (block.preview.id) {
|
78
|
+
imageFilesData.push(await fileManager.files.getFile(block.preview.id));
|
79
|
+
} // Extract the block data in a json file and upload it to S3
|
80
|
+
|
81
|
+
|
82
|
+
const blockData = {
|
83
|
+
block: {
|
84
|
+
name: block.name,
|
85
|
+
content: block.content,
|
86
|
+
preview: block.preview
|
87
|
+
},
|
88
|
+
files: imageFilesData
|
89
|
+
};
|
90
|
+
const blockDataBuffer = Buffer.from(JSON.stringify(blockData));
|
91
|
+
const zipper = new _zipper.default({
|
92
|
+
exportInfo: {
|
93
|
+
files: imageFilesData,
|
94
|
+
name: block.name,
|
95
|
+
dataBuffer: blockDataBuffer
|
96
|
+
},
|
97
|
+
archiveFileKey: exportBlocksDataKey
|
98
|
+
});
|
99
|
+
return zipper.process();
|
100
|
+
}
|
101
|
+
|
102
|
+
function extractFilesFromData(data, files = []) {
|
103
|
+
// Base case: termination
|
104
|
+
if (!data || typeof data !== "object") {
|
105
|
+
return files;
|
106
|
+
} // Recursively call function for each element
|
107
|
+
|
108
|
+
|
109
|
+
if (Array.isArray(data)) {
|
110
|
+
for (let i = 0; i < data.length; i++) {
|
111
|
+
const element = data[i];
|
112
|
+
extractFilesFromData(element, files);
|
113
|
+
}
|
114
|
+
|
115
|
+
return files;
|
116
|
+
} // Main
|
117
|
+
|
118
|
+
|
119
|
+
const tuple = Object.entries(data);
|
120
|
+
|
121
|
+
for (let i = 0; i < tuple.length; i++) {
|
122
|
+
const [key, value] = tuple[i]; // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
|
123
|
+
|
124
|
+
if (key === "file" && value) {
|
125
|
+
files.push(value);
|
126
|
+
} else if (key === "images" && Array.isArray(value)) {
|
127
|
+
// Handle case for "images-list" component
|
128
|
+
files.push(...value);
|
129
|
+
} else {
|
130
|
+
extractFilesFromData(value, files);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
return files;
|
135
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","EXPORT_BLOCKS_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","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, PageBlock } 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\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport async function exportPage(\n page: Page,\n exportPagesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromData(page.content || {});\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\") as unknown as File,\n get(page, \"settings.social.image\") as unknown as File\n ].filter(image => image && image.src);\n\n const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: imageFilesData\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: page.title,\n dataBuffer: pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\" | \"preview\">;\n files: File[];\n}\n\nexport async function exportBlock(\n block: PageBlock,\n exportBlocksDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromData(block.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n // Add block preview image file data\n if (block.preview.id) {\n imageFilesData.push(await fileManager.files.getFile(block.preview.id));\n }\n\n // Extract the block data in a json file and upload it to S3\n const blockData = {\n block: {\n name: block.name,\n content: block.content,\n preview: block.preview\n },\n files: imageFilesData\n };\n const blockDataBuffer = Buffer.from(JSON.stringify(blockData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: block.name,\n dataBuffer: blockDataBuffer\n },\n archiveFileKey: exportBlocksDataKey\n });\n\n return zipper.process();\n}\n\nexport function extractFilesFromData(data: Record<string, any>, files: any[] = []): File[] {\n // Base case: termination\n if (!data || typeof data !== \"object\") {\n return files;\n }\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;;AAGA;;AACA;;AAEO,MAAMA,uBAAuB,GAAG,wBAAhC;;AACA,MAAMC,wBAAwB,GAAG,wBAAjC;;;AAOA,eAAeC,UAAf,CACHC,IADG,EAEHC,kBAFG,EAGHC,WAHG,EAI+B;EAClC;EACA,MAAMC,KAAK,GAAGC,oBAAoB,CAACJ,IAAI,CAACK,OAAL,IAAgB,EAAjB,CAAlC,CAFkC,CAGlC;;EACA,MAAMC,kBAAkB,GAAG,CACvB,IAAAC,YAAA,EAAIP,IAAJ,EAAU,wBAAV,CADuB,EAEvB,IAAAO,YAAA,EAAIP,IAAJ,EAAU,uBAAV,CAFuB,EAGzBQ,MAHyB,CAGlBC,KAAK,IAAIA,KAAK,IAAIA,KAAK,CAACC,GAHN,CAA3B;EAKA,MAAMC,OAAO,GAAG,CAAC,GAAGR,KAAJ,EAAW,GAAGG,kBAAd,EAAkCM,GAAlC,CAAsCC,SAAS,IAAIA,SAAS,CAACC,EAA7D,CAAhB,CATkC,CAUlC;;EACA,MAAMC,cAAc,GAAG,EAAvB;;EACA,IAAIJ,OAAO,CAACK,MAAR,GAAiB,CAArB,EAAwB;IACpB,MAAM,CAACC,SAAD,IAAc,MAA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MC,OAAO,GAAGJ,IAAI,CAACG,CAAD,CAApB;MACA7C,oBAAoB,CAAC8C,OAAD,EAAU/C,KAAV,CAApB;IACH;;IACD,OAAOA,KAAP;EACH,CAZsF,CAcvF;;;EACA,MAAMgD,KAAK,GAAGC,MAAM,CAACC,OAAP,CAAeP,IAAf,CAAd;;EACA,KAAK,IAAIG,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGE,KAAK,CAACnC,MAA1B,EAAkCiC,CAAC,EAAnC,EAAuC;IACnC,MAAM,CAACK,GAAD,EAAMC,KAAN,IAAeJ,KAAK,CAACF,CAAD,CAA1B,CADmC,CAEnC;;IACA,IAAIK,GAAG,KAAK,MAAR,IAAkBC,KAAtB,EAA6B;MACzBpD,KAAK,CAACiB,IAAN,CAAWmC,KAAX;IACH,CAFD,MAEO,IAAID,GAAG,KAAK,QAAR,IAAoBP,KAAK,CAACC,OAAN,CAAcO,KAAd,CAAxB,EAA8C;MACjD;MACApD,KAAK,CAACiB,IAAN,CAAW,GAAGmC,KAAd;IACH,CAHM,MAGA;MACHnD,oBAAoB,CAACmD,KAAD,EAAQpD,KAAR,CAApB;IACH;EACJ;;EACD,OAAOA,KAAP;AACH"}
|
@@ -2,15 +2,15 @@
|
|
2
2
|
/// <reference types="node" />
|
3
3
|
import S3 from "aws-sdk/clients/s3";
|
4
4
|
import { Readable } from "stream";
|
5
|
-
import {
|
5
|
+
import { File } from "@webiny/api-file-manager/types";
|
6
6
|
interface FileStreamDetails {
|
7
7
|
stream: Readable;
|
8
8
|
filename: string;
|
9
9
|
}
|
10
10
|
interface ExportInfo {
|
11
|
-
files:
|
12
|
-
|
13
|
-
|
11
|
+
files: File[];
|
12
|
+
name: string;
|
13
|
+
dataBuffer: Buffer;
|
14
14
|
}
|
15
15
|
export interface ZipperConfig {
|
16
16
|
exportInfo: ExportInfo;
|
@@ -29,7 +29,8 @@ export declare class ZipOfZip {
|
|
29
29
|
private readonly archiveFormat;
|
30
30
|
private readonly archiveFileName;
|
31
31
|
keys: string[];
|
32
|
-
|
32
|
+
filename: string;
|
33
|
+
constructor(keys: string[], filename: string);
|
33
34
|
getFileStreams(): FileStreamDetails[];
|
34
35
|
process(): Promise<S3.ManagedUpload.SendData>;
|
35
36
|
}
|