feat: add fediseer support

This commit is contained in:
Xylight committed 2024-01-22 20:40:22 -08:00
1 parent c300d73d75
commit 8590377082
4 files changed
+174 -3

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
<script lang="ts">
import { Badge, Modal } from "mono-svelte"
import type { Data } from "./fediseer"
import SectionTitle from "$lib/components/ui/SectionTitle.svelte"
import LabelStat from "$lib/components/ui/LabelStat.svelte"
import Expandable from "$lib/components/ui/Expandable.svelte"
export let open: boolean = false
export let data: Data
</script>
<Modal bind:open title="Fediseer">
<div class="flex flex-col [&>*]:py-2 divide-y divide-slate-300 dark:divide-zinc-800">
<Expandable class="flex flex-col gap-4">
<SectionTitle class="flex gap-2 items-center flex-row" slot="title">
Endorsements <Badge class="w-max h-max" color="green-subtle">{data.endorsements.instances.length}</Badge>
</SectionTitle>
<div class="flex flex-row gap-6 flex-wrap">
{#each data.endorsements.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.endorsement_reasons?.[0] || '👍'}>
</LabelStat>
</div>
{/each}
</div>
</Expandable>
<Expandable class="flex flex-col gap-4">
<SectionTitle class="flex gap-2 items-center flex-row" slot="title">
Guarantees <Badge class="w-max h-max" color="green-subtle">{data.guarantees.instances.length}</Badge>
</SectionTitle>
<div class="flex flex-row gap-6 flex-wrap">
{#each data.guarantees.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.guarantee_reasons?.[0] || '👍'}>
</LabelStat>
</div>
{/each}
</div>
</Expandable>
<Expandable class="flex flex-col gap-4">
<SectionTitle class="flex gap-2 items-center flex-row" slot="title">
Censures <Badge class="w-max h-max" color="red-subtle">{data.censures.instances.length}</Badge>
</SectionTitle>
<div class="flex flex-row gap-6 flex-wrap">
{#each data.censures.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.censure_reasons?.[0] || '👎'}>
</LabelStat>
</div>
{/each}
</div>
</Expandable>
<Expandable class="flex flex-col gap-4">
<SectionTitle class="flex gap-2 items-center flex-row" slot="title">
Hesitations <Badge class="w-max h-max" color="red-subtle">{data.hesitations.instances.length}</Badge>
</SectionTitle>
<div class="flex flex-row gap-6 flex-wrap">
{#each data.hesitations.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.hesitation_reasons?.[0] || '👎'}>
</LabelStat>
</div>
{/each}
</div>
</Expandable>
</div>
</Modal>
+55
View File
@@ -0,0 +1,55 @@
export interface Endorsements {
instances: {
domain: string
endorsement_reasons: string[]
}[]
}
export interface Hesitations {
instances: {
domain: string
hesitation_reasons: string[]
}[]
}
export interface Censures {
instances: {
domain: string
censure_reasons: string[]
}[]
}
export interface Guarantees {
instances: {
domain: string
guarantee_reasons: string[]
}[]
}
export interface Data {
endorsements: Endorsements
hesitations: Hesitations
guarantees: Guarantees
censures: Censures
}
class Fediseer {
url: string
constructor(url: string) {
this.url = url
}
async getInstanceInfo(domain: string): Promise<Data> {
const [endorsements, hesitations, guarantees, censures] = await Promise.all([
fetch(`${this.url}/v1/endorsements/${domain}`).then(r => r.json()) as Promise<Endorsements>,
fetch(`${this.url}/v1/hesitations/${domain}`).then(r => r.json()) as Promise<Hesitations>,
fetch(`${this.url}/v1/guarantees/${domain}`).then(r => r.json()) as Promise<Guarantees>,
fetch(`${this.url}/v1/censures/${domain}`).then(r => r.json()) as Promise<Censures>
])
return { endorsements, hesitations, guarantees, censures }
}
}
export const fediseer = new Fediseer('https://fediseer.com/api')