fix: white screen when invidious instances don't load (#1755)
* fix white screen when invidious instances don't load * static file for instances on api fail * Update src/renderer/store/modules/invidious.js Co-authored-by: PikachuEXE <pikachuexe@gmail.com> * only parse json if file exists * fix linter * Update src/renderer/store/modules/invidious.js Co-authored-by: PikachuEXE <pikachuexe@gmail.com> * Update src/renderer/store/modules/invidious.js * Update invidious.js * Update src/renderer/store/modules/invidious.js Co-authored-by: PikachuEXE <pikachuexe@gmail.com> * remove trailing space Co-authored-by: PikachuEXE <pikachuexe@gmail.com>
This commit is contained in:
parent
ef9efc9c75
commit
c25997c804
|
@ -130,7 +130,7 @@ export default Vue.extend({
|
||||||
},
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
this.grabUserSettings().then(async () => {
|
this.grabUserSettings().then(async () => {
|
||||||
await this.fetchInvidiousInstances()
|
await this.fetchInvidiousInstances({ isDev: this.isDev })
|
||||||
if (this.defaultInvidiousInstance === '') {
|
if (this.defaultInvidiousInstance === '') {
|
||||||
await this.setRandomCurrentInvidiousInstance()
|
await this.setRandomCurrentInvidiousInstance()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import $ from 'jquery'
|
import $ from 'jquery'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
currentInvidiousInstance: '',
|
currentInvidiousInstance: '',
|
||||||
|
@ -21,17 +22,14 @@ const getters = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
async fetchInvidiousInstances({ commit }) {
|
async fetchInvidiousInstances({ commit }, payload) {
|
||||||
const requestUrl = 'https://api.invidious.io/instances.json'
|
const requestUrl = 'https://api.invidious.io/instances.json'
|
||||||
|
|
||||||
let response
|
let response
|
||||||
|
let instances = []
|
||||||
try {
|
try {
|
||||||
response = await $.getJSON(requestUrl)
|
response = await $.getJSON(requestUrl)
|
||||||
} catch (err) {
|
instances = response.filter((instance) => {
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
const instances = response.filter((instance) => {
|
|
||||||
if (instance[0].includes('.onion') || instance[0].includes('.i2p')) {
|
if (instance[0].includes('.onion') || instance[0].includes('.i2p')) {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,6 +38,27 @@ const actions = {
|
||||||
}).map((instance) => {
|
}).map((instance) => {
|
||||||
return instance[1].uri.replace(/\/$/, '')
|
return instance[1].uri.replace(/\/$/, '')
|
||||||
})
|
})
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
// Starts fallback strategy: read from static file
|
||||||
|
// And fallback to hardcoded entry(s) if static file absent
|
||||||
|
const fileName = 'invidious-instances.json'
|
||||||
|
/* eslint-disable-next-line */
|
||||||
|
const fileLocation = payload.isDev ? './static/' : `${__dirname}/static/`
|
||||||
|
if (fs.existsSync(`${fileLocation}${fileName}`)) {
|
||||||
|
console.log('reading static file for invidious instances')
|
||||||
|
const fileData = fs.readFileSync(`${fileLocation}${fileName}`)
|
||||||
|
instances = JSON.parse(fileData).map((entry) => {
|
||||||
|
return entry.url
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log('unable to read static file for invidious instances')
|
||||||
|
instances = [
|
||||||
|
'https://invidious.snopyta.org',
|
||||||
|
'https://invidious.kavin.rocks/'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commit('setInvidiousInstancesList', instances)
|
commit('setInvidiousInstancesList', instances)
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
[
|
||||||
|
{ "url": "https://yewtu.be" },
|
||||||
|
{ "url": "https://invidious.snopyta.org" },
|
||||||
|
{ "url": "https://invidious.kavin.rocks" },
|
||||||
|
{ "url": "https://vid.puffyan.us" },
|
||||||
|
{ "url": "https://invidious.exonip.de" },
|
||||||
|
{ "url": "https://ytprivate.com" },
|
||||||
|
{ "url": "https://invidious-us.kavin.rocks" },
|
||||||
|
{ "url": "https://invidious.silkky.cloud" },
|
||||||
|
{ "url": "https://y.com.cm" },
|
||||||
|
{ "url": "https://inv.riverside.rocks" },
|
||||||
|
{ "url": "https://invidio.xamh.de" },
|
||||||
|
{ "url": "https://vid.mint.lgbt" },
|
||||||
|
{ "url": "https://invidious-jp.kavin.rocks" },
|
||||||
|
{ "url": "https://invidious.hub.ne.kr" },
|
||||||
|
{ "url": "https://yt.didw.to" },
|
||||||
|
{ "url": "https://yt.artemislena.eu" },
|
||||||
|
{ "url": "https://youtube.076.ne.jp" },
|
||||||
|
{ "url": "https://ytb.trom.tf" },
|
||||||
|
{ "url": "https://invidious.namazso.eu" }
|
||||||
|
]
|
Loading…
Reference in New Issue