diff options
author | Michael C <[email protected]> | 2024-09-07 00:17:03 -0400 |
---|---|---|
committer | Michael C <[email protected]> | 2024-09-07 00:17:03 -0400 |
commit | 20d538b6e9104770d85e3acea35fe07d09163be5 (patch) | |
tree | df5d5c5f4ca38bd05840a285a4a81139e9c092d4 /ci/invidiousCI.ts | |
parent | 36a5bc105b0df4402e7549e21713e3c3b5374b01 (diff) | |
download | SponsorBlock-20d538b6e9104770d85e3acea35fe07d09163be5.tar.gz SponsorBlock-20d538b6e9104770d85e3acea35fe07d09163be5.zip |
fully typed updown response
Diffstat (limited to 'ci/invidiousCI.ts')
-rw-r--r-- | ci/invidiousCI.ts | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/ci/invidiousCI.ts b/ci/invidiousCI.ts index 0782288d..d97250d0 100644 --- a/ci/invidiousCI.ts +++ b/ci/invidiousCI.ts @@ -1,27 +1,34 @@ -import { InvidiousInstance, instanceMap } from "./invidiousType" +import { InvidiousInstance, monitor } from "./invidiousType" import * as data from "../ci/invidious_instances.json"; // only https servers -const mapped: instanceMap = (data as InvidiousInstance[]) - .filter((i) => i[1]?.type === "https") +const mapped = (data as InvidiousInstance[]) + .filter((i) => + i[1]?.type === "https" + && i[1]?.monitor?.enabled + ) .map((instance) => { + const monitor = instance[1].monitor as monitor; return { name: instance[0], url: instance[1].uri, - uptime: instance[1].monitor?.uptime || 0, - down: instance[1].monitor?.down ?? false + uptime: monitor.uptime || 0, + down: monitor.down ?? false, + created_at: monitor.created_at, } }); // reliability and sanity checks const reliableCheck = mapped .filter(instance => { - return instance.uptime > 80 && !instance.down; + 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; }) - // url includes name - .filter(instance => instance.url.includes(instance.name)); -export function getInvidiousList(): string[] { - return reliableCheck.map(instance => instance.name).sort() -}
\ No newline at end of file +export const getInvidiousList = (): string[] => + reliableCheck.map(instance => instance.name).sort()
\ No newline at end of file |