api/utils: replace redirectStatuses array with a set

Co-authored-by: jj <log@riseup.net>
This commit is contained in:
wukko 2025-01-20 19:30:11 +06:00 committed by GitHub
parent cd0a2a47c9
commit de5eca19a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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