Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
feat: ✨ criar promise de response de imagens
Browse files Browse the repository at this point in the history
+ renomear waitDownload.js
  • Loading branch information
renatocfrancisco committed Aug 27, 2024
1 parent 5a3c610 commit 255656c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
30 changes: 30 additions & 0 deletions js/promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export async function waitUntilDownload (page) {
return new Promise((resolve, reject) => {
page._client().on('Page.downloadProgress', (e) => {
// or 'Browser.downloadProgress'
console.clear()
if (e.state === 'completed') {
console.log('Chart downloaded!')
resolve()
} else if (e.state === 'canceled') {
reject(new Error('Download canceled'))
}
})
})
}

export async function waitImageResponses (page, numImgs, responseCount = 0) {
await new Promise((resolve, _reject) => {
page.on('response', async (response) => {
if (response.url().startsWith('https://lastfm.freetls.fastly.net/i/u/')) {
responseCount++
console.clear()
console.log(`Image ${responseCount} of ${numImgs} downloaded...`)

if (responseCount === numImgs) {
resolve()
}
}
})
})
}
12 changes: 0 additions & 12 deletions js/waitDownload.js

This file was deleted.

0 comments on commit 255656c

Please sign in to comment.