Add use podcasts

This commit is contained in:
CREDO23 2025-10-23 23:50:45 +02:00 committed by thierryverse
parent 666ea87a9d
commit 13342eb823
3 changed files with 43 additions and 1 deletions

View file

@ -0,0 +1,30 @@
import { useCallback } from "react";
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
export function usePodcast() {
const getPodcastByChatId = useCallback(async (chatId: number) => {
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/podcasts/by-chat/${chatId}`,
{
headers: {
Authorization: `Bearer ${localStorage.getItem("surfsense_bearer_token")}`,
},
method: "GET",
}
);
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.detail || "Failed to fetch podcast");
}
return (await response.json()) as PodcastItem;
} catch (err: any) {
console.error("Error fetching podcast:", err);
throw err;
}
}, []);
return { getPodcastByChatId };
}