Attic is a cozy space with lofty ambitions. attic.social
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

avatar route

+57 -34
+1 -1
src/app.d.ts
··· 1 - import type { OAuthClient } from "@atcute/oauth-node-client"; 2 1 import type { PrivateUserData } from "$lib/valibot.ts"; 2 + import type { OAuthClient } from "@atcute/oauth-node-client"; 3 3 4 4 // See https://svelte.dev/docs/kit/types#app.d.ts 5 5 // for information about these interfaces
+2 -2
src/hooks.server.ts
··· 1 - import type { Handle } from "@sveltejs/kit"; 2 1 import { dev } from "$app/environment"; 3 - import { sequence } from "@sveltejs/kit/hooks"; 4 2 import { restoreSession } from "$lib/server/session.ts"; 3 + import type { Handle } from "@sveltejs/kit"; 4 + import { sequence } from "@sveltejs/kit/hooks"; 5 5 6 6 /** 7 7 * {@link https://svelte.dev/docs/cli/devtools-json}
+9 -9
src/lib/server/oauth.ts
··· 1 - import type { Cookies } from "@sveltejs/kit"; 1 + import { dev } from "$app/environment"; 2 + import { env } from "$env/dynamic/private"; 3 + import { 4 + OAUTH_COOKIE_PREFIX, 5 + OAUTH_MAX_AGE, 6 + SESSION_MAX_AGE, 7 + } from "$lib/server/constants.ts"; 8 + import { decryptText, encryptText } from "$lib/server/crypto.ts"; 2 9 import { 3 10 CompositeDidDocumentResolver, 4 11 CompositeHandleResolver, ··· 9 16 } from "@atcute/identity-resolver"; 10 17 import { NodeDnsHandleResolver } from "@atcute/identity-resolver-node"; 11 18 import { OAuthClient, scope, type Store } from "@atcute/oauth-node-client"; 12 - import { decryptText, encryptText } from "$lib/server/crypto.ts"; 13 - import { 14 - OAUTH_COOKIE_PREFIX, 15 - OAUTH_MAX_AGE, 16 - SESSION_MAX_AGE, 17 - } from "$lib/server/constants.ts"; 18 - import { env } from "$env/dynamic/private"; 19 - import { dev } from "$app/environment"; 19 + import type { Cookies } from "@sveltejs/kit"; 20 20 import { Buffer } from "node:buffer"; 21 21 22 22 class CookieStore<K extends string, V> implements Store<K, V> {
+7 -7
src/lib/server/session.ts
··· 1 - import type { RequestEvent } from "@sveltejs/kit"; 2 - import { Client } from "@atcute/client"; 3 - import { isHandle } from "@atcute/lexicons/syntax"; 4 - import { createOAuthClient } from "$lib/server/oauth.ts"; 5 - import { decryptText } from "$lib/server/crypto.ts"; 1 + import { dev } from "$app/environment"; 2 + import { env } from "$env/dynamic/private"; 6 3 import { 7 4 HANDLE_COOKIE, 8 5 OAUTH_MAX_AGE, 9 6 SESSION_COOKIE, 10 7 } from "$lib/server/constants.ts"; 8 + import { decryptText } from "$lib/server/crypto.ts"; 9 + import { createOAuthClient } from "$lib/server/oauth.ts"; 11 10 import { parsePublicUser, type PublicUserData } from "$lib/valibot.ts"; 12 - import { dev } from "$app/environment"; 13 - import { env } from "$env/dynamic/private"; 11 + import { Client } from "@atcute/client"; 12 + import { isHandle } from "@atcute/lexicons/syntax"; 13 + import type { RequestEvent } from "@sveltejs/kit"; 14 14 15 15 /** 16 16 * Logout
+3 -3
src/lib/valibot.ts
··· 1 - import * as v from "valibot"; 2 1 import { Client } from "@atcute/client"; 3 - import { OAuthSession } from "@atcute/oauth-node-client"; 4 - import { isDid, isHandle } from "@atcute/lexicons/syntax"; 5 2 import type { Did, Handle } from "@atcute/lexicons"; 3 + import { isDid, isHandle } from "@atcute/lexicons/syntax"; 4 + import { OAuthSession } from "@atcute/oauth-node-client"; 5 + import * as v from "valibot"; 6 6 7 7 const UserSchema = { 8 8 did: v.custom<Did>(isDid, "invalid did"),
+1 -1
src/routes/+layout.server.ts
··· 1 - import type { LayoutServerLoad } from "./$types"; 2 1 import type { PublicUserData } from "$lib/valibot.ts"; 2 + import type { LayoutServerLoad } from "./$types.d.ts"; 3 3 4 4 export const load: LayoutServerLoad = (event) => { 5 5 let user: PublicUserData | undefined = undefined;
+1 -1
src/routes/+page.server.ts
··· 1 - import { type Actions, fail, redirect } from "@sveltejs/kit"; 2 1 import { destroySession, startSession } from "$lib/server/session.ts"; 2 + import { type Actions, fail, redirect } from "@sveltejs/kit"; 3 3 4 4 export const actions = { 5 5 logout: async (event) => {
+2 -1
src/routes/+page.svelte
··· 1 1 <script lang="ts"> 2 - import type { PageProps } from "./$types"; 2 + import type { PageProps } from "./$types.d.ts"; 3 3 let { data, form }: PageProps = $props(); 4 4 5 5 let handle = $derived(form?.handle ?? ""); 6 6 </script> 7 7 8 8 {#if data.user} 9 + <img alt="avatar" src="/avatar/{data.user.did}" width="50" height="50" /> 9 10 <h2>Hello, {data.user.displayName}!</h2> 10 11 <form method="POST" action="?/logout"> 11 12 <button type="submit">Logout</button>
+22
src/routes/avatar/[did]/+server.ts
··· 1 + import { AppBskyActorGetProfile } from "@atcute/bluesky"; 2 + import { ok } from "@atcute/client"; 3 + import { isDid } from "@atcute/lexicons/syntax"; 4 + import { error } from "@sveltejs/kit"; 5 + import type { RequestHandler } from "./$types.d.ts"; 6 + 7 + export const GET: RequestHandler = async (event) => { 8 + const { params: { did }, locals: { user } } = event; 9 + if (user === undefined || isDid(did) === false) { 10 + error(404); 11 + } 12 + try { 13 + const profile = await ok(user.client.call(AppBskyActorGetProfile, { 14 + params: { actor: did }, 15 + })); 16 + const avatar = new URL(profile.avatar!); 17 + return event.fetch(avatar); 18 + } catch (err) { 19 + console.log(err); 20 + error(404); 21 + } 22 + };
+9 -9
src/routes/oauth/callback/+server.ts
··· 1 - import type { RequestHandler } from "./$types"; 2 - import type { OAuthSession } from "@atcute/oauth-node-client"; 1 + import { dev } from "$app/environment"; 2 + import { env } from "$env/dynamic/private"; 3 + import { HANDLE_COOKIE, SESSION_COOKIE } from "$lib/server/constants.ts"; 4 + import { encryptText } from "$lib/server/crypto.ts"; 5 + import { createOAuthClient } from "$lib/server/oauth.ts"; 6 + import type { PublicUserData } from "$lib/valibot.ts"; 3 7 import { AppBskyActorGetProfile } from "@atcute/bluesky"; 4 8 import { Client, ok } from "@atcute/client"; 5 - import { redirect } from "@sveltejs/kit"; 6 - import { createOAuthClient } from "$lib/server/oauth.ts"; 7 - import { encryptText } from "$lib/server/crypto.ts"; 8 - import { HANDLE_COOKIE, SESSION_COOKIE } from "$lib/server/constants.ts"; 9 - import { env } from "$env/dynamic/private"; 10 - import { dev } from "$app/environment"; 11 9 import { isHandle } from "@atcute/lexicons/syntax"; 12 - import type { PublicUserData } from "$lib/valibot.ts"; 10 + import type { OAuthSession } from "@atcute/oauth-node-client"; 11 + import { redirect } from "@sveltejs/kit"; 12 + import type { RequestHandler } from "./$types.d.ts"; 13 13 14 14 export const GET: RequestHandler = async (event) => { 15 15 const { url, cookies } = event;