fix: create the bsky client in the create note route
All checks were successful
create archive with lfs / tag (push) Successful in 9s
All checks were successful
create archive with lfs / tag (push) Successful in 9s
This commit is contained in:
parent
a2ac850abb
commit
89d936b96a
@ -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)
|
||||
|
@ -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 }), {
|
||||
|
Loading…
Reference in New Issue
Block a user