feat: implement find_all method in ChannelRepository and update related services and routes for public access
This commit is contained in:
@@ -27,14 +27,12 @@ export async function GET(
|
||||
const { channelId } = await params;
|
||||
const token = request.nextUrl.searchParams.get("token");
|
||||
|
||||
if (!token) {
|
||||
return new Response(null, { status: 401 });
|
||||
}
|
||||
|
||||
let res: Response;
|
||||
try {
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
res = await fetch(`${API_URL}/channels/${channelId}/stream`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
headers,
|
||||
redirect: "manual",
|
||||
});
|
||||
} catch {
|
||||
|
||||
@@ -9,8 +9,8 @@ export function useChannels() {
|
||||
const { token } = useAuthContext();
|
||||
return useQuery({
|
||||
queryKey: ["channels"],
|
||||
queryFn: () => api.channels.list(token!),
|
||||
enabled: !!token,
|
||||
// Public endpoint — no token needed for TV viewing
|
||||
queryFn: () => api.channels.list(token ?? ""),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ export function useCurrentBroadcast(channelId: string) {
|
||||
const { token } = useAuthContext();
|
||||
return useQuery({
|
||||
queryKey: ["broadcast", channelId],
|
||||
queryFn: () => api.schedule.getCurrentBroadcast(channelId, token!),
|
||||
enabled: !!token && !!channelId,
|
||||
queryFn: () => api.schedule.getCurrentBroadcast(channelId, token ?? ""),
|
||||
enabled: !!channelId,
|
||||
refetchInterval: 30_000,
|
||||
retry: false,
|
||||
});
|
||||
@@ -96,7 +96,7 @@ export function useEpg(channelId: string, from?: string, until?: string) {
|
||||
const { token } = useAuthContext();
|
||||
return useQuery({
|
||||
queryKey: ["epg", channelId, from, until],
|
||||
queryFn: () => api.schedule.getEpg(channelId, token!, from, until),
|
||||
enabled: !!token && !!channelId,
|
||||
queryFn: () => api.schedule.getEpg(channelId, token ?? "", from, until),
|
||||
enabled: !!channelId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,7 +106,8 @@ export function useStreamUrl(
|
||||
return useQuery({
|
||||
queryKey: ["stream-url", channelId, slotId],
|
||||
queryFn: async (): Promise<string | null> => {
|
||||
const params = new URLSearchParams({ token: token! });
|
||||
const params = new URLSearchParams();
|
||||
if (token) params.set("token", token);
|
||||
const res = await fetch(`/api/stream/${channelId}?${params}`, {
|
||||
cache: "no-store",
|
||||
});
|
||||
@@ -115,7 +116,7 @@ export function useStreamUrl(
|
||||
const { url } = await res.json();
|
||||
return url as string;
|
||||
},
|
||||
enabled: !!channelId && !!token && !!slotId,
|
||||
enabled: !!channelId && !!slotId,
|
||||
staleTime: Infinity,
|
||||
retry: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user