-
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.
- Loading branch information
Showing
1 changed file
with
21 additions
and
8 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 |
---|---|---|
@@ -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); | ||
} | ||
} | ||
}; |