From fa4bd81dd69dc6c6d51fd724fd4f621dd069bfda Mon Sep 17 00:00:00 2001 From: zeudev Date: Tue, 12 May 2026 15:29:14 -0700 Subject: [PATCH] implement /live --- astro.config.mjs | 2 +- src/actions/index.ts | 54 ++++++++++++++++++++++++ src/components/SiteLayout.astro | 2 +- src/components/StreamplaceChat.svelte | 59 +++++++++++++++++++++++++++ src/lib/utils.ts | 2 + src/pages/live.astro | 46 +++++++++++++++++++++ src/pages/stream.astro | 6 --- 7 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 src/actions/index.ts create mode 100644 src/components/StreamplaceChat.svelte create mode 100644 src/pages/live.astro delete mode 100644 src/pages/stream.astro diff --git a/astro.config.mjs b/astro.config.mjs index 4986d02..2414bff 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -19,7 +19,7 @@ export default defineConfig({ "applicationName": "Zeu's Personal Site", "applicationDomain": "https://zeu.dev", scopes: [ - "repo:place.stream.chat.message?action=create" + "include:place.stream.authFull", ] }) ], diff --git a/src/actions/index.ts b/src/actions/index.ts new file mode 100644 index 0000000..b88e7ab --- /dev/null +++ b/src/actions/index.ts @@ -0,0 +1,54 @@ +import { z } from "astro/zod"; +import { ActionError, defineAction } from "astro:actions"; +import { getPdsAgent } from "@fujocoded/authproto/helpers"; +import { TID } from "@atproto/common-web"; + +export const server = { + sendChatMessage: defineAction({ + accept: "form", + input: z.object({ + message: z.string().optional() + }), + handler: async (input, context) => { + console.log({ input }); + const loggedInUser = context.locals.loggedInUser; + if (!loggedInUser) { + throw new ActionError({ + code: "UNAUTHORIZED", + message: "You're not logged in!" + }); + } + + const agent = await getPdsAgent({ loggedInUser }); + if (!agent) { + throw new ActionError({ + code: "INTERNAL_SERVER_ERROR", + message: "Something went wrong when connecting to your PDS." + }); + } + + try { + const record = await agent.com.atproto.repo.createRecord({ + repo: loggedInUser.did, + collection: "place.stream.chat.message", + rkey: TID.nextStr(), + record: { + text: input.message, + createdAt: new Date().toISOString(), + streamer: "did:plc:gotnvwkr56ibs33l4hwgfoet", + $type: "place.stream.chat.message" + } + }); + console.log(record); + } + catch (e) { + console.error(e); + console.log("EWRROR"); + throw new ActionError({ + code: "INTERNAL_SERVER_ERROR", + message: "Something went wrong with posting your status to your PDS!" + }) + } + } + }), +} diff --git a/src/components/SiteLayout.astro b/src/components/SiteLayout.astro index c360d0e..89d3255 100644 --- a/src/components/SiteLayout.astro +++ b/src/components/SiteLayout.astro @@ -51,7 +51,7 @@ const loggedInUser = Astro.locals.loggedInUser;

- stream + live

resume diff --git a/src/components/StreamplaceChat.svelte b/src/components/StreamplaceChat.svelte new file mode 100644 index 0000000..001b9fb --- /dev/null +++ b/src/components/StreamplaceChat.svelte @@ -0,0 +1,59 @@ + + + +

👁️ {viewerCount} Viewers

+
+ {#each chat as msg} + + {msg.author.handle} +

{msg.record.text}

+
+ {/each} +
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 42b2bf9..b5d1d89 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -76,5 +76,7 @@ export async function resolveHandle(handle: string) { const response = await fetch(url); const miniDoc = await response.json() as MiniDoc; + handleCache = {...handleCache, [miniDoc.handle]: miniDoc}; + return miniDoc; } diff --git a/src/pages/live.astro b/src/pages/live.astro new file mode 100644 index 0000000..26dae83 --- /dev/null +++ b/src/pages/live.astro @@ -0,0 +1,46 @@ +--- +import { actions } from "astro:actions"; +import SiteLayout from "../components/SiteLayout.astro" +import StreamplaceChat from "../components/StreamplaceChat.svelte"; + +export const prerender = false; +const loggedInUser = Astro.locals.loggedInUser; +const result = Astro.getActionResult(actions.sendChatMessage); +console.log({ result }); +--- + + +
+

Livestream

+ + +
+ {!loggedInUser &&

Login to chat

} +
+ + +
+
+ +
+
+ + diff --git a/src/pages/stream.astro b/src/pages/stream.astro deleted file mode 100644 index bb82da6..0000000 --- a/src/pages/stream.astro +++ /dev/null @@ -1,6 +0,0 @@ ---- -import SiteLayout from "../components/SiteLayout.astro" ---- - - - -- 2.51.2