This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ criar promise de response de imagens
+ renomear waitDownload.js
- Loading branch information
1 parent
5a3c610
commit 255656c
Showing
2 changed files
with
30 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
}) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.