mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02:00
fix podcast generation
This commit is contained in:
parent
678d8fbbcd
commit
55e5b45a42
26 changed files with 477 additions and 223 deletions
28
surfsense_web/lib/apis/chat-apis.ts
Normal file
28
surfsense_web/lib/apis/chat-apis.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
||||
|
||||
export const fetchChatDetails = async (
|
||||
chatId: string,
|
||||
authToken: string
|
||||
): Promise<ChatDetails | null> => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/${Number(chatId)}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch chat details: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
console.error("Error fetching chat details:", err);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
52
surfsense_web/lib/apis/podcast-apis.ts
Normal file
52
surfsense_web/lib/apis/podcast-apis.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
|
||||
import type { GeneratePodcastRequest } from "@/components/chat/ChatPanel/ChatPanelContainer";
|
||||
|
||||
export const getPodcastByChatId = async (chatId: string, authToken: string) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/podcasts/by-chat/${Number(chatId)}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
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 | null;
|
||||
} catch (err: any) {
|
||||
console.error("Error fetching podcast:", err);
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const generatePodcast = async (request: GeneratePodcastRequest, authToken: string) => {
|
||||
try {
|
||||
const { podcast_title = "SurfSense Podcast" } = request;
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/podcasts/generate/`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ ...request, podcast_title }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.detail || "Failed to generate podcast");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error generating podcast:", error);
|
||||
}
|
||||
};
|
||||
3
surfsense_web/lib/query-client/cache-keys.ts
Normal file
3
surfsense_web/lib/query-client/cache-keys.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const cacheKeys = {
|
||||
activeChat: (chatId: string) => ["activeChat", chatId],
|
||||
};
|
||||
3
surfsense_web/lib/query-client/client.ts
Normal file
3
surfsense_web/lib/query-client/client.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { QueryClient } from "@tanstack/react-query";
|
||||
|
||||
export const queryClient = new QueryClient();
|
||||
13
surfsense_web/lib/query-client/query-client.provider.tsx
Normal file
13
surfsense_web/lib/query-client/query-client.provider.tsx
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
"use client";
|
||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||
import { QueryClientAtomProvider } from "jotai-tanstack-query/react";
|
||||
import { queryClient } from "./client";
|
||||
|
||||
export function ReactQueryClientProvider({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<QueryClientAtomProvider client={queryClient}>
|
||||
{children}
|
||||
<ReactQueryDevtools initialIsOpen={false} />
|
||||
</QueryClientAtomProvider>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue