api/utils: update getRedirectingURL to accept more statuses & dispatcher

This commit is contained in:
wukko 2025-01-20 18:51:37 +06:00
parent ef687750b4
commit 9bdcb9d821
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -1,8 +1,16 @@
export function getRedirectingURL(url) {
return fetch(url, { redirect: 'manual' }).then((r) => {
if ([301, 302, 303].includes(r.status) && r.headers.has('location'))
const redirectStatuses = [301, 302, 303, 307, 308];
export async function getRedirectingURL(url, dispatcher) {
const location = await fetch(url, {
redirect: 'manual',
dispatcher,
}).then((r) => {
if (redirectStatuses.includes(r.status) && r.headers.has('location')) {
return r.headers.get('location');
}
}).catch(() => null);
return location;
}
export function merge(a, b) {