diff --git a/threads.ts b/threads.ts index 81f4675..7142818 100644 --- a/threads.ts +++ b/threads.ts @@ -66,25 +66,34 @@ Threads.parentPort.on('message', async (Message: string) => { ${ChangedFiles.join('\n - ').replace(/^/, ' - ')} `) + // Set new array by splitting with each of the 20 items. + var SplittedChangedFiles:Array = new Array(Math.ceil(ChangedFiles.length / 20)) + for (let i = 0; i < SplittedChangedFiles.length; i++) { + SplittedChangedFiles[i] = ChangedFiles.slice(i === 0 ? i : i * 20, (i + 1) * 20 > ChangedFiles.length ? ChangedFiles.length : (i + 1) * 20) + } + ChangedFiles = null + // Make requests - for (const Changed of ChangedFiles) { - const CDNResponses:Array = [] + for (let Changed of SplittedChangedFiles) { + let CDNResponses:Array = [] while(CDNResponses.length === 0 || !(CDNResponses.some(async (CDNResponse) => { - const CDNStatus:JSON = await Got.got.get(`https://purge.jsdelivr.net/status/${CDNResponse}`, { https: { minVersion: 'TLSv1.3' }, http2: true }).json() + let CDNStatus:JSON = await Got.got.get(`https://purge.jsdelivr.net/status/${CDNResponse}`, { https: { minVersion: 'TLSv1.3' }, http2: true }).json() return CDNStatus['status'] === 'finished' || CDNStatus['status'] === 'failed'})) ) { - const CDNRequest:JSON = await Got.got.post('https://purge.jsdelivr.net/', { + let CDNRequest:JSON = await Got.got.post('https://purge.jsdelivr.net/', { headers: { 'cache-control': 'no-cache' }, json: { - 'path': [`/gh/${RepoOwner}/${RepoName}@${Message}/${Changed}`] + 'path': Changed.map(element => `/gh/${RepoOwner}/${RepoName}@${Message}/${element}`) }, https: { minVersion: 'TLSv1.3' }, http2: true }).json() Actions.info(`Thread for ${Message}: Sent new request having ${CDNRequest['id']} ID.`) CDNResponses.push(CDNRequest['id']) await new Promise(resolve => setTimeout(resolve, 5000)) } - Actions.info(`Thread for ${Message}: jsDelivr server returns that ${Changed} is purged.`) + Actions.info(`Thread for ${Message}: jsDelivr server returns that the following files are purged: + ${Changed.join('\n - ').replace(/^/, ' - ')} + `) } Actions.info(`Thread for ${Message}: All changed files are purged. Exiting...`)