Skip to content

Commit

Permalink
retry 5x
Browse files Browse the repository at this point in the history
  • Loading branch information
haayman committed Oct 18, 2023
1 parent bfc611d commit 60961c5
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions parseAlbum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
onmessage = async ({data:link}) => {

const response = await fetch(`/wp-admin/admin-ajax.php?action=plusleo_album&link=${encodeURIComponent(link)}`).then(res => res.text());
const regex = new RegExp('"(?<url>http[^"]+)",[0-9^,]+,[0-9^,]+', 'gi');
const urls = [];
for( const match of response.matchAll(regex) ) {
onmessage = async ({ data: link }) => {
let retries = 5;
while (retries--) {
try {
const response = await fetch(
`/wp-admin/admin-ajax.php?action=foto_album&link=${encodeURIComponent(
link
)}`
).then((res) => res.text());
const regex = new RegExp('"(?<url>http[^"]+)",[0-9^,]+,[0-9^,]+', "gi");
const urls = [];
for (const match of response.matchAll(regex)) {
urls.push(match.groups.url);
}
if(!urls.length) throw new Error("No urls found");
postMessage(urls);
return;
} catch (e) {
console.log(`retrying ${link}...(${retries} retries left)`);
await new Promise((r) => setTimeout(r, 500));
}
postMessage(urls);
}
}
};

0 comments on commit 60961c5

Please sign in to comment.