import { postHashtags, retrieveHashtagsFromGweet } from "@/components/trends"; import { postMedia } from "./post-media"; export const postGweet = async ({ content, files, userId, replyToGweetId, quoteGweetId, }: { content: string; files: File[]; userId: string; replyToGweetId?: string | null; quoteGweetId?: string | null; }) => { const gweet = { content, userId, ...(replyToGweetId && { replyToGweetId }), ...(quoteGweetId && { quoteGweetId }), }; try { const data = await fetch('/api/gweets', { method: 'POST', body: JSON.stringify(gweet) }).then((result) => result.json()) if (files.length > 0) { await postMedia({ files, gweet_id: data.id }); } const hashtags = retrieveHashtagsFromGweet(content); if (hashtags) await postHashtags(hashtags); return data; } catch (error: any) { return error.response.data; } };