feat: implement authentication context and hooks for user management

- Add AuthContext to manage user authentication state and token storage.
- Create hooks for login, registration, and logout functionalities.
- Implement dashboard layout with authentication check and loading state.
- Enhance dashboard page with channel management features including create, edit, and delete channels.
- Integrate API calls for channel operations and current broadcast retrieval.
- Add stream URL resolution via server-side API route to handle redirects.
- Update TV page to utilize new hooks for channel and broadcast management.
- Refactor components for better organization and user experience.
- Update application metadata for improved branding.
This commit is contained in:
2026-03-11 19:32:49 +01:00
parent 01108aa23e
commit 8d8d320a02
22 changed files with 2118 additions and 173 deletions

118
k-tv-frontend/lib/types.ts Normal file
View File

@@ -0,0 +1,118 @@
// API response and request types matching the backend DTOs
export type ContentType = "movie" | "episode" | "short";
export type FillStrategy = "best_fit" | "sequential" | "random";
export interface MediaFilter {
content_type?: ContentType | null;
genres: string[];
decade?: number | null;
tags: string[];
min_duration_secs?: number | null;
max_duration_secs?: number | null;
collections: string[];
}
export interface RecyclePolicy {
cooldown_days?: number | null;
cooldown_generations?: number | null;
min_available_ratio: number;
}
export type BlockContent =
| { type: "algorithmic"; filter: MediaFilter; strategy: FillStrategy }
| { type: "manual"; items: string[] };
export interface ProgrammingBlock {
id: string;
name: string;
/** "HH:MM:SS" */
start_time: string;
duration_mins: number;
content: BlockContent;
}
export interface ScheduleConfig {
blocks: ProgrammingBlock[];
}
// Auth
export interface TokenResponse {
access_token: string;
token_type: string;
expires_in: number;
}
export interface UserResponse {
id: string;
email: string;
created_at: string;
}
// Channels
export interface ChannelResponse {
id: string;
owner_id: string;
name: string;
description?: string | null;
timezone: string;
schedule_config: ScheduleConfig;
recycle_policy: RecyclePolicy;
created_at: string;
updated_at: string;
}
export interface CreateChannelRequest {
name: string;
timezone: string;
description?: string;
}
export interface UpdateChannelRequest {
name?: string;
description?: string;
timezone?: string;
schedule_config?: ScheduleConfig;
recycle_policy?: RecyclePolicy;
}
// Media & Schedule
export interface MediaItemResponse {
id: string;
title: string;
content_type: ContentType;
duration_secs: number;
description?: string | null;
genres: string[];
tags: string[];
year?: number | null;
}
export interface ScheduledSlotResponse {
id: string;
block_id: string;
item: MediaItemResponse;
/** RFC3339 */
start_at: string;
/** RFC3339 */
end_at: string;
}
export interface ScheduleResponse {
id: string;
channel_id: string;
generation: number;
generated_at: string;
valid_from: string;
valid_until: string;
slots: ScheduledSlotResponse[];
}
export interface CurrentBroadcastResponse {
slot: ScheduledSlotResponse;
offset_secs: number;
}