Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
const AUTH_ERROR_MESSAGES: Record<string, string> = {
|
|
|
|
|
|
google_error: 'Google вернул ошибку авторизации',
|
|
|
|
|
|
invalid_state: 'Сессия авторизации устарела, попробуйте снова',
|
|
|
|
|
|
exchange_failed: 'Не удалось обменять код авторизации',
|
|
|
|
|
|
userinfo_failed: 'Не удалось получить данные аккаунта Google',
|
|
|
|
|
|
account_not_allowed: 'Этот Google-аккаунт не разрешён для входа',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function authErrorMessage(code: string): string {
|
|
|
|
|
|
return AUTH_ERROR_MESSAGES[code] ?? 'Неизвестная ошибка авторизации'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
|
|
|
|
|
const res = await fetch(path, {
|
|
|
|
|
|
credentials: 'include',
|
|
|
|
|
|
headers: { 'Content-Type': 'application/json', ...(options.headers ?? {}) },
|
|
|
|
|
|
...options,
|
|
|
|
|
|
})
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
|
let detail = `${res.status}`
|
|
|
|
|
|
try {
|
|
|
|
|
|
const body = await res.json()
|
|
|
|
|
|
detail = body.detail ?? detail
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// ignore
|
|
|
|
|
|
}
|
|
|
|
|
|
throw new Error(detail)
|
|
|
|
|
|
}
|
|
|
|
|
|
return res.json()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface AuthStatus {
|
|
|
|
|
|
authenticated: boolean
|
|
|
|
|
|
connected: boolean
|
|
|
|
|
|
email: string | null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getAuthStatus() {
|
|
|
|
|
|
return request<AuthStatus>('/api/auth/status')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function startGoogleAuth() {
|
|
|
|
|
|
window.location.href = '/api/auth/google/start'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function logout() {
|
|
|
|
|
|
return request<{ ok: boolean }>('/api/auth/logout', { method: 'POST' })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ChannelDto {
|
|
|
|
|
|
id: number
|
|
|
|
|
|
youtube_channel_id: string
|
|
|
|
|
|
title: string
|
|
|
|
|
|
description: string | null
|
|
|
|
|
|
thumbnail_url: string | null
|
|
|
|
|
|
uploads_playlist_id: string | null
|
|
|
|
|
|
subscribed: boolean
|
|
|
|
|
|
last_synced_at: string | null
|
|
|
|
|
|
category_ids: number[]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getChannel(channelId: number) {
|
|
|
|
|
|
return request<ChannelDto>(`/api/channels/${channelId}`)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function listChannels(
|
|
|
|
|
|
params: { search?: string; categoryId?: number; uncategorized?: boolean } = {},
|
|
|
|
|
|
) {
|
|
|
|
|
|
const qs = new URLSearchParams()
|
|
|
|
|
|
if (params.search) qs.set('search', params.search)
|
|
|
|
|
|
if (params.categoryId != null) qs.set('category_id', String(params.categoryId))
|
|
|
|
|
|
if (params.uncategorized) qs.set('uncategorized', 'true')
|
|
|
|
|
|
const suffix = qs.toString() ? `?${qs.toString()}` : ''
|
|
|
|
|
|
return request<ChannelDto[]>(`/api/channels${suffix}`)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function setChannelCategories(channelId: number, categoryIds: number[]) {
|
|
|
|
|
|
return request<ChannelDto>(`/api/channels/${channelId}/categories`, {
|
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
|
body: JSON.stringify({ category_ids: categoryIds }),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-16 19:47:35 +00:00
|
|
|
|
export function unsubscribeChannel(channelId: number) {
|
|
|
|
|
|
return request<ChannelDto>(`/api/channels/${channelId}/unsubscribe`, { method: 'POST' })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
export interface CategoryDto {
|
|
|
|
|
|
id: number
|
|
|
|
|
|
name: string
|
|
|
|
|
|
slug: string
|
|
|
|
|
|
sort_order: number
|
|
|
|
|
|
channel_count: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function listCategories() {
|
|
|
|
|
|
return request<CategoryDto[]>('/api/categories')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function createCategory(name: string) {
|
|
|
|
|
|
return request<CategoryDto>('/api/categories', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
body: JSON.stringify({ name }),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function updateCategory(id: number, name: string) {
|
|
|
|
|
|
return request<CategoryDto>(`/api/categories/${id}`, {
|
|
|
|
|
|
method: 'PATCH',
|
|
|
|
|
|
body: JSON.stringify({ name }),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function deleteCategory(id: number) {
|
|
|
|
|
|
return fetch(`/api/categories/${id}`, { method: 'DELETE', credentials: 'include' }).then((res) => {
|
|
|
|
|
|
if (!res.ok) throw new Error(`${res.status}`)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function reorderCategories(categoryIds: number[]) {
|
|
|
|
|
|
return request<CategoryDto[]>('/api/categories/reorder', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
body: JSON.stringify({ category_ids: categoryIds }),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface SyncStatus {
|
|
|
|
|
|
status: string
|
|
|
|
|
|
started_at?: string
|
|
|
|
|
|
finished_at?: string | null
|
|
|
|
|
|
error?: string | null
|
|
|
|
|
|
running: boolean
|
|
|
|
|
|
[key: string]: unknown
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getSyncStatus() {
|
|
|
|
|
|
return request<{ subscriptions: SyncStatus; videos: SyncStatus }>('/api/sync/status')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function syncSubscriptions() {
|
|
|
|
|
|
return request<SyncStatus>('/api/sync/subscriptions', { method: 'POST' })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function syncVideos() {
|
|
|
|
|
|
return request<SyncStatus>('/api/sync/videos', { method: 'POST' })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface FeedVideoDto {
|
|
|
|
|
|
youtube_video_id: string
|
|
|
|
|
|
title: string
|
|
|
|
|
|
description: string | null
|
|
|
|
|
|
channel: {
|
|
|
|
|
|
id: number
|
|
|
|
|
|
youtube_channel_id: string
|
|
|
|
|
|
title: string
|
|
|
|
|
|
thumbnail_url: string | null
|
|
|
|
|
|
}
|
|
|
|
|
|
thumbnail_url: string | null
|
|
|
|
|
|
published_at: string
|
|
|
|
|
|
duration_seconds: number | null
|
|
|
|
|
|
youtube_url: string
|
|
|
|
|
|
categories: { id: number; name: string }[]
|
|
|
|
|
|
local: {
|
|
|
|
|
|
available: boolean
|
|
|
|
|
|
status: string
|
|
|
|
|
|
progress_percent: number | null
|
|
|
|
|
|
media_url: string | null
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getVideo(youtubeVideoId: string) {
|
|
|
|
|
|
return request<FeedVideoDto>(`/api/videos/${youtubeVideoId}`)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-16 18:56:17 +00:00
|
|
|
|
export interface DownloadJobDto {
|
|
|
|
|
|
status: string
|
|
|
|
|
|
progress_percent: number | null
|
|
|
|
|
|
media_url: string | null
|
|
|
|
|
|
error_message: string | null
|
|
|
|
|
|
requested_at?: string
|
|
|
|
|
|
started_at?: string | null
|
|
|
|
|
|
completed_at?: string | null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function downloadVideo(youtubeVideoId: string) {
|
|
|
|
|
|
return request<DownloadJobDto>(`/api/videos/${youtubeVideoId}/download`, { method: 'POST' })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-16 19:47:35 +00:00
|
|
|
|
export function deleteDownload(youtubeVideoId: string) {
|
|
|
|
|
|
return request<DownloadJobDto>(`/api/videos/${youtubeVideoId}/download`, { method: 'DELETE' })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-16 18:56:17 +00:00
|
|
|
|
export function getDownloadStatus(youtubeVideoId: string) {
|
|
|
|
|
|
return request<DownloadJobDto>(`/api/videos/${youtubeVideoId}/download-status`)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function recheckLocal(youtubeVideoId: string) {
|
|
|
|
|
|
return request<DownloadJobDto>(`/api/videos/${youtubeVideoId}/recheck-local`, { method: 'POST' })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
export function getFeed(
|
|
|
|
|
|
params: { categoryId?: number; uncategorized?: boolean; channelId?: number; cursor?: string } = {},
|
|
|
|
|
|
) {
|
|
|
|
|
|
const qs = new URLSearchParams()
|
|
|
|
|
|
if (params.categoryId != null) qs.set('category_id', String(params.categoryId))
|
|
|
|
|
|
if (params.uncategorized) qs.set('uncategorized', 'true')
|
|
|
|
|
|
if (params.channelId != null) qs.set('channel_id', String(params.channelId))
|
|
|
|
|
|
if (params.cursor) qs.set('cursor', params.cursor)
|
|
|
|
|
|
const suffix = qs.toString() ? `?${qs.toString()}` : ''
|
|
|
|
|
|
return request<{ items: FeedVideoDto[]; next_cursor: string | null }>(`/api/feed${suffix}`)
|
|
|
|
|
|
}
|