diff --git a/ci/invidiousCI.ts b/ci/invidiousCI.ts index e96ea171..1e2e8348 100644 --- a/ci/invidiousCI.ts +++ b/ci/invidiousCI.ts @@ -4,8 +4,9 @@ This file is only ran by GitHub Actions in order to populate the Invidious insta This file should not be shipped with the extension */ -import { writeFile, existsSync } from 'fs'; -import { join } from 'path'; +import { writeFile, existsSync } from "fs" +import { join } from "path" +import { InvidiousInstance, instanceMap } from "./invidiousType" // import file from https://api.invidious.io/instances.json if (!existsSync(join(__dirname, "data.json"))) { @@ -15,41 +16,40 @@ if (!existsSync(join(__dirname, "data.json"))) { // @ts-ignore import * as data from "../ci/data.json"; -type instanceMap = { - name: string; - url: string; - dailyRatios: {ratio: string; label: string }[]; - thirtyDayUptime: string; -}[] +// static non-invidious instances +const staticInstances = ["www.youtubekids.com"]; // only https servers const mapped: instanceMap = data - // eslint-disable-next-line @typescript-eslint/no-explicit-any - .filter((i: any) => i[1]?.type === 'https') - // eslint-disable-next-line @typescript-eslint/no-explicit-any - .map((instance: any) => { + .filter((i: InvidiousInstance) => i[1]?.type === "https") + .map((instance: InvidiousInstance) => { return { name: instance[0], url: instance[1].uri, dailyRatios: instance[1].monitor.dailyRatios, - thirtyDayUptime: instance[1]?.monitor['30dRatio'].ratio, + thirtyDayUptime: instance[1]?.monitor["30dRatio"].ratio, } - }) + }); // reliability and sanity checks const reliableCheck = mapped .filter((instance) => { // 30d uptime >= 90% - const thirtyDayUptime = Number(instance.thirtyDayUptime) >= 90 + const thirtyDayUptime = Number(instance.thirtyDayUptime) >= 90; // available for at least 80/90 days - const dailyRatioCheck = instance.dailyRatios.filter(status => status.label !== "black") - return (thirtyDayUptime && dailyRatioCheck.length >= 80) + const dailyRatioCheck = instance.dailyRatios.filter(status => status.label !== "black"); + return thirtyDayUptime && dailyRatioCheck.length >= 80; }) // url includes name - .filter(instance => instance.url.includes(instance.name)) + .filter((instance) => instance.url.includes(instance.name)); // finally map to array -const result: string[] = reliableCheck.map(instance => instance.name).sort() -writeFile(join(__dirname, "./invidiouslist.json"), JSON.stringify(result), (err) => { - if (err) return console.log(err); -}) \ No newline at end of file +const result: string[] = reliableCheck.map((instance) => instance.name).sort(); + +writeFile( + join(__dirname, "./invidiouslist.json"), + JSON.stringify([...staticInstances, ...result]), + (err) => { + if (err) return console.log(err); + } +); diff --git a/ci/invidiousType.ts b/ci/invidiousType.ts new file mode 100644 index 00000000..e5f682bb --- /dev/null +++ b/ci/invidiousType.ts @@ -0,0 +1,54 @@ +type ratio = { + ratio: string; + label: string; +} + +export type instanceMap = { + name: string; + url: string; + dailyRatios: {ratio: string; label: string }[]; + thirtyDayUptime: string; +}[] + +export type InvidiousInstance = [ + string, + { + flag: string; + region: string; + stats: null | { + version: string; + software: { + name: string; + version: string; + branch: string; + }; + openRegistrations: boolean; + usage: { + users: { + total: number; + activeHalfyear: number; + activeMonth: number; + }; + }; + metadata: { + updatedAt: number; + lastChannelRefreshedAt: number; + }; + }; + cors: boolean | null; + api: boolean | null; + type: "https" | "http" | "onion" | "i2p"; + uri: string; + monitor: null | { + monitorId: number; + createdAt: number; + statusClass: string; + name: string; + url: string | null; + type: "HTTP(s)"; + dailyRatios: ratio[]; + "90dRatio": ratio; + "30dRatio": ratio; + }; + } +] \ No newline at end of file diff --git a/ci/invidiouslist.json b/ci/invidiouslist.json index e81439d7..5ad44cb3 100644 --- a/ci/invidiouslist.json +++ b/ci/invidiouslist.json @@ -1 +1 @@ -["inv.bp.projectsegfau.lt","inv.zzls.xyz","invidious.0011.lt","invidious.baczek.me","invidious.lunar.icu","invidious.privacydev.net","invidious.tiekoetter.com","iv.ggtyler.dev","iv.melmac.space","vid.puffyan.us","y.com.sb","yewtu.be","yt.artemislena.eu"] \ No newline at end of file +["www.youtubekids.com","inv.bp.projectsegfau.lt","inv.tux.pizza","inv.zzls.xyz","invidious.0011.lt","invidious.lunar.icu","invidious.privacydev.net","invidious.tiekoetter.com","iv.ggtyler.dev","iv.melmac.space","vid.priv.au","vid.puffyan.us","yewtu.be","yt.artemislena.eu"] \ No newline at end of file