From 04006bda91a0a5ee2785e21341c40f9ef9ca584b Mon Sep 17 00:00:00 2001 From: dusk Date: Wed, 30 Oct 2024 18:12:43 +0300 Subject: [PATCH] fix: use interface for note create, actually remove tag in bot --- gazebot/src/main.rs | 6 +++--- src/routes/log/create/+server.ts | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gazebot/src/main.rs b/gazebot/src/main.rs index 070663c..8fa7040 100644 --- a/gazebot/src/main.rs +++ b/gazebot/src/main.rs @@ -22,12 +22,12 @@ impl EventHandler for Handler { let mut note_content = msg.content.clone(); const BSKY_TAG: &str = ".nobsky"; - let post_to_bsky = !note_content.contains(BSKY_TAG); - if post_to_bsky { + let no_bsky_posse = note_content.contains(BSKY_TAG); + if no_bsky_posse { note_content = note_content.replace(BSKY_TAG, ""); } - let note_data = json!({"content": note_content.trim(), "bskyPosse": post_to_bsky}); + let note_data = json!({"content": note_content.trim(), "bskyPosse": !no_bsky_posse}); let resp = self .http .post("https://gaze.systems/log/create") diff --git a/src/routes/log/create/+server.ts b/src/routes/log/create/+server.ts index 92f6fc5..d1c1b60 100644 --- a/src/routes/log/create/+server.ts +++ b/src/routes/log/create/+server.ts @@ -4,6 +4,10 @@ import { bskyClient, loginToBsky } from '$lib'; import { createNote } from '$lib/notes.js'; import { get } from 'svelte/store'; +interface NoteData { + content: string, + bskyPosse: boolean, +} export const POST = async ({ request }) => { const token = request.headers.get('authorization') @@ -11,16 +15,13 @@ export const POST = async ({ request }) => { return new Response("rizz failed", { status: 403 }) } // get note data - const noteData = await request.json() + const noteData: NoteData = await request.json() console.log("want to create note with data: ", noteData) - if (noteData.content ?? null === null) { - return new Response("no rizz :(", { status: 400 }) - } // create note const published = Date.now() const noteId = createNote({ content: noteData.content, published }) // bridge to bsky if want to bridge - if (noteData.bskyPosse ?? false) { + if (noteData.bskyPosse) { let client = get(bskyClient) if (client === null) { client = await loginToBsky()