From cb1b56f5a0eddbf77446f415f2beda57c8305f85 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 23 Nov 2025 01:12:53 +0700 Subject: wut --- packages/tweetdeck/src/lib/client/twitterClient.ts | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 packages/tweetdeck/src/lib/client/twitterClient.ts (limited to 'packages/tweetdeck/src/lib/client/twitterClient.ts') diff --git a/packages/tweetdeck/src/lib/client/twitterClient.ts b/packages/tweetdeck/src/lib/client/twitterClient.ts new file mode 100644 index 0000000..b8914b5 --- /dev/null +++ b/packages/tweetdeck/src/lib/client/twitterClient.ts @@ -0,0 +1,75 @@ +import { + type TwitterUser, + type TweetList, + type TwitterList, + type TwitterNotification, +} from "../fetching/types"; + +const headers = { "Content-Type": "application/json" }; + +async function postJson( + url: string, + body: Record, +): Promise { + const res = await fetch(url, { + method: "POST", + headers, + body: JSON.stringify(body), + }); + + if (!res.ok) { + const text = await res.text(); + throw new Error(text || `Request failed (${res.status})`); + } + + return (await res.json()) as T; +} + +export const twitterClient = { + own(payload: Record) { + // return postJson(`/api/twitter/our`, payload); + }, + timeline(mode: string, payload: Record) { + console.log("fetching tweets", mode); + return postJson(`/api/twitter/timeline/${mode}`, payload); + }, + lists(payload: Record) { + return postJson("/api/twitter/lists", payload); + }, + notifications(payload: Record) { + return postJson( + "/api/twitter/notifications", + payload, + ); + }, + removeBookmark(payload: Record) { + return postJson<{ status: string }>( + "/api/twitter/bookmarks/remove", + payload, + ); + }, + like(tweetId: string, payload: Record) { + return postJson<{ status: string }>( + `/api/twitter/tweets/${tweetId}/like`, + payload, + ); + }, + retweet(tweetId: string, payload: Record) { + return postJson<{ status: string }>( + `/api/twitter/tweets/${tweetId}/retweet`, + payload, + ); + }, + bookmark(tweetId: string, payload: Record) { + return postJson<{ status: string }>( + `/api/twitter/tweets/${tweetId}/bookmark`, + payload, + ); + }, + reply(tweetId: string, payload: Record) { + return postJson<{ status: string }>( + `/api/twitter/tweets/${tweetId}/reply`, + payload, + ); + }, +}; -- cgit v1.2.3