mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-11 00:32:38 +02:00
Add use podcasts
This commit is contained in:
parent
666ea87a9d
commit
13342eb823
3 changed files with 43 additions and 1 deletions
30
surfsense_web/hooks/use-podcast.ts
Normal file
30
surfsense_web/hooks/use-podcast.ts
Normal 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 };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue