🍙 url resolver changes

- made it send more than one request at once
This commit is contained in:
Shiba 2022-01-07 20:09:05 +00:00
parent 682af767c9
commit 75274005ee

View file

@ -156,37 +156,44 @@ export const ytService = {
url.pathname = urlResolverFunction.pathname url.pathname = urlResolverFunction.pathname
if (urlResolverFunction.paramArraySeperator === SingleValueAtATime) if (urlResolverFunction.paramArraySeperator === SingleValueAtATime)
{ {
for (const descriptor of descriptorsGroup) await Promise.all(descriptorsGroup.map(async (descriptor) => {
{ switch (null)
{
default:
if (!descriptor.id) break
url.searchParams.set(urlResolverFunction.paramName, descriptor.id)
const apiResponse = await fetch(url.toString(), { cache: 'force-cache' });
if (!apiResponse.ok) break
const value = followResponsePath<string>(await apiResponse.json(), urlResolverFunction.responsePath)
if (value) results[descriptor.index] = value
}
progressCount++ progressCount++
if (!descriptor.id) continue
url.searchParams.set(urlResolverFunction.paramName, descriptor.id)
const apiResponse = await fetch(url.toString(), { cache: 'force-cache' });
if (!apiResponse.ok) continue
const value = followResponsePath<string>(await apiResponse.json(), urlResolverFunction.responsePath)
if (value) results[descriptor.index] = value
if (progressCallback) progressCallback(progressCount / descriptorsWithIndex.length) if (progressCallback) progressCallback(progressCount / descriptorsWithIndex.length)
} }))
} }
else else
{ {
progressCount += descriptorsGroup.length
url.searchParams
.set(urlResolverFunction.paramName, descriptorsGroup
.map((descriptor) => descriptor.id)
.filter((descriptorId) => descriptorId)
.join(urlResolverFunction.paramArraySeperator)
)
const apiResponse = await fetch(url.toString(), { cache: 'force-cache' }); switch (null)
if (!apiResponse.ok) return {
const values = followResponsePath<string[]>(await apiResponse.json(), urlResolverFunction.responsePath) default:
values.forEach((value, index) => { url.searchParams
const descriptorIndex = descriptorsGroup[index].index .set(urlResolverFunction.paramName, descriptorsGroup
if (value) (results[descriptorIndex] = value) .map((descriptor) => descriptor.id)
if (progressCallback) progressCallback(progressCount / descriptorsWithIndex.length) .filter((descriptorId) => descriptorId)
}) .join(urlResolverFunction.paramArraySeperator)
)
const apiResponse = await fetch(url.toString(), { cache: 'force-cache' });
if (!apiResponse.ok) break
const values = followResponsePath<string[]>(await apiResponse.json(), urlResolverFunction.responsePath)
values.forEach((value, index) => {
const descriptorIndex = descriptorsGroup[index].index
if (value) (results[descriptorIndex] = value)
})
}
progressCount += descriptorsGroup.length
if (progressCallback) progressCallback(progressCount / descriptorsWithIndex.length)
} }
} }