-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2095 from mchangrh/inv-ci
fully typed updown response
- Loading branch information
Showing
3 changed files
with
85 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
export const getInvidiousList = (): string[] => | ||
reliableCheck.map(instance => instance.name).sort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,72 @@ | ||
export type InvidiousInstance = [ | ||
string, | ||
{ | ||
flag: string; | ||
region: string; | ||
stats: null | ivStats; | ||
cors: null | boolean; | ||
api: null | boolean; | ||
type: "https" | "http" | "onion" | "i2p"; | ||
uri: string; | ||
monitor: null | monitor; | ||
} | ||
] | ||
|
||
export type instanceMap = { | ||
name: string; | ||
export type monitor = { | ||
token: string; | ||
url: string; | ||
alias: string; | ||
last_status: number; | ||
uptime: number; | ||
down: boolean; | ||
}[] | ||
down_since: null | string; | ||
up_since: null | string; | ||
error: null | string; | ||
period: number; | ||
apdex_t: number; | ||
string_match: string; | ||
enabled: boolean; | ||
published: boolean; | ||
disabled_locations: string[]; | ||
recipients: string[]; | ||
last_check_at: string; | ||
next_check_at: string; | ||
created_at: string; | ||
mute_until: null | string; | ||
favicon_url: string; | ||
custom_headers: Record<string, string>; | ||
http_verb: string; | ||
http_body: string; | ||
ssl: { | ||
tested_at: string; | ||
expires_at: string; | ||
valid: boolean; | ||
error: null | string; | ||
}; | ||
} | ||
|
||
export type InvidiousInstance = [ | ||
string, | ||
{ | ||
uri: string; | ||
type: "https" | "http" | "onion" | "i2p"; | ||
monitor: null | { | ||
uptime: number; | ||
down: boolean; | ||
export type ivStats = { | ||
version: string; | ||
software: { | ||
name: "invidious" | string; | ||
version: string; | ||
branch: "master" | string; | ||
}; | ||
openRegistrations: boolean; | ||
usage: { | ||
users: { | ||
total: number; | ||
activeHalfyear: number; | ||
activeMonth: number; | ||
}; | ||
} | ||
] | ||
}; | ||
metadata: { | ||
updatedAt: number; | ||
lastChannelRefreshedAt: number; | ||
}; | ||
playback: { | ||
totalRequests: number; | ||
successfulRequests: number; | ||
ratio: number; | ||
}; | ||
} |