"use strict";exports.ids=["254"],exports.modules={11361:function(e,t,s){Object.defineProperty(t,"__esModule",{value:!0}),t.CreateZipPagesTasks=void 0;var a=s(30690),r=s(29294);t.CreateZipPagesTasks=class{async execute({response:e,input:t,isAborted:s,isCloseToTimeout:o,context:i,store:n}){let c,l={where:t.where,after:t.after,limit:25},u=t.currentBatch||1;for(;c=await i.pageBuilder.listLatestPages(l);){if(s())return e.aborted();if(o())return e.continue({...t,...l,currentBatch:u});let[p,d]=c;if(l.after=d.cursor,0===d.totalCount)return e.done("No pages to export.");if(0===p.length)return e.continue({...t,...l,currentBatch:u,totalPages:d.totalCount,zippingPages:!0},{seconds:a.ZIP_PAGES_WAIT_TIME});let g=p.map(e=>e.id);if(await i.tasks.trigger({name:`Page Builder - Export Pages - Zip Pages #${u}`,parent:n.getTask(),definition:r.PageExportTask.ZipPages,input:{queue:g,type:t.type}}),!d.hasMoreItems||!d.cursor)return e.continue({...t,...l,currentBatch:u,totalPages:d.totalCount,zippingPages:!0},{seconds:a.ZIP_PAGES_WAIT_TIME});u++}return e.continue({...t,...l,currentBatch:u},{seconds:a.ZIP_PAGES_WAIT_TIME})}}},13736:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.createExportPagesDataKey=t.EXPORT_PAGES_FOLDER_KEY=void 0;let s=t.EXPORT_PAGES_FOLDER_KEY="WEBINY_PB_EXPORT_PAGES";t.createExportPagesDataKey=e=>`${s}/${e}`},30690:function(e,t,s){Object.defineProperty(t,"__esModule",{value:!0}),t.ZIP_PAGES_WAIT_TIME=t.ProcessZipPagesTasks=void 0;var a=s(97227),r=s(29294),o=s(98543);let i=t.ZIP_PAGES_WAIT_TIME=5;t.ProcessZipPagesTasks=class{async execute(e){let{response:t,input:s,isAborted:n,isCloseToTimeout:c,context:l,store:u}=e;return n()?t.aborted():c()?t.continue({...s}):(await l.tasks.listTasks({where:{parentId:u.getTask().id,definitionId:r.PageExportTask.ZipPages,taskStatus_in:[a.TaskDataStatus.RUNNING,a.TaskDataStatus.PENDING]},limit:1})).items.length>0?t.continue({...s},{seconds:i}):new o.CombineZippedPages().execute({store:u,response:t})}}},38907:function(e,t,s){t.ExportPagesController=void 0;var a=s(30690),r=s(11361);t.ExportPagesController=class{async execute(e){let{input:t}=e;if(t.zippingPages){let t=new a.ProcessZipPagesTasks;return await t.execute(e)}let s=new r.CreateZipPagesTasks;return await s.execute(e)}}},53314:function(e,t,s){var a=s(15755).default;Object.defineProperty(t,"__esModule",{value:!0}),t.ZipFiles=void 0;var r=s(81671),o=s(84442),i=a(s(71017)),n=s(12781),c=s(27856),l=s(28645),u=s(95687),p=s(13685);class d{bucket=process.env.S3_BUCKET;debug="true"===process.env.DEBUG;constructor(e){this.setDebug(e?.debug)}async process(e,t){let s=Array.from(t),a=(0,o.createS3)({requestHandler:new l.NodeHttpHandler({connectionTimeout:0,httpAgent:new p.Agent({maxSockets:1e4,keepAlive:!0,maxFreeSockets:1e4,maxTotalSockets:1e4,keepAliveMsecs:9e5}),httpsAgent:new u.Agent({maxSockets:1e4,keepAlive:!0,sessionTimeout:900,maxCachedSessions:1e5,maxFreeSockets:1e4,maxTotalSockets:1e4,keepAliveMsecs:9e5}),requestTimeout:9e5})}),d=new n.Stream.PassThrough({autoDestroy:!0}),g=new c.Upload({client:a,params:{ACL:"private",Body:d,Bucket:this.bucket,ContentType:"application/zip",Key:e},queueSize:1,partSize:5242880,leavePartsOnError:!1}),P=(0,r.create)("zip",{});P.on("error",e=>{throw console.error(e),Error(`${e.name} ${e.code} ${e.message} ${e.path} ${e.stack}`)}),P.pipe(d),P.on("entry",e=>{this.debug&&console.log(`Archived file: ${e.name}`),f()});let f=async()=>{let e=s.shift();if(!e){this.debug&&console.log("No more files to add to the archive."),setTimeout(()=>{P.finalize()},200);return}this.debug&&console.log(`Adding file "${e}" to the archive.`);let t=new o.GetObjectCommand({Bucket:this.bucket,Key:e}),r=await a.send(t);if(!r.Body)return this.debug&&console.log(`No response.Body for file "${e}", moving to next file.`),f();let n=`${i.default.basename(e)}`;P.append(r.Body,{name:n})};f();let m=await g.done();return a.destroy(),m}setDebug(e){void 0!==e&&(this.debug=e)}}t.ZipFiles=d},98543:function(e,t,s){var a=s(15755).default;Object.defineProperty(t,"__esModule",{value:!0}),t.CombineZippedPages=void 0;var r=s(31299),o=s(13736),i=s(53314),n=a(s(16277));t.CombineZippedPages=class{async execute(e){let t,s,{response:a,store:c}=e,l=c.getTask().id,u=(0,o.createExportPagesDataKey)(l);try{if(t=await r.s3Stream.listObject(u),!Array.isArray(t.Contents))return a.error({message:"There is no Contents defined on S3 Stream while combining pages."});if(0===t.Contents.length)return a.done("No zip files to combine.")}catch(e){return a.error(e)}let p=t.Contents.reduce((e,t)=>(t.Key&&(t.Key===u||e.push(t.Key)),e),[]);try{let e=new i.ZipFiles,t=(0,n.default)("EXPORTS/","-WEBINY_PAGE_EXPORT.zip"),r=await e.process(t,p);if(!r?.Key)return a.error({message:"There is no Key defined on pageExportUpload."});s=r.Key}catch(e){return console.error(`Error while combining zip files into a single zip: ${e.message}`),console.log(e),a.error(e)}let d=await r.s3Stream.getPresignedUrl(s);return a.done("Done combining pages.",{key:s,url:d})}}}};
//# sourceMappingURL=ExportPagesController.f929d99e.chunk.js.map