diff --git a/api/settings.js b/api/settings.js index 653811c..cce54b1 100644 --- a/api/settings.js +++ b/api/settings.js @@ -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}) } }, { diff --git a/background/instances.js b/background/instances.js new file mode 100644 index 0000000..620fbe6 --- /dev/null +++ b/background/instances.js @@ -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 diff --git a/pug/settings.pug b/pug/settings.pug index 1115727..d70c3e4 100644 --- a/pug/settings.pug +++ b/pug/settings.pug @@ -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"},