fix: create the bsky client in the create note route
All checks were successful
create archive with lfs / tag (push) Successful in 9s

This commit is contained in:
dusk 2024-10-30 23:14:45 +09:00
parent a2ac850abb
commit 89d936b96a
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
2 changed files with 11 additions and 6 deletions

View File

@ -21,9 +21,9 @@ export const scopeCookies = (cookies: Cookies, path: string) => {
export const visitCountFile = `${env.WEBSITE_DATA_DIR}/visitcount`
export const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));
const loginToBsky = () => {
export const loginToBsky = async () => {
const creds = new CredentialSession(new URL("https://bsky.social"))
creds.login({identifier: 'gaze.systems', password: env.BSKY_PASSWORD ?? "" })
await creds.login({identifier: 'gaze.systems', password: env.BSKY_PASSWORD ?? "" })
return new Agent(creds)
}
export const bskyClient = writable(loginToBsky())
export const bskyClient = writable<null | Agent>(null)

View File

@ -1,6 +1,6 @@
import { env } from '$env/dynamic/private';
import { PUBLIC_BASE_URL } from '$env/static/public';
import { bskyClient } from '$lib';
import { bskyClient, loginToBsky } from '$lib';
import { createNote } from '$lib/notes.js';
import { get } from 'svelte/store';
@ -20,7 +20,12 @@ 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 get(bskyClient).post({text: `${noteData.content} (${PUBLIC_BASE_URL}/log?id=${noteId})`})
let client = get(bskyClient)
if (client === null) {
client = await loginToBsky()
bskyClient.set(client)
}
await client.post({text: `${noteData.content} (${PUBLIC_BASE_URL}/log?id=${noteId})`})
}
// send back created note id
return new Response(JSON.stringify({ noteId }), {