mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2024-12-22 13:07:00 +00:00
Fetch instance list from instances.invidio.us
This commit is contained in:
parent
c55429ac49
commit
806494f5e0
@ -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
23
background/instances.js
Normal 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
|
@ -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"},
|
||||
|
Loading…
Reference in New Issue
Block a user