Skip to content
Snippets Groups Projects
Commit a81c6470 authored by Anthony's avatar Anthony
Browse files

Modify searchManifestAndAddButton to group all the fetch in one promise

parent 4d86183c
No related branches found
No related tags found
No related merge requests found
...@@ -26,18 +26,27 @@ export function searchManifestAndAddButton(html) { ...@@ -26,18 +26,27 @@ export function searchManifestAndAddButton(html) {
const urls = html.match( const urls = html.match(
/((http|https)\:\/\/[a-z0-9\/:%_+.,#?!@&=-]+)/g, /((http|https)\:\/\/[a-z0-9\/:%_+.,#?!@&=-]+)/g,
); );
if (urls) { if (urls) {
urls.forEach((url) => { let requestsArray = urls.map((url) => {
fetch(url, { let request = new Request(url, {
method: 'GET', method: 'GET',
}) });
.then((response) => response.text())
.then((text) => { return request;
const obj = JSON.parse(text); });
if (obj.type === 'Manifest') { Promise.all(requestsArray.map((request) => {
console.log(`Manifest Found ${url}`); return fetch(request).then((response) => {
return response.json();
}).then((data) => {
if (data.type === 'Manifest') {
return data;
} }
return null;
}); });
})).then((values) => {
console.log('values', values);
return values;
}); });
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment