1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-12 19:37:29 +00:00

Fetch instance list from instances.invidio.us

This commit is contained in:
Cadence Ember 2021-01-13 23:48:18 +13:00
parent c55429ac49
commit 806494f5e0
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17
3 changed files with 27 additions and 7 deletions

View File

@ -2,6 +2,7 @@ const {render, redirect} = require("pinski/plugins")
const db = require("../utils/db")
const {getToken, getUser} = require("../utils/getuser")
const constants = require("../utils/constants")
const {getInstances} = require("../background/instances")
const validate = require("../utils/validate")
const V = validate.V
@ -10,7 +11,8 @@ module.exports = [
route: "/settings", methods: ["GET"], code: async ({req}) => {
const user = getUser(req)
const settings = user.getSettings()
return render(200, "pug/settings.pug", {constants, user, settings})
const instances = getInstances()
return render(200, "pug/settings.pug", {constants, user, settings, instances})
}
},
{

23
background/instances.js Normal file
View File

@ -0,0 +1,23 @@
const {request} = require("../utils/request")
let globalList = []
function execute() {
return request("https://instances.invidio.us/instances.json?sort_by=health").then(res => res.json()).then(list => {
list = list.filter(i => i[1].type === "https").map(i => i[1].uri)
globalList = list
}).catch(error => {
console.error(error)
})
}
function getInstances() {
return globalList
}
execute()
setInterval(() => {
execute()
}, 60*60*1000)
module.exports.getInstances = getInstances

View File

@ -30,12 +30,7 @@ block content
form(method="post" action="/settings")
+fieldset("Settings")
+input("instance", "Instance", "url", constants.user_settings.instance.default, false, [
"https://invidious.snopyta.org",
"https://invidious.13ad.de",
"https://watch.nettohikari.com",
"https://invidious.fdn.fr"
])
+input("instance", "Instance", "url", constants.user_settings.instance.default, false, instances)
+select("save_history", "Watched videos history", false, [
{value: "0", text: "Don't store"},