feat: add fediseer support
This commit is contained in:
1 parent
c300d73d75
commit
8590377082
4 files changed
+174
-3
No files matched your search
@@ -16,6 +16,7 @@
|
|||||||
Icon,
|
Icon,
|
||||||
Newspaper,
|
Newspaper,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
|
ServerStack,
|
||||||
Share,
|
Share,
|
||||||
Trash,
|
Trash,
|
||||||
UserCircle,
|
UserCircle,
|
||||||
@@ -41,6 +42,8 @@
|
|||||||
Modal,
|
Modal,
|
||||||
Spinner,
|
Spinner,
|
||||||
} from 'mono-svelte'
|
} from 'mono-svelte'
|
||||||
|
import { fediseer, type Data } from '$lib/fediseer/fediseer'
|
||||||
|
import Fediseer from '$lib/fediseer/Fediseer.svelte'
|
||||||
|
|
||||||
export let post: PostView
|
export let post: PostView
|
||||||
|
|
||||||
@@ -49,8 +52,16 @@
|
|||||||
let editing = false
|
let editing = false
|
||||||
let saving = false
|
let saving = false
|
||||||
export let debug: boolean = false
|
export let debug: boolean = false
|
||||||
|
|
||||||
|
let fediseerOpen = false
|
||||||
|
let fediseerData: Data | null = null
|
||||||
|
let fediseerLoading = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if fediseerData}
|
||||||
|
<Fediseer bind:open={fediseerOpen} data={fediseerData} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if editing}
|
{#if editing}
|
||||||
<Modal bind:open={editing}>
|
<Modal bind:open={editing}>
|
||||||
<h1 slot="title" class="text-2xl font-bold">Editing post</h1>
|
<h1 slot="title" class="text-2xl font-bold">Editing post</h1>
|
||||||
@@ -166,6 +177,28 @@
|
|||||||
<Icon src={Newspaper} width={16} mini />
|
<Icon src={Newspaper} width={16} mini />
|
||||||
<span>{post.community.title}</span>
|
<span>{post.community.title}</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
<MenuButton
|
||||||
|
loading={fediseerLoading}
|
||||||
|
on:click={async (e) => {
|
||||||
|
e.stopImmediatePropagation()
|
||||||
|
|
||||||
|
fediseerLoading = true
|
||||||
|
const data = await fediseer.getInstanceInfo(new URL(post.community.actor_id).hostname)
|
||||||
|
console.log(data)
|
||||||
|
fediseerData = data
|
||||||
|
fediseerOpen = true
|
||||||
|
fediseerLoading = false
|
||||||
|
|
||||||
|
return
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{#if fediseerLoading}
|
||||||
|
<Spinner width={14} />
|
||||||
|
{:else}
|
||||||
|
<Icon src={ServerStack} width={16} mini />
|
||||||
|
{/if}
|
||||||
|
<span>{new URL(post.community.actor_id).hostname}</span>
|
||||||
|
</MenuButton>
|
||||||
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
|
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
|
||||||
<MenuDivider>Actions</MenuDivider>
|
<MenuDivider>Actions</MenuDivider>
|
||||||
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
||||||
@@ -181,7 +214,7 @@
|
|||||||
post.read = await markAsRead(post.post, !post.read, $profile.jwt)
|
post.read = await markAsRead(post.post, !post.read, $profile.jwt)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon src={post.read ? EyeSlash : Eye} width={16} mini />
|
<Icon slot="prefix" src={post.read ? EyeSlash : Eye} width={16} mini />
|
||||||
Mark as {post.read ? 'Unread' : 'Read'}
|
Mark as {post.read ? 'Unread' : 'Read'}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col {$$props.class}">
|
<div class="flex flex-col {$$props.class}">
|
||||||
<span class="text-slate-600 dark:text-zinc-400 text-xs">{label}</span>
|
<span class="text-slate-600 dark:text-zinc-400 text-xs {$$props.labelClass}">{label}</span>
|
||||||
<span class="text-base">
|
<span class="text-base {$$props.contentClass}">
|
||||||
{#if formatted}
|
{#if formatted}
|
||||||
<FormattedNumber number={Number(content)} />
|
<FormattedNumber number={Number(content)} />
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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')
|
||||||
Reference in new issue
Block a user