mirror of https://github.com/FreeTubeApp/FreeTube
Add a 15 second timeout for fetching the Invidious instances at startup (#4233)
* Add a 15 second timeout for fetching the Invidious instances at startup * Use a better name for the timeout parameter Co-authored-by: PikachuEXE <pikachuexe@gmail.com> * Fix docs --------- Co-authored-by: PikachuEXE <pikachuexe@gmail.com>
This commit is contained in:
parent
ff76f0e8c4
commit
6d6fc73059
|
@ -672,3 +672,35 @@ export function escapeHTML(untrusted) {
|
|||
export function deepCopy(obj) {
|
||||
return JSON.parse(JSON.stringify(obj))
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the `name` of the error is `TimeoutError` to know if the error was caused by a timeout or something else.
|
||||
* @param {number} timeoutMs
|
||||
* @param {RequestInfo|URL} input
|
||||
* @param {RequestInit=} init
|
||||
*/
|
||||
export async function fetchWithTimeout(timeoutMs, input, init) {
|
||||
const timeoutSignal = AbortSignal.timeout(timeoutMs)
|
||||
|
||||
if (typeof init !== 'undefined') {
|
||||
init.signal = timeoutSignal
|
||||
} else {
|
||||
init = {
|
||||
signal: timeoutSignal
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return await fetch(input, init)
|
||||
} catch (err) {
|
||||
if (err.name === 'AbortError' && timeoutSignal.aborted) {
|
||||
// According to the spec, fetch should use the original abort reason.
|
||||
// Unfortunately chromium browsers always throw an AbortError, even when it was caused by a TimeoutError,
|
||||
// so we need manually throw the original abort reason
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1431720
|
||||
throw timeoutSignal.reason
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import fs from 'fs/promises'
|
||||
import { pathExists } from '../../helpers/filesystem'
|
||||
import { createWebURL } from '../../helpers/utils'
|
||||
import { createWebURL, fetchWithTimeout } from '../../helpers/utils'
|
||||
|
||||
const state = {
|
||||
currentInvidiousInstance: '',
|
||||
|
@ -23,7 +23,7 @@ const actions = {
|
|||
|
||||
let instances = []
|
||||
try {
|
||||
const response = await fetch(requestUrl)
|
||||
const response = await fetchWithTimeout(15_000, requestUrl)
|
||||
const json = await response.json()
|
||||
instances = json.filter((instance) => {
|
||||
return !(instance[0].includes('.onion') ||
|
||||
|
@ -34,7 +34,11 @@ const actions = {
|
|||
return instance[1].uri.replace(/\/$/, '')
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
if (err.name === 'TimeoutError') {
|
||||
console.error('Fetching the Invidious instance list timed out after 15 seconds. Falling back to local copy.')
|
||||
} else {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
// If the invidious instance fetch isn't returning anything interpretable
|
||||
if (instances.length === 0) {
|
||||
|
|
|
@ -1,74 +1,90 @@
|
|||
[
|
||||
{
|
||||
"url": "https://invidious.fdn.fr",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://vid.puffyan.us",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://inv.riverside.rocks",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.nerdvpn.de",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.tiekoetter.com",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://inv.bp.projectsegfau.lt",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.flokinet.to",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://yt.artemislena.eu",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://inv.pistasjis.net",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.sethforprivacy.com",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.projectsegfau.lt",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.baczek.me",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://yt.funami.tech",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://iv.ggtyler.dev",
|
||||
"url": "https://inv.bp.projectsegfau.lt",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.lunar.icu",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.io.lol",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://inv.tux.pizza",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.privacydev.net",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://yt.artemislena.eu",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://vid.priv.au",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.0011.lt",
|
||||
"url": "https://onion.tube",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://inv.zzls.xyz",
|
||||
"url": "https://yt.oelrichsgarcia.de",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.protokolla.fi",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.asir.dev",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://iv.nboeck.de",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.private.coffee",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://iv.datura.network",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://anontube.lvkaszus.pl",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://inv.us.projectsegfau.lt",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.perennialte.ch",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.drgns.space",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.einfachzocken.eu",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
|
@ -76,11 +92,15 @@
|
|||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://yt.floss.media",
|
||||
"cors": false
|
||||
"url": "https://invidious.no-logs.com",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.nogafa.org",
|
||||
"url": "https://yt.drgnz.club",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://yt.cdaut.de",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
|
@ -88,11 +108,7 @@
|
|||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.esmailelbob.xyz",
|
||||
"cors": true
|
||||
},
|
||||
{
|
||||
"url": "https://invidious.snopyta.org",
|
||||
"url": "https://inv.citw.lgbt",
|
||||
"cors": true
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue