tangled
alpha
login
or
join now
moth11.net
/
xcvr
2
fork
atom
frontend for xcvr appview
2
fork
atom
overview
issues
pulls
pipelines
add ban page
moth11.net
5 months ago
7128ec49
8d0cd60e
+54
2 changed files
expand all
collapse all
unified
split
src
routes
b
[id]
+page.svelte
+page.ts
+27
src/routes/b/[id]/+page.svelte
···
1
1
+
<script lang="ts">
2
2
+
import type { PageProps } from "./$types";
3
3
+
import { dumbAbsoluteTimestamp, smartAbsoluteTimestamp } from "$lib/utils";
4
4
+
let { data }: PageProps = $props();
5
5
+
const fetchhandle = async (did: string) => {
6
6
+
return fetch(`https://plc.directory/${did}`).then((res) => res.json());
7
7
+
};
8
8
+
</script>
9
9
+
10
10
+
{#if data.ban}
11
11
+
{#await fetchhandle(data.ban.did)}
12
12
+
fetching handle
13
13
+
{:then result}
14
14
+
{result.alsoKnownAs[0]}
15
15
+
{:catch}
16
16
+
error fetching handle
17
17
+
{/await}
18
18
+
({data.ban.did}) was banned {smartAbsoluteTimestamp(data.ban.bannedAt)}
19
19
+
{#if data.ban.reason}
20
20
+
for {data.ban.reason}.
21
21
+
{/if}
22
22
+
{#if data.ban.till}
23
23
+
the ban will end on {dumbAbsoluteTimestamp(data.ban.till)}.
24
24
+
{/if}
25
25
+
{:else}
26
26
+
i can't find ban
27
27
+
{/if}
+27
src/routes/b/[id]/+page.ts
···
1
1
+
import type { PageLoad } from './$types'
2
2
+
3
3
+
export const load: PageLoad = async ({ params, fetch }) => {
4
4
+
const base = import.meta.env.VITE_API_URL
5
5
+
const query = `?id=${params.id}`
6
6
+
7
7
+
const fetchSafely = async (url: string) => {
8
8
+
try {
9
9
+
const res = await fetch(url)
10
10
+
return res.ok ? await res.json() : null
11
11
+
} catch {
12
12
+
return null
13
13
+
}
14
14
+
}
15
15
+
16
16
+
const [ban] = await Promise.allSettled([
17
17
+
fetchSafely(`${base}/oauth/ban${query}`),
18
18
+
]).then(results =>
19
19
+
results.map(result =>
20
20
+
result.status === 'fulfilled' ? result.value : null
21
21
+
)
22
22
+
)
23
23
+
24
24
+
return {
25
25
+
ban,
26
26
+
}
27
27
+
}