From a2ac850abb7f697e8213f31e7c86817394cdaa31 Mon Sep 17 00:00:00 2001 From: dusk Date: Wed, 30 Oct 2024 16:59:38 +0300 Subject: [PATCH] fix: use svelte store to init bsky client --- src/lib/index.ts | 2 +- src/routes/log/create/+server.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index b67102e..acad6b4 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -26,4 +26,4 @@ const loginToBsky = () => { creds.login({identifier: 'gaze.systems', password: env.BSKY_PASSWORD ?? "" }) return new Agent(creds) } -export const bskyClient = loginToBsky() \ No newline at end of file +export const bskyClient = writable(loginToBsky()) \ No newline at end of file diff --git a/src/routes/log/create/+server.ts b/src/routes/log/create/+server.ts index 43182c2..d269a82 100644 --- a/src/routes/log/create/+server.ts +++ b/src/routes/log/create/+server.ts @@ -2,6 +2,7 @@ import { env } from '$env/dynamic/private'; import { PUBLIC_BASE_URL } from '$env/static/public'; import { bskyClient } from '$lib'; import { createNote } from '$lib/notes.js'; +import { get } from 'svelte/store'; export const POST = async ({ request }) => { @@ -19,7 +20,7 @@ export const POST = async ({ request }) => { const noteId = createNote({ content: noteData.content, published }) // bridge to bsky if want to bridge if (noteData.bskyPosse ?? null !== null) { - await bskyClient.post({text: `${noteData.content} (${PUBLIC_BASE_URL}/log?id=${noteId})`}) + await get(bskyClient).post({text: `${noteData.content} (${PUBLIC_BASE_URL}/log?id=${noteId})`}) } // send back created note id return new Response(JSON.stringify({ noteId }), {