@webiny/api-page-builder-import-export 5.39.2 → 5.39.3-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/export/combine/index.js +2 -2
- package/export/combine/index.js.map +1 -1
- package/export/pages/ExportPagesCleanup.d.ts +5 -0
- package/export/pages/ExportPagesCleanup.js +82 -0
- package/export/pages/ExportPagesCleanup.js.map +1 -0
- package/export/pages/ExportPagesController.d.ts +5 -0
- package/export/pages/ExportPagesController.js +31 -0
- package/export/pages/ExportPagesController.js.map +1 -0
- package/export/pages/ExportPagesZipPages.d.ts +5 -0
- package/export/pages/ExportPagesZipPages.js +23 -0
- package/export/pages/ExportPagesZipPages.js.map +1 -0
- package/export/pages/controller/CombineZippedPages.d.ts +5 -0
- package/export/pages/controller/CombineZippedPages.js +75 -0
- package/export/pages/controller/CombineZippedPages.js.map +1 -0
- package/export/pages/controller/CreateZipPagesTasks.d.ts +8 -0
- package/export/pages/controller/CreateZipPagesTasks.js +103 -0
- package/export/pages/controller/CreateZipPagesTasks.js.map +1 -0
- package/export/pages/controller/ProcessZipPagesTasks.d.ts +6 -0
- package/export/pages/controller/ProcessZipPagesTasks.js +62 -0
- package/export/pages/controller/ProcessZipPagesTasks.js.map +1 -0
- package/export/pages/types.d.ts +53 -0
- package/export/pages/types.js +27 -0
- package/export/pages/types.js.map +1 -0
- package/export/pages/utils.d.ts +2 -0
- package/export/pages/utils.js +14 -0
- package/export/pages/utils.js.map +1 -0
- package/export/pages/zipPages/ZipPages.d.ts +5 -0
- package/export/pages/zipPages/ZipPages.js +100 -0
- package/export/pages/zipPages/ZipPages.js.map +1 -0
- package/export/pages/zipPages/ZipPagesDataManager.d.ts +14 -0
- package/export/pages/zipPages/ZipPagesDataManager.js +46 -0
- package/export/pages/zipPages/ZipPagesDataManager.js.map +1 -0
- package/export/pages/zipPages/getPageFactory.d.ts +4 -0
- package/export/pages/zipPages/getPageFactory.js +38 -0
- package/export/pages/zipPages/getPageFactory.js.map +1 -0
- package/export/process/exporters/PageExporter.d.ts +8 -1
- package/export/process/exporters/PageExporter.js.map +1 -1
- package/export/process/index.js +2 -2
- package/export/process/index.js.map +1 -1
- package/export/s3Stream.d.ts +2 -2
- package/export/s3Stream.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +0 -1
- package/graphql/crud/pages.crud.js +207 -123
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.js +3 -4
- package/graphql/graphql/blocks.gql.js.map +1 -1
- package/graphql/graphql/forms.gql.js +3 -4
- package/graphql/graphql/forms.gql.js.map +1 -1
- package/graphql/graphql/importExportTasks.gql.js +3 -4
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.js +100 -12
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.js +3 -4
- package/graphql/graphql/templates.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.d.ts +3 -3
- package/graphql/graphql/utils/resolve.js +14 -5
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +2 -1
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +53 -25
- package/graphql/types.js.map +1 -1
- package/import/create/index.js +2 -2
- package/import/create/index.js.map +1 -1
- package/import/pages/ImportPagesController.d.ts +5 -0
- package/import/pages/ImportPagesController.js +29 -0
- package/import/pages/ImportPagesController.js.map +1 -0
- package/import/pages/ImportPagesProcessPages.d.ts +6 -0
- package/import/pages/ImportPagesProcessPages.js +111 -0
- package/import/pages/ImportPagesProcessPages.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.d.ts +6 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js +40 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessZipFile.d.ts +5 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js +71 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js.map +1 -0
- package/import/{process/pages → pages/process}/importPage.d.ts +0 -1
- package/import/pages/process/importPage.js.map +1 -0
- package/import/pages/types.d.ts +48 -0
- package/import/pages/types.js +21 -0
- package/import/pages/types.js.map +1 -0
- package/import/process/index.js +2 -2
- package/import/process/index.js.map +1 -1
- package/import/utils/extractAndUploadZipFileContents.js +5 -2
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -1
- package/package.json +25 -23
- package/tasks/common/ChildTasksCleanup.d.ts +12 -0
- package/tasks/common/ChildTasksCleanup.js +64 -0
- package/tasks/common/ChildTasksCleanup.js.map +1 -0
- package/tasks/index.d.ts +1 -0
- package/tasks/index.js +13 -0
- package/tasks/index.js.map +1 -0
- package/tasks/pages/exportPagesCleanupTask.d.ts +3 -0
- package/tasks/pages/exportPagesCleanupTask.js +36 -0
- package/tasks/pages/exportPagesCleanupTask.js.map +1 -0
- package/tasks/pages/exportPagesControllerTask.d.ts +3 -0
- package/tasks/pages/exportPagesControllerTask.js +82 -0
- package/tasks/pages/exportPagesControllerTask.js.map +1 -0
- package/tasks/pages/exportPagesZipPagesTask.d.ts +3 -0
- package/tasks/pages/exportPagesZipPagesTask.js +39 -0
- package/tasks/pages/exportPagesZipPagesTask.js.map +1 -0
- package/tasks/pages/importPagesControllerTask.d.ts +3 -0
- package/tasks/pages/importPagesControllerTask.js +39 -0
- package/tasks/pages/importPagesControllerTask.js.map +1 -0
- package/tasks/pages/importPagesProcessPageTask.d.ts +3 -0
- package/tasks/pages/importPagesProcessPageTask.js +39 -0
- package/tasks/pages/importPagesProcessPageTask.js.map +1 -0
- package/tasks/pages/index.d.ts +1 -0
- package/tasks/pages/index.js +17 -0
- package/tasks/pages/index.js.map +1 -0
- package/utils/ZipFiles.d.ts +11 -0
- package/utils/ZipFiles.js +127 -0
- package/utils/ZipFiles.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +0 -6
- package/export/combine/pagesHandler.js +0 -101
- package/export/combine/pagesHandler.js.map +0 -1
- package/export/process/pagesHandler.d.ts +0 -6
- package/export/process/pagesHandler.js +0 -191
- package/export/process/pagesHandler.js.map +0 -1
- package/import/process/pages/importPage.js.map +0 -1
- package/import/process/pages/pagesHandler.d.ts +0 -3
- package/import/process/pages/pagesHandler.js +0 -185
- package/import/process/pages/pagesHandler.js.map +0 -1
- /package/import/{process/pages → pages/process}/importPage.js +0 -0
package/export/combine/index.js
CHANGED
@@ -7,7 +7,6 @@ exports.default = void 0;
|
|
7
7
|
var _handlerAws = require("@webiny/handler-aws");
|
8
8
|
var _blocksHandler = require("./blocksHandler");
|
9
9
|
var _formsHandler = require("./formsHandler");
|
10
|
-
var _pagesHandler = require("./pagesHandler");
|
11
10
|
var _templatesHandler = require("./templatesHandler");
|
12
11
|
/**
|
13
12
|
* Handles the export pages combine workflow.
|
@@ -33,7 +32,8 @@ var _default = () => {
|
|
33
32
|
}
|
34
33
|
default:
|
35
34
|
{
|
36
|
-
|
35
|
+
console.log("Export PB combine", JSON.stringify(payload));
|
36
|
+
throw new Error("Invalid type provided: pb combine.");
|
37
37
|
}
|
38
38
|
}
|
39
39
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_handlerAws","require","_blocksHandler","_formsHandler","
|
1
|
+
{"version":3,"names":["_handlerAws","require","_blocksHandler","_formsHandler","_templatesHandler","_default","createRawEventHandler","payload","context","security","withoutAuthorization","type","blocksHandler","formsHandler","templatesHandler","console","log","JSON","stringify","Error","exports","default"],"sources":["index.ts"],"sourcesContent":["import { PbImportExportContext } from \"~/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { blocksHandler } from \"~/export/combine/blocksHandler\";\nimport { formsHandler } from \"~/export/combine/formsHandler\";\nimport { templatesHandler } from \"~/export/combine/templatesHandler\";\n\nexport interface Payload {\n taskId: string;\n type: string;\n identity: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\n/**\n * Handles the export pages combine workflow.\n */\nexport default () => {\n return createRawEventHandler<Payload, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n return context.security.withoutAuthorization(() => {\n switch (payload.type) {\n case \"block\": {\n return blocksHandler(payload, context);\n }\n case \"form\": {\n return formsHandler(payload, context);\n }\n case \"template\": {\n return templatesHandler(payload, context);\n }\n default: {\n console.log(\"Export PB combine\", JSON.stringify(payload));\n throw new Error(\"Invalid type provided: pb combine.\");\n }\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAaA;AACA;AACA;AAFA,IAAAI,QAAA,GAGeA,CAAA,KAAM;EACjB,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5B,OAAOA,OAAO,CAACC,QAAQ,CAACC,oBAAoB,CAAC,MAAM;MAC/C,QAAQH,OAAO,CAACI,IAAI;QAChB,KAAK,OAAO;UAAE;YACV,OAAO,IAAAC,4BAAa,EAACL,OAAO,EAAEC,OAAO,CAAC;UAC1C;QACA,KAAK,MAAM;UAAE;YACT,OAAO,IAAAK,0BAAY,EAACN,OAAO,EAAEC,OAAO,CAAC;UACzC;QACA,KAAK,UAAU;UAAE;YACb,OAAO,IAAAM,kCAAgB,EAACP,OAAO,EAAEC,OAAO,CAAC;UAC7C;QACA;UAAS;YACLO,OAAO,CAACC,GAAG,CAAC,mBAAmB,EAAEC,IAAI,CAACC,SAAS,CAACX,OAAO,CAAC,CAAC;YACzD,MAAM,IAAIY,KAAK,CAAC,oCAAoC,CAAC;UACzD;MACJ;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAhB,QAAA"}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.ExportPagesCleanup = void 0;
|
8
|
+
var _types = require("./types");
|
9
|
+
var _clientS = require("@webiny/aws-sdk/client-s3");
|
10
|
+
var _chunk = _interopRequireDefault(require("lodash/chunk"));
|
11
|
+
class ExportPagesCleanup {
|
12
|
+
async execute(params) {
|
13
|
+
const {
|
14
|
+
context,
|
15
|
+
response,
|
16
|
+
store
|
17
|
+
} = params;
|
18
|
+
/**
|
19
|
+
* This task must have a parent one. If it does not, just end with error.
|
20
|
+
* This should not happen as we trigger this task from a parent one, not directly.
|
21
|
+
*
|
22
|
+
* But let's just make sure.
|
23
|
+
*/
|
24
|
+
const task = store.getTask();
|
25
|
+
if (!task.parentId) {
|
26
|
+
return response.error(`Missing task "${task.id}" parent id.`);
|
27
|
+
}
|
28
|
+
const parent = await context.tasks.getTask(task.parentId);
|
29
|
+
if (!parent) {
|
30
|
+
return response.error(`Missing parent task "${task.parentId}" in the database.`);
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* We need to find all the tasks that created zip files, so we can have a list of files to delete.
|
34
|
+
*/
|
35
|
+
const {
|
36
|
+
items: subTasks
|
37
|
+
} = await context.tasks.listTasks({
|
38
|
+
where: {
|
39
|
+
parentId: parent.id,
|
40
|
+
definitionId: _types.PageExportTask.ZipPages
|
41
|
+
},
|
42
|
+
limit: 10000
|
43
|
+
});
|
44
|
+
if (subTasks.length === 0) {
|
45
|
+
return response.done("No subtasks found - nothing to cleanup.");
|
46
|
+
}
|
47
|
+
const files = subTasks.reduce((collection, subTask) => {
|
48
|
+
const done = subTask.output?.done;
|
49
|
+
if (!done) {
|
50
|
+
return collection;
|
51
|
+
}
|
52
|
+
const results = Object.values(done).filter(Boolean);
|
53
|
+
collection.push(...results);
|
54
|
+
return collection;
|
55
|
+
}, []);
|
56
|
+
const s3 = (0, _clientS.createS3Client)({
|
57
|
+
region: process.env.AWS_REGION
|
58
|
+
});
|
59
|
+
const parentKey = parent.output?.key;
|
60
|
+
if (typeof parentKey === "string") {
|
61
|
+
await s3.deleteObject({
|
62
|
+
Bucket: process.env.S3_BUCKET,
|
63
|
+
Key: parentKey
|
64
|
+
});
|
65
|
+
}
|
66
|
+
const chunks = (0, _chunk.default)(files, 500);
|
67
|
+
for (const chunk of chunks) {
|
68
|
+
await s3.deleteObjects({
|
69
|
+
Bucket: process.env.S3_BUCKET,
|
70
|
+
Delete: {
|
71
|
+
Objects: chunk.map(Key => ({
|
72
|
+
Key
|
73
|
+
}))
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}
|
77
|
+
return response.done("Done with cleanup!");
|
78
|
+
}
|
79
|
+
}
|
80
|
+
exports.ExportPagesCleanup = ExportPagesCleanup;
|
81
|
+
|
82
|
+
//# sourceMappingURL=ExportPagesCleanup.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_types","require","_clientS","_chunk","_interopRequireDefault","ExportPagesCleanup","execute","params","context","response","store","task","getTask","parentId","error","id","parent","tasks","items","subTasks","listTasks","where","definitionId","PageExportTask","ZipPages","limit","length","done","files","reduce","collection","subTask","output","results","Object","values","filter","Boolean","push","s3","createS3Client","region","process","env","AWS_REGION","parentKey","key","deleteObject","Bucket","S3_BUCKET","Key","chunks","lodashChunk","chunk","deleteObjects","Delete","Objects","map","exports"],"sources":["ExportPagesCleanup.ts"],"sourcesContent":["import {\n IExportPagesCleanupTaskParams,\n IExportPagesControllerOutput,\n IExportPagesZipPagesOutput,\n PageExportTask\n} from \"~/export/pages/types\";\nimport { ITaskResponseResult } from \"@webiny/tasks\";\nimport { createS3Client } from \"@webiny/aws-sdk/client-s3\";\nimport lodashChunk from \"lodash/chunk\";\n\nexport class ExportPagesCleanup {\n public async execute(params: IExportPagesCleanupTaskParams): Promise<ITaskResponseResult> {\n const { context, response, store } = params;\n /**\n * This task must have a parent one. If it does not, just end with error.\n * This should not happen as we trigger this task from a parent one, not directly.\n *\n * But let's just make sure.\n */\n const task = store.getTask();\n if (!task.parentId) {\n return response.error(`Missing task \"${task.id}\" parent id.`);\n }\n\n const parent = await context.tasks.getTask<IExportPagesControllerOutput>(task.parentId);\n if (!parent) {\n return response.error(`Missing parent task \"${task.parentId}\" in the database.`);\n }\n /**\n * We need to find all the tasks that created zip files, so we can have a list of files to delete.\n */\n const { items: subTasks } = await context.tasks.listTasks<any, IExportPagesZipPagesOutput>({\n where: {\n parentId: parent.id,\n definitionId: PageExportTask.ZipPages\n },\n limit: 10000\n });\n if (subTasks.length === 0) {\n return response.done(\"No subtasks found - nothing to cleanup.\");\n }\n\n const files = subTasks.reduce<string[]>((collection, subTask) => {\n const done = subTask.output?.done;\n if (!done) {\n return collection;\n }\n const results = Object.values(done).filter(Boolean);\n collection.push(...results);\n return collection;\n }, []);\n\n const s3 = createS3Client({\n region: process.env.AWS_REGION\n });\n\n const parentKey = parent.output?.key;\n if (typeof parentKey === \"string\") {\n await s3.deleteObject({\n Bucket: process.env.S3_BUCKET,\n Key: parentKey\n });\n }\n\n const chunks = lodashChunk(files, 500);\n\n for (const chunk of chunks) {\n await s3.deleteObjects({\n Bucket: process.env.S3_BUCKET,\n Delete: {\n Objects: chunk.map(Key => ({ Key }))\n }\n });\n }\n\n return response.done(\"Done with cleanup!\");\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEO,MAAMI,kBAAkB,CAAC;EAC5B,MAAaC,OAAOA,CAACC,MAAqC,EAAgC;IACtF,MAAM;MAAEC,OAAO;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGH,MAAM;IAC3C;AACR;AACA;AACA;AACA;AACA;IACQ,MAAMI,IAAI,GAAGD,KAAK,CAACE,OAAO,CAAC,CAAC;IAC5B,IAAI,CAACD,IAAI,CAACE,QAAQ,EAAE;MAChB,OAAOJ,Q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AAQ,EAAE;MAC/B,MAAMN,EAAE,CAACQ,YAAY,CAAC;QAClBC,MAAM,EAAEN,OAAO,CAACC,GAAG,CAACM,SAAS;QAC7BC,GAAG,EAAEL;MACT,CAAC,CAAC;IACN;IAEA,MAAMM,MAAM,GAAG,IAAAC,cAAW,EAACxB,KAAK,EAAE,GAAG,CAAC;IAEtC,KAAK,MAAMyB,KAAK,IAAIF,MAAM,EAAE;MACxB,MAAMZ,EAAE,CAACe,aAAa,CAAC;QACnBN,MAAM,EAAEN,OAAO,CAACC,GAAG,CAACM,SAAS;QAC7BM,MAAM,EAAE;UACJC,OAAO,EAAEH,KAAK,CAACI,GAAG,CAACP,GAAG,KAAK;YAAEA;UAAI,CAAC,CAAC;QACvC;MACJ,CAAC,CAAC;IACN;IAEA,OAAOzC,QAAQ,CAACkB,IAAI,CAAC,oBAAoB,CAAC;EAC9C;AACJ;AAAC+B,OAAA,CAAArD,kBAAA,GAAAA,kBAAA"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ExportPagesController = void 0;
|
7
|
+
var _ProcessZipPagesTasks = require("./controller/ProcessZipPagesTasks");
|
8
|
+
var _CreateZipPagesTasks = require("./controller/CreateZipPagesTasks");
|
9
|
+
class ExportPagesController {
|
10
|
+
async execute(params) {
|
11
|
+
const {
|
12
|
+
input
|
13
|
+
} = params;
|
14
|
+
/**
|
15
|
+
* In case subtasks for zipping pages are already created, we need to wait for them to finish.
|
16
|
+
* After they are done, we can combine all zip files into a single one.
|
17
|
+
*/
|
18
|
+
if (input.zippingPages) {
|
19
|
+
const processZipPagesTasks = new _ProcessZipPagesTasks.ProcessZipPagesTasks();
|
20
|
+
return await processZipPagesTasks.execute(params);
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* On the first run of the task, we need to create subtasks for zipping pages in batches.
|
24
|
+
*/
|
25
|
+
const createZipPagesTasks = new _CreateZipPagesTasks.CreateZipPagesTasks();
|
26
|
+
return await createZipPagesTasks.execute(params);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.ExportPagesController = ExportPagesController;
|
30
|
+
|
31
|
+
//# sourceMappingURL=ExportPagesController.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_ProcessZipPagesTasks","require","_CreateZipPagesTasks","ExportPagesController","execute","params","input","zippingPages","processZipPagesTasks","ProcessZipPagesTasks","createZipPagesTasks","CreateZipPagesTasks","exports"],"sources":["ExportPagesController.ts"],"sourcesContent":["import { IExportPagesControllerTaskParams } from \"./types\";\nimport { ITaskResponseResult } from \"@webiny/tasks\";\nimport { ProcessZipPagesTasks } from \"./controller/ProcessZipPagesTasks\";\nimport { CreateZipPagesTasks } from \"./controller/CreateZipPagesTasks\";\n\nexport class ExportPagesController {\n public async execute(params: IExportPagesControllerTaskParams): Promise<ITaskResponseResult> {\n const { input } = params;\n /**\n * In case subtasks for zipping pages are already created, we need to wait for them to finish.\n * After they are done, we can combine all zip files into a single one.\n */\n if (input.zippingPages) {\n const processZipPagesTasks = new ProcessZipPagesTasks();\n return await processZipPagesTasks.execute(params);\n }\n /**\n * On the first run of the task, we need to create subtasks for zipping pages in batches.\n */\n const createZipPagesTasks = new CreateZipPagesTasks();\n return await createZipPagesTasks.execute(params);\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAEO,MAAME,qBAAqB,CAAC;EAC/B,MAAaC,OAAOA,CAACC,MAAwC,EAAgC;IACzF,MAAM;MAAEC;IAAM,CAAC,GAAGD,MAAM;IACxB;AACR;AACA;AACA;IACQ,IAAIC,KAAK,CAACC,YAAY,EAAE;MACpB,MAAMC,oBAAoB,GAAG,IAAIC,0CAAoB,CAAC,CAAC;MACvD,OAAO,MAAMD,oBAAoB,CAACJ,OAAO,CAACC,MAAM,CAAC;IACrD;IACA;AACR;AACA;IACQ,MAAMK,mBAAmB,GAAG,IAAIC,wCAAmB,CAAC,CAAC;IACrD,OAAO,MAAMD,mBAAmB,CAACN,OAAO,CAACC,MAAM,CAAC;EACpD;AACJ;AAACO,OAAA,CAAAT,qBAAA,GAAAA,qBAAA"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ExportPagesZipPages = void 0;
|
7
|
+
var _ZipPages = require("./zipPages/ZipPages");
|
8
|
+
class ExportPagesZipPages {
|
9
|
+
async execute(params) {
|
10
|
+
const {
|
11
|
+
isAborted,
|
12
|
+
response
|
13
|
+
} = params;
|
14
|
+
if (isAborted()) {
|
15
|
+
return response.aborted();
|
16
|
+
}
|
17
|
+
const zipPages = new _ZipPages.ZipPages();
|
18
|
+
return await zipPages.execute(params);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
exports.ExportPagesZipPages = ExportPagesZipPages;
|
22
|
+
|
23
|
+
//# sourceMappingURL=ExportPagesZipPages.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_ZipPages","require","ExportPagesZipPages","execute","params","isAborted","response","aborted","zipPages","ZipPages","exports"],"sources":["ExportPagesZipPages.ts"],"sourcesContent":["import { IExportPagesZipPagesTaskParams } from \"~/export/pages/types\";\nimport { ITaskResponseResult } from \"@webiny/tasks\";\nimport { ZipPages } from \"./zipPages/ZipPages\";\n\nexport class ExportPagesZipPages {\n public async execute(params: IExportPagesZipPagesTaskParams): Promise<ITaskResponseResult> {\n const { isAborted, response } = params;\n if (isAborted()) {\n return response.aborted();\n }\n\n const zipPages = new ZipPages();\n return await zipPages.execute(params);\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,mBAAmB,CAAC;EAC7B,MAAaC,OAAOA,CAACC,MAAsC,EAAgC;IACvF,MAAM;MAAEC,SAAS;MAAEC;IAAS,CAAC,GAAGF,MAAM;IACtC,IAAIC,SAAS,CAAC,CAAC,EAAE;MACb,OAAOC,QAAQ,CAACC,OAAO,CAAC,CAAC;IAC7B;IAEA,MAAMC,QAAQ,GAAG,IAAIC,kBAAQ,CAAC,CAAC;IAC/B,OAAO,MAAMD,QAAQ,CAACL,OAAO,CAACC,MAAM,CAAC;EACzC;AACJ;AAACM,OAAA,CAAAR,mBAAA,GAAAA,mBAAA"}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.CombineZippedPages = void 0;
|
8
|
+
var _s3Stream = require("../../s3Stream");
|
9
|
+
var _utils = require("../utils");
|
10
|
+
var _ZipFiles = require("../../../utils/ZipFiles");
|
11
|
+
var _uniqid = _interopRequireDefault(require("uniqid"));
|
12
|
+
class CombineZippedPages {
|
13
|
+
async execute(params) {
|
14
|
+
const {
|
15
|
+
response,
|
16
|
+
store
|
17
|
+
} = params;
|
18
|
+
/**
|
19
|
+
* We need to get all the subtasks of the PageExportTask.ZipPages type, so we can get all the zip files and combine them into one.
|
20
|
+
* Current task must have a parent for this to work.
|
21
|
+
*/
|
22
|
+
const taskId = store.getTask().id;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* When we have all the pages IDs and their zip files, we can continue to combine the zip files into one.
|
26
|
+
*/
|
27
|
+
const exportPagesDataKey = (0, _utils.createExportPagesDataKey)(taskId);
|
28
|
+
let listObjectResponse;
|
29
|
+
try {
|
30
|
+
listObjectResponse = await _s3Stream.s3Stream.listObject(exportPagesDataKey);
|
31
|
+
if (!Array.isArray(listObjectResponse.Contents)) {
|
32
|
+
return response.error({
|
33
|
+
message: "There is no Contents defined on S3 Stream while combining pages."
|
34
|
+
});
|
35
|
+
} else if (listObjectResponse.Contents.length === 0) {
|
36
|
+
return response.done("No zip files to combine.");
|
37
|
+
}
|
38
|
+
} catch (ex) {
|
39
|
+
return response.error(ex);
|
40
|
+
}
|
41
|
+
const zipFileKeys = listObjectResponse.Contents.reduce((files, file) => {
|
42
|
+
if (!file.Key) {
|
43
|
+
return files;
|
44
|
+
} else if (file.Key === exportPagesDataKey) {
|
45
|
+
return files;
|
46
|
+
}
|
47
|
+
files.push(file.Key);
|
48
|
+
return files;
|
49
|
+
}, []);
|
50
|
+
let key;
|
51
|
+
try {
|
52
|
+
const zipOfZip = new _ZipFiles.ZipFiles();
|
53
|
+
const target = (0, _uniqid.default)("EXPORTS/", "-WEBINY_PAGE_EXPORT.zip");
|
54
|
+
const pageExportUpload = await zipOfZip.process(target, zipFileKeys);
|
55
|
+
if (!pageExportUpload?.Key) {
|
56
|
+
return response.error({
|
57
|
+
message: "There is no Key defined on pageExportUpload."
|
58
|
+
});
|
59
|
+
}
|
60
|
+
key = pageExportUpload.Key;
|
61
|
+
} catch (ex) {
|
62
|
+
console.error(`Error while combining zip files into a single zip: ${ex.message}`);
|
63
|
+
console.log(ex);
|
64
|
+
return response.error(ex);
|
65
|
+
}
|
66
|
+
const url = await _s3Stream.s3Stream.getPresignedUrl(key);
|
67
|
+
return response.done("Done combining pages.", {
|
68
|
+
key,
|
69
|
+
url
|
70
|
+
});
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.CombineZippedPages = CombineZippedPages;
|
74
|
+
|
75
|
+
//# sourceMappingURL=CombineZippedPages.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_s3Stream","require","_utils","_ZipFiles","_uniqid","_interopRequireDefault","CombineZippedPages","execute","params","response","store","taskId","getTask","id","exportPagesDataKey","createExportPagesDataKey","listObjectResponse","s3Stream","listObject","Array","isArray","Contents","error","message","length","done","ex","zipFileKeys","reduce","files","file","Key","push","key","zipOfZip","ZipFiles","target","uniqueId","pageExportUpload","process","console","log","url","getPresignedUrl","exports"],"sources":["CombineZippedPages.ts"],"sourcesContent":["import { IExportPagesCombineZippedPagesParams } from \"~/export/pages/types\";\nimport { ITaskResponseResult } from \"@webiny/tasks\";\nimport { ListObjectsOutput, s3Stream } from \"~/export/s3Stream\";\nimport { createExportPagesDataKey } from \"~/export/pages/utils\";\nimport { ZipFiles } from \"~/utils/ZipFiles\";\nimport uniqueId from \"uniqid\";\n\nexport class CombineZippedPages {\n public async execute(\n params: IExportPagesCombineZippedPagesParams\n ): Promise<ITaskResponseResult> {\n const { response, store } = params;\n /**\n * We need to get all the subtasks of the PageExportTask.ZipPages type, so we can get all the zip files and combine them into one.\n * Current task must have a parent for this to work.\n */\n const taskId = store.getTask().id;\n\n /**\n * When we have all the pages IDs and their zip files, we can continue to combine the zip files into one.\n */\n const exportPagesDataKey = createExportPagesDataKey(taskId);\n\n let listObjectResponse: ListObjectsOutput;\n try {\n listObjectResponse = await s3Stream.listObject(exportPagesDataKey);\n if (!Array.isArray(listObjectResponse.Contents)) {\n return response.error({\n message: \"There is no Contents defined on S3 Stream while combining pages.\"\n });\n } else if (listObjectResponse.Contents.length === 0) {\n return response.done(\"No zip files to combine.\");\n }\n } catch (ex) {\n return response.error(ex);\n }\n\n const zipFileKeys = listObjectResponse.Contents.reduce<string[]>((files, file) => {\n if (!file.Key) {\n return files;\n } else if (file.Key === exportPagesDataKey) {\n return files;\n }\n files.push(file.Key);\n\n return files;\n }, []);\n\n let key: string;\n\n try {\n const zipOfZip = new ZipFiles();\n const target = uniqueId(\"EXPORTS/\", \"-WEBINY_PAGE_EXPORT.zip\");\n const pageExportUpload = await zipOfZip.process(target, zipFileKeys);\n\n if (!pageExportUpload?.Key) {\n return response.error({\n message: \"There is no Key defined on pageExportUpload.\"\n });\n }\n key = pageExportUpload.Key;\n } catch (ex) {\n console.error(`Error while combining zip files into a single zip: ${ex.message}`);\n console.log(ex);\n return response.error(ex);\n }\n\n const url = await s3Stream.getPresignedUrl(key);\n\n return response.done(\"Done combining pages.\", {\n key,\n url\n });\n }\n}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AAI,CAACC,GAAG,CAAC;MAEpB,OAAOF,KAAK;IAChB,CAAC,EAAE,EAAE,CAAC;IAEN,IAAII,GAAW;IAEf,IAAI;MACA,MAAMC,QAAQ,GAAG,IAAIC,kBAAQ,CAAC,CAAC;MAC/B,MAAMC,MAAM,GAAG,IAAAC,eAAQ,EAAC,UAAU,EAAE,yBAAyB,CAAC;MAC9D,MAAMC,gBAAgB,GAAG,MAAMJ,QAAQ,CAACK,OAAO,CAACH,MAAM,EAAET,WAAW,CAAC;MAEpE,IAAI,CAACW,gBAAgB,EAAEP,GAAG,EAAE;QACxB,OAAOtB,QAAQ,CAACa,KAAK,CAAC;UAClBC,OAAO,EAAE;QACb,CAAC,CAAC;MACN;MACAU,GAAG,GAAGK,gBAAgB,CAACP,GAAG;IAC9B,CAAC,CAAC,OAAOL,EAAE,EAAE;MACTc,OAAO,CAAClB,KAAK,CAAE,sDAAqDI,EAAE,CAACH,OAAQ,EAAC,CAAC;MACjFiB,OAAO,CAACC,GAAG,CAACf,EAAE,CAAC;MACf,OAAOjB,QAAQ,CAACa,KAAK,CAACI,EAAE,CAAC;IAC7B;IAEA,MAAMgB,GAAG,GAAG,MAAMzB,kBAAQ,CAAC0B,eAAe,CAACV,GAAG,CAAC;IAE/C,OAAOxB,QAAQ,CAACgB,IAAI,CAAC,uBAAuB,EAAE;MAC1CQ,GAAG;MACHS;IACJ,CAAC,CAAC;EACN;AACJ;AAACE,OAAA,CAAAtC,kBAAA,GAAAA,kBAAA"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { IExportPagesControllerTaskParams } from "../types";
|
2
|
+
import { ITaskResponseResult } from "@webiny/tasks/types";
|
3
|
+
/**
|
4
|
+
* Go through all the pages and create subtasks for zipping pages in batches.
|
5
|
+
*/
|
6
|
+
export declare class CreateZipPagesTasks {
|
7
|
+
execute({ response, input, isAborted, isCloseToTimeout, context, store }: IExportPagesControllerTaskParams): Promise<ITaskResponseResult>;
|
8
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.CreateZipPagesTasks = void 0;
|
7
|
+
var _ProcessZipPagesTasks = require("./ProcessZipPagesTasks");
|
8
|
+
var _types = require("../types");
|
9
|
+
const PAGES_IN_BATCH = 25;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Go through all the pages and create subtasks for zipping pages in batches.
|
13
|
+
*/
|
14
|
+
class CreateZipPagesTasks {
|
15
|
+
async execute({
|
16
|
+
response,
|
17
|
+
input,
|
18
|
+
isAborted,
|
19
|
+
isCloseToTimeout,
|
20
|
+
context,
|
21
|
+
store
|
22
|
+
}) {
|
23
|
+
const listPagesParams = {
|
24
|
+
where: input.where,
|
25
|
+
after: input.after,
|
26
|
+
limit: PAGES_IN_BATCH
|
27
|
+
};
|
28
|
+
let currentBatch = input.currentBatch || 1;
|
29
|
+
let result;
|
30
|
+
while (result = await context.pageBuilder.listLatestPages(listPagesParams)) {
|
31
|
+
if (isAborted()) {
|
32
|
+
return response.aborted();
|
33
|
+
} else if (isCloseToTimeout()) {
|
34
|
+
return response.continue({
|
35
|
+
...input,
|
36
|
+
...listPagesParams,
|
37
|
+
currentBatch
|
38
|
+
});
|
39
|
+
}
|
40
|
+
const [pages, meta] = result;
|
41
|
+
listPagesParams.after = meta.cursor;
|
42
|
+
/**
|
43
|
+
* If no pages are returned there are two options:
|
44
|
+
* * mark task as done because there are no pages at all
|
45
|
+
* * continue with the control task, but in zippingPages mode
|
46
|
+
*/
|
47
|
+
if (meta.totalCount === 0) {
|
48
|
+
return response.done("No pages to export.");
|
49
|
+
} else if (pages.length === 0) {
|
50
|
+
return response.continue({
|
51
|
+
...input,
|
52
|
+
...listPagesParams,
|
53
|
+
currentBatch,
|
54
|
+
totalPages: meta.totalCount,
|
55
|
+
zippingPages: true
|
56
|
+
}, {
|
57
|
+
seconds: _ProcessZipPagesTasks.ZIP_PAGES_WAIT_TIME
|
58
|
+
});
|
59
|
+
}
|
60
|
+
const queue = pages.map(page => page.id);
|
61
|
+
/**
|
62
|
+
* Trigger a task for each of the loaded pages batch.
|
63
|
+
*/
|
64
|
+
await context.tasks.trigger({
|
65
|
+
name: `Page Builder - Export Pages - Zip Pages #${currentBatch}`,
|
66
|
+
parent: store.getTask(),
|
67
|
+
definition: _types.PageExportTask.ZipPages,
|
68
|
+
input: {
|
69
|
+
queue,
|
70
|
+
type: input.type
|
71
|
+
}
|
72
|
+
});
|
73
|
+
/**
|
74
|
+
* If there are no more pages to load, we can continue the controller task in a zippingPages mode, with some delay.
|
75
|
+
*/
|
76
|
+
if (!meta.hasMoreItems || !meta.cursor) {
|
77
|
+
return response.continue({
|
78
|
+
...input,
|
79
|
+
...listPagesParams,
|
80
|
+
currentBatch,
|
81
|
+
totalPages: meta.totalCount,
|
82
|
+
zippingPages: true
|
83
|
+
}, {
|
84
|
+
seconds: _ProcessZipPagesTasks.ZIP_PAGES_WAIT_TIME
|
85
|
+
});
|
86
|
+
}
|
87
|
+
currentBatch++;
|
88
|
+
}
|
89
|
+
/**
|
90
|
+
* Should not be possible to exit the loop without returning a response, but let's have a continue response here just in case.
|
91
|
+
*/
|
92
|
+
return response.continue({
|
93
|
+
...input,
|
94
|
+
...listPagesParams,
|
95
|
+
currentBatch
|
96
|
+
}, {
|
97
|
+
seconds: _ProcessZipPagesTasks.ZIP_PAGES_WAIT_TIME
|
98
|
+
});
|
99
|
+
}
|
100
|
+
}
|
101
|
+
exports.CreateZipPagesTasks = CreateZipPagesTasks;
|
102
|
+
|
103
|
+
//# sourceMappingURL=CreateZipPagesTasks.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_ProcessZipPagesTasks","require","_types","PAGES_IN_BATCH","CreateZipPagesTasks","execute","response","input","isAborted","isCloseToTimeout","context","store","listPagesParams","where","after","limit","currentBatch","result","pageBuilder","listLatestPages","aborted","continue","pages","meta","cursor","totalCount","done","length","totalPages","zippingPages","seconds","ZIP_PAGES_WAIT_TIME","queue","map","page","id","tasks","trigger","name","parent","getTask","definition","PageExportTask","ZipPages","type","hasMoreItems","exports"],"sources":["CreateZipPagesTasks.ts"],"sourcesContent":["import { ListMeta, ListPagesParams, Page } from \"@webiny/api-page-builder/types\";\nimport { ZIP_PAGES_WAIT_TIME } from \"./ProcessZipPagesTasks\";\nimport {\n IExportPagesControllerTaskParams,\n IExportPagesZipPagesInput,\n PageExportTask\n} from \"~/export/pages/types\";\nimport { ITaskResponseResult } from \"@webiny/tasks/types\";\n\nconst PAGES_IN_BATCH = 25;\n\n/**\n * Go through all the pages and create subtasks for zipping pages in batches.\n */\nexport class CreateZipPagesTasks {\n public async execute({\n response,\n input,\n isAborted,\n isCloseToTimeout,\n context,\n store\n }: IExportPagesControllerTaskParams): Promise<ITaskResponseResult> {\n const listPagesParams: ListPagesParams = {\n where: input.where,\n after: input.after,\n limit: PAGES_IN_BATCH\n };\n\n let currentBatch = input.currentBatch || 1;\n let result: [Page[], ListMeta];\n while ((result = await context.pageBuilder.listLatestPages(listPagesParams))) {\n if (isAborted()) {\n return response.aborted();\n } else if (isCloseToTimeout()) {\n return response.continue({\n ...input,\n ...listPagesParams,\n currentBatch\n });\n }\n const [pages, meta] = result;\n\n listPagesParams.after = meta.cursor;\n /**\n * If no pages are returned there are two options:\n * * mark task as done because there are no pages at all\n * * continue with the control task, but in zippingPages mode\n */\n if (meta.totalCount === 0) {\n return response.done(\"No pages to export.\");\n } else if (pages.length === 0) {\n return response.continue(\n {\n ...input,\n ...listPagesParams,\n currentBatch,\n totalPages: meta.totalCount,\n zippingPages: true\n },\n {\n seconds: ZIP_PAGES_WAIT_TIME\n }\n );\n }\n\n const queue = pages.map(page => page.id);\n /**\n * Trigger a task for each of the loaded pages batch.\n */\n await context.tasks.trigger<IExportPagesZipPagesInput>({\n name: `Page Builder - Export Pages - Zip Pages #${currentBatch}`,\n parent: store.getTask(),\n definition: PageExportTask.ZipPages,\n input: {\n queue,\n type: input.type\n }\n });\n /**\n * If there are no more pages to load, we can continue the controller task in a zippingPages mode, with some delay.\n */\n if (!meta.hasMoreItems || !meta.cursor) {\n return response.continue(\n {\n ...input,\n ...listPagesParams,\n currentBatch,\n totalPages: meta.totalCount,\n zippingPages: true\n },\n {\n seconds: ZIP_PAGES_WAIT_TIME\n }\n );\n }\n currentBatch++;\n }\n /**\n * Should not be possible to exit the loop without returning a response, but let's have a continue response here just in case.\n */\n return response.continue(\n {\n ...input,\n ...listPagesParams,\n currentBatch\n },\n {\n seconds: ZIP_PAGES_WAIT_TIME\n }\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAOA,MAAME,cAAc,GAAG,EAAE;;AAEzB;AACA;AACA;AACO,MAAMC,mBAAmB,CAAC;EAC7B,MAAaC,OAAOA,CAAC;IACjBC,QAAQ;IACRC,KAAK;IACLC,SAAS;IACTC,gBAAgB;IAChBC,OAAO;IACPC;EAC8B,CAAC,EAAgC;IAC/D,MAAMC,eAAgC,GAAG;MACrCC,KAAK,EAAEN,KAAK,CAACM,KAAK;MAClBC,KAAK,EAAEP,KAAK,CAACO,KAAK;MAClBC,KAAK,EAAEZ;IACX,CAAC;IAED,IAAIa,YAAY,GAAGT,KAAK,CAACS,YAAY,IAAI,CAAC;IAC1C,IAAIC,MAA0B;IAC9B,OAAQA,MAAM,GAAG,MAAMP,OAAO,CAACQ,WAAW,CAACC,eAAe,CAACP,eAAe,CAAC,EAAG;MAC1E,IAAIJ,SAAS,CAAC,CAAC,EAAE;QACb,OAAOF,QAAQ,CAACc,OAAO,CAAC,CAAC;MAC7B,CAAC,MAAM,IAAIX,gBAAgB,CAAC,CAAC,EAAE;QAC3B,OAAOH,QAAQ,CAACe,QAAQ,CAAC;UACrB,GAAGd,KAAK;UACR,GAAGK,eAAe;UAClBI;QACJ,CAAC,CAAC;MACN;MACA,MAAM,CAACM,KAAK,EAAEC,IAA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;MACI,GAAGd,KAAK;MACR,GAAGK,eAAe;MAClBI;IACJ,CAAC,EACD;MACIc,OAAO,EAAEC;IACb,CACJ,CAAC;EACL;AACJ;AAACe,OAAA,CAAA1C,mBAAA,GAAAA,mBAAA"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { ITaskResponseResult } from "@webiny/tasks";
|
2
|
+
import { IExportPagesControllerTaskParams } from "../types";
|
3
|
+
export declare const ZIP_PAGES_WAIT_TIME = 5;
|
4
|
+
export declare class ProcessZipPagesTasks {
|
5
|
+
execute(params: IExportPagesControllerTaskParams): Promise<ITaskResponseResult>;
|
6
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ZIP_PAGES_WAIT_TIME = exports.ProcessZipPagesTasks = void 0;
|
7
|
+
var _tasks = require("@webiny/tasks");
|
8
|
+
var _types = require("../types");
|
9
|
+
var _CombineZippedPages = require("./CombineZippedPages");
|
10
|
+
const ZIP_PAGES_WAIT_TIME = 5;
|
11
|
+
exports.ZIP_PAGES_WAIT_TIME = ZIP_PAGES_WAIT_TIME;
|
12
|
+
class ProcessZipPagesTasks {
|
13
|
+
async execute(params) {
|
14
|
+
const {
|
15
|
+
response,
|
16
|
+
input,
|
17
|
+
isAborted,
|
18
|
+
isCloseToTimeout,
|
19
|
+
context,
|
20
|
+
store
|
21
|
+
} = params;
|
22
|
+
if (isAborted()) {
|
23
|
+
return response.aborted();
|
24
|
+
} else if (isCloseToTimeout()) {
|
25
|
+
return response.continue({
|
26
|
+
...input
|
27
|
+
});
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* TODO: implement subtasks and subtask management into the base tasks package.
|
31
|
+
*/
|
32
|
+
const result = await context.tasks.listTasks({
|
33
|
+
where: {
|
34
|
+
parentId: store.getTask().id,
|
35
|
+
definitionId: _types.PageExportTask.ZipPages,
|
36
|
+
taskStatus_in: [_tasks.TaskDataStatus.RUNNING, _tasks.TaskDataStatus.PENDING]
|
37
|
+
},
|
38
|
+
limit: 1
|
39
|
+
});
|
40
|
+
/**
|
41
|
+
* Do we still need to wait until all subtasks (Zip Pages) are done?
|
42
|
+
*/
|
43
|
+
if (result.items.length > 0) {
|
44
|
+
return response.continue({
|
45
|
+
...input
|
46
|
+
}, {
|
47
|
+
seconds: ZIP_PAGES_WAIT_TIME
|
48
|
+
});
|
49
|
+
}
|
50
|
+
/**
|
51
|
+
* If all subtasks (Zip Pages) are done, we can continue with zipping all zip files into a single one.
|
52
|
+
*/
|
53
|
+
const combineZippedPages = new _CombineZippedPages.CombineZippedPages();
|
54
|
+
return combineZippedPages.execute({
|
55
|
+
store,
|
56
|
+
response
|
57
|
+
});
|
58
|
+
}
|
59
|
+
}
|
60
|
+
exports.ProcessZipPagesTasks = ProcessZipPagesTasks;
|
61
|
+
|
62
|
+
//# sourceMappingURL=ProcessZipPagesTasks.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_tasks","require","_types","_CombineZippedPages","ZIP_PAGES_WAIT_TIME","exports","ProcessZipPagesTasks","execute","params","response","input","isAborted","isCloseToTimeout","context","store","aborted","continue","result","tasks","listTasks","where","parentId","getTask","id","definitionId","PageExportTask","ZipPages","taskStatus_in","TaskDataStatus","RUNNING","PENDING","limit","items","length","seconds","combineZippedPages","CombineZippedPages"],"sources":["ProcessZipPagesTasks.ts"],"sourcesContent":["import { ITaskResponseResult, TaskDataStatus } from \"@webiny/tasks\";\nimport { IExportPagesControllerTaskParams, PageExportTask } from \"../types\";\nimport { CombineZippedPages } from \"~/export/pages/controller/CombineZippedPages\";\n\nexport const ZIP_PAGES_WAIT_TIME = 5;\n\nexport class ProcessZipPagesTasks {\n public async execute(params: IExportPagesControllerTaskParams): Promise<ITaskResponseResult> {\n const { response, input, isAborted, isCloseToTimeout, context, store } = params;\n\n if (isAborted()) {\n return response.aborted();\n } else if (isCloseToTimeout()) {\n return response.continue({\n ...input\n });\n }\n /**\n * TODO: implement subtasks and subtask management into the base tasks package.\n */\n const result = await context.tasks.listTasks({\n where: {\n parentId: store.getTask().id,\n definitionId: PageExportTask.ZipPages,\n taskStatus_in: [TaskDataStatus.RUNNING, TaskDataStatus.PENDING]\n },\n limit: 1\n });\n /**\n * Do we still need to wait until all subtasks (Zip Pages) are done?\n */\n if (result.items.length > 0) {\n return response.continue(\n {\n ...input\n },\n {\n seconds: ZIP_PAGES_WAIT_TIME\n }\n );\n }\n /**\n * If all subtasks (Zip Pages) are done, we can continue with zipping all zip files into a single one.\n */\n const combineZippedPages = new CombineZippedPages();\n\n return combineZippedPages.execute({\n store,\n response\n });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAEO,MAAMG,mBAAmB,GAAG,CAAC;AAACC,OAAA,CAAAD,mBAAA,GAAAA,mBAAA;AAE9B,MAAME,oBAAoB,CAAC;EAC9B,MAAaC,OAAOA,CAACC,MAAwC,EAAgC;IACzF,MAAM;MAAEC,QAAQ;MAAEC,KAAK;MAAEC,SAAS;MAAEC,gBAAgB;MAAEC,OAAO;MAAEC;IAAM,CAAC,GAAGN,MAAM;IAE/E,IAAIG,SAAS,CAAC,CAAC,EAAE;MACb,OAAOF,QAAQ,CAACM,OAAO,CAAC,CAAC;IAC7B,CAAC,MAAM,IAAIH,gBAAgB,CAAC,CAAC,EAAE;MAC3B,OAAOH,QAAQ,CAACO,QAAQ,CAAC;QACrB,GAAGN;MACP,CAAC,CAAC;IACN;IACA;AACR;AACA;IACQ,MAAMO,MAAM,GAAG,MAAMJ,OAAO,CAACK,KAAK,CAACC,SAAS,CAAC;MACzCC,KAAK,EAAE;QACHC,QAAQ,EAAEP,KAAK,CAACQ,OAAO,CAAC,CAAC,CAACC,EAAE;QAC5BC,YAAY,EAAEC,qBAAc,CAACC,QAAQ;QACrCC,aAAa,EAAE,CAACC,qBAAc,CAACC,OAAO,EAAED,qBAAc,CAACE,OAAO;MAClE,CAAC;MACDC,KAAK,EAAE;IACX,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAId,MAAM,CAACe,KAAK,CAACC,MAAM,GAAG,CAAC,EAAE;MACzB,OAAOxB,QAAQ,CAACO,QAAQ,CACpB;QACI,GAAGN;MACP,CAAC,EACD;QACIwB,OAAO,EAAE9B;MACb,CACJ,CAAC;IACL;IACA;AACR;AACA;IACQ,MAAM+B,kBAAkB,GAAG,IAAIC,sCAAkB,CAAC,CAAC;IAEnD,OAAOD,kBAAkB,CAAC5B,OAAO,CAAC;MAC9BO,KAAK;MACLL;IACJ,CAAC,CAAC;EACN;AACJ;AAACJ,OAAA,CAAAC,oBAAA,GAAAA,oBAAA"}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { ITaskResponseDoneResultOutput, ITaskRunParams } from "@webiny/tasks";
|
2
|
+
import { PbImportExportContext } from "../../types";
|
3
|
+
export declare enum PageExportTask {
|
4
|
+
Controller = "pageBuilderExportPagesController",
|
5
|
+
ZipPages = "pageBuilderExportPagesZipPages",
|
6
|
+
Cleanup = "pageBuilderExportPagesCleanup"
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* Controller
|
10
|
+
*/
|
11
|
+
export interface IExportPagesControllerInput {
|
12
|
+
type: "published" | "latest";
|
13
|
+
where?: Record<string, any>;
|
14
|
+
totalPages: number;
|
15
|
+
after?: string | null;
|
16
|
+
currentBatch?: number;
|
17
|
+
zippingPages?: boolean;
|
18
|
+
}
|
19
|
+
export interface IExportPagesControllerOutput extends ITaskResponseDoneResultOutput {
|
20
|
+
key: string;
|
21
|
+
url: string;
|
22
|
+
}
|
23
|
+
export declare type IExportPagesControllerTaskParams = ITaskRunParams<PbImportExportContext, IExportPagesControllerInput, IExportPagesControllerOutput>;
|
24
|
+
/**
|
25
|
+
* Zip Pages
|
26
|
+
*/
|
27
|
+
export interface IExportPagesZipPagesDone {
|
28
|
+
[pageId: string]: string;
|
29
|
+
}
|
30
|
+
export interface IExportPagesZipPagesInput {
|
31
|
+
type: "published" | "latest";
|
32
|
+
queue: string[];
|
33
|
+
done?: IExportPagesZipPagesDone;
|
34
|
+
failed?: string[];
|
35
|
+
}
|
36
|
+
export interface IExportPagesZipPagesOutput extends ITaskResponseDoneResultOutput {
|
37
|
+
done: IExportPagesZipPagesDone;
|
38
|
+
failed: string[];
|
39
|
+
}
|
40
|
+
export declare type IExportPagesZipPagesTaskParams = ITaskRunParams<PbImportExportContext, IExportPagesZipPagesInput, IExportPagesZipPagesOutput>;
|
41
|
+
/**
|
42
|
+
* Combine Zipped Pages
|
43
|
+
*/
|
44
|
+
export interface IExportPagesCombineZippedPagesOutput extends ITaskResponseDoneResultOutput {
|
45
|
+
key: string;
|
46
|
+
url: string;
|
47
|
+
}
|
48
|
+
export declare type IExportPagesCombineZippedPagesParams = Pick<ITaskRunParams<PbImportExportContext, IExportPagesControllerInput, IExportPagesCombineZippedPagesOutput>, "store" | "response">;
|
49
|
+
/**
|
50
|
+
* Cleanup Zip files
|
51
|
+
*/
|
52
|
+
export declare type IExportPagesCleanupInput = Record<string, boolean>;
|
53
|
+
export declare type IExportPagesCleanupTaskParams = ITaskRunParams<PbImportExportContext, IExportPagesCleanupInput>;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.PageExportTask = void 0;
|
7
|
+
let PageExportTask = /*#__PURE__*/function (PageExportTask) {
|
8
|
+
PageExportTask["Controller"] = "pageBuilderExportPagesController";
|
9
|
+
PageExportTask["ZipPages"] = "pageBuilderExportPagesZipPages";
|
10
|
+
PageExportTask["Cleanup"] = "pageBuilderExportPagesCleanup";
|
11
|
+
return PageExportTask;
|
12
|
+
}({});
|
13
|
+
/**
|
14
|
+
* Controller
|
15
|
+
*/
|
16
|
+
/**
|
17
|
+
* Zip Pages
|
18
|
+
*/
|
19
|
+
/**
|
20
|
+
* Combine Zipped Pages
|
21
|
+
*/
|
22
|
+
/**
|
23
|
+
* Cleanup Zip files
|
24
|
+
*/
|
25
|
+
exports.PageExportTask = PageExportTask;
|
26
|
+
|
27
|
+
//# sourceMappingURL=types.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["PageExportTask","exports"],"sources":["types.ts"],"sourcesContent":["import { ITaskResponseDoneResultOutput, ITaskRunParams } from \"@webiny/tasks\";\nimport { PbImportExportContext } from \"~/types\";\n\nexport enum PageExportTask {\n Controller = \"pageBuilderExportPagesController\",\n ZipPages = \"pageBuilderExportPagesZipPages\",\n Cleanup = \"pageBuilderExportPagesCleanup\"\n}\n\n/**\n * Controller\n */\nexport interface IExportPagesControllerInput {\n type: \"published\" | \"latest\";\n where?: Record<string, any>;\n totalPages: number;\n after?: string | null;\n currentBatch?: number;\n zippingPages?: boolean;\n}\n\nexport interface IExportPagesControllerOutput extends ITaskResponseDoneResultOutput {\n key: string;\n url: string;\n}\n\nexport type IExportPagesControllerTaskParams = ITaskRunParams<\n PbImportExportContext,\n IExportPagesControllerInput,\n IExportPagesControllerOutput\n>;\n\n/**\n * Zip Pages\n */\nexport interface IExportPagesZipPagesDone {\n [pageId: string]: string;\n}\nexport interface IExportPagesZipPagesInput {\n type: \"published\" | \"latest\";\n queue: string[];\n done?: IExportPagesZipPagesDone;\n failed?: string[];\n}\n\nexport interface IExportPagesZipPagesOutput extends ITaskResponseDoneResultOutput {\n done: IExportPagesZipPagesDone;\n failed: string[];\n}\n\nexport type IExportPagesZipPagesTaskParams = ITaskRunParams<\n PbImportExportContext,\n IExportPagesZipPagesInput,\n IExportPagesZipPagesOutput\n>;\n\n/**\n * Combine Zipped Pages\n */\n\nexport interface IExportPagesCombineZippedPagesOutput extends ITaskResponseDoneResultOutput {\n key: string;\n url: string;\n}\n\nexport type IExportPagesCombineZippedPagesParams = Pick<\n ITaskRunParams<\n PbImportExportContext,\n IExportPagesControllerInput,\n IExportPagesCombineZippedPagesOutput\n >,\n \"store\" | \"response\"\n>;\n\n/**\n * Cleanup Zip files\n */\nexport type IExportPagesCleanupInput = Record<string, boolean>;\n\nexport type IExportPagesCleanupTaskParams = ITaskRunParams<\n PbImportExportContext,\n IExportPagesCleanupInput\n>;\n"],"mappings":";;;;;;IAGYA,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA;AAM1B;AACA;AACA;AAqBA;AACA;AACA;AAsBA;AACA;AACA;AAgBA;AACA;AACA;AAFAC,OAAA,CAAAD,cAAA,GAAAA,cAAA"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createExportPagesDataKey = exports.EXPORT_PAGES_FOLDER_KEY = void 0;
|
7
|
+
const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
8
|
+
exports.EXPORT_PAGES_FOLDER_KEY = EXPORT_PAGES_FOLDER_KEY;
|
9
|
+
const createExportPagesDataKey = taskId => {
|
10
|
+
return `${EXPORT_PAGES_FOLDER_KEY}/${taskId}`;
|
11
|
+
};
|
12
|
+
exports.createExportPagesDataKey = createExportPagesDataKey;
|
13
|
+
|
14
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","exports","createExportPagesDataKey","taskId"],"sources":["utils.ts"],"sourcesContent":["export const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\n\nexport const createExportPagesDataKey = (taskId: string) => {\n return `${EXPORT_PAGES_FOLDER_KEY}/${taskId}`;\n};\n"],"mappings":";;;;;;AAAO,MAAMA,uBAAuB,GAAG,wBAAwB;AAACC,OAAA,CAAAD,uBAAA,GAAAA,uBAAA;AAEzD,MAAME,wBAAwB,GAAIC,MAAc,IAAK;EACxD,OAAQ,GAAEH,uBAAwB,IAAGG,MAAO,EAAC;AACjD,CAAC;AAACF,OAAA,CAAAC,wBAAA,GAAAA,wBAAA"}
|