SponsorBlock/ci/invidiousCI.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-09-07 06:17:03 +02:00
import { InvidiousInstance, monitor } from "./invidiousType"
2021-11-30 21:55:26 +01:00
import * as data from "../ci/invidious_instances.json";
2021-11-30 21:55:26 +01:00
// only https servers
2024-09-07 06:17:03 +02:00
const mapped = (data as InvidiousInstance[])
.filter((i) =>
i[1]?.type === "https"
&& i[1]?.monitor?.enabled
)
2024-09-06 08:45:32 +02:00
.map((instance) => {
2024-09-07 06:17:03 +02:00
const monitor = instance[1].monitor as monitor;
2021-11-30 21:55:26 +01:00
return {
name: instance[0],
url: instance[1].uri,
2024-09-07 06:17:03 +02:00
uptime: monitor.uptime || 0,
down: monitor.down ?? false,
created_at: monitor.created_at,
2021-11-30 21:55:26 +01:00
}
});
2021-11-30 21:55:26 +01:00
// reliability and sanity checks
const reliableCheck = mapped
.filter(instance => {
2024-09-07 06:17:03 +02:00
const uptime = instance.uptime > 80 && !instance.down;
const nameIncluded = instance.url.includes(instance.name);
const ninetyDays = 90 * 24 * 60 * 60 * 1000;
const ninetyDaysAgo = new Date(Date.now() - ninetyDays);
const createdAt = new Date(instance.created_at).getTime() < ninetyDaysAgo.getTime();
return uptime && nameIncluded && createdAt;
2021-11-30 21:55:26 +01:00
})
2024-09-07 06:17:03 +02:00
export const getInvidiousList = (): string[] =>
reliableCheck.map(instance => instance.name).sort()