Files
TeleWave/frontend/src/features/admin/shows/api.ts
T

114 lines
4.3 KiB
TypeScript

import { apiRequest } from '@/shared/api/client'
import type {
CreatedIdResponse,
MetadataCandidate,
MissingEpisodesReport,
ShowAudience,
ShowDto,
ShowKind,
ShowSummaryDto,
} from '@/shared/api/types'
export function listShows(genreId?: string) {
const query = genreId ? `?${new URLSearchParams({ genreId }).toString()}` : ''
return apiRequest<ShowSummaryDto[]>(`/admin/shows${query}`)
}
export function getShow(id: string) {
return apiRequest<ShowDto>(`/admin/shows/${id}`)
}
export function createShow(body: {
name: string
kind: ShowKind
description?: string
originalName?: string
audience?: ShowAudience | null
}) {
return apiRequest<CreatedIdResponse>('/admin/shows', { method: 'POST', body })
}
/** `null` — снять проставленный рейтинг. */
export function setShowAudience(id: string, audience: ShowAudience | null) {
return apiRequest<void>(`/admin/shows/${id}/audience`, { method: 'PUT', body: { audience } })
}
/** Полностью заменяет набор жанров шоу; основной — primaryGenreId (иначе первый в списке). */
export function setShowGenres(id: string, genreIds: string[], primaryGenreId: string | null) {
return apiRequest<void>(`/admin/shows/${id}/genres`, {
method: 'PUT',
body: { genreIds, primaryGenreId },
})
}
export function renameShow(id: string, name: string) {
return apiRequest<void>(`/admin/shows/${id}/name`, { method: 'PUT', body: { name } })
}
export function setShowOriginalName(id: string, originalName: string | null) {
return apiRequest<void>(`/admin/shows/${id}/original-name`, {
method: 'PUT',
body: { originalName },
})
}
export function deleteShow(id: string) {
return apiRequest<void>(`/admin/shows/${id}`, { method: 'DELETE' })
}
export function addEpisode(showId: string, mediaAssetId: string) {
return apiRequest<CreatedIdResponse>(`/admin/shows/${showId}/episodes`, {
method: 'POST',
body: { mediaAssetId },
})
}
export function removeEpisode(showId: string, episodeId: string) {
return apiRequest<void>(`/admin/shows/${showId}/episodes/${episodeId}`, { method: 'DELETE' })
}
// ── Метаданные ────────────────────────────────────────────────────────────
export function getMetadataProviders() {
return apiRequest<string[]>('/admin/metadata/providers')
}
/** `kind` определяет, среди чего искать: у TMDb сериалы и фильмы — разные пространства id. */
export function searchMetadata(provider: string, query: string, kind: ShowKind) {
const q = new URLSearchParams({ provider, query, kind })
return apiRequest<MetadataCandidate[]>(`/admin/metadata/search?${q.toString()}`)
}
export function applyMetadata(showId: string, provider: string, externalId: string) {
return apiRequest<void>(`/admin/metadata/shows/${showId}/apply`, {
method: 'POST',
body: { provider, externalId },
})
}
export function updateMetadata(showId: string, body: { description: string | null; year: number | null }) {
return apiRequest<void>(`/admin/metadata/shows/${showId}`, { method: 'PUT', body })
}
export function clearMetadata(showId: string) {
return apiRequest<void>(`/admin/metadata/shows/${showId}`, { method: 'DELETE' })
}
/** Привязать/снять постер шоу по ссылке на изображение из реестра (null — отвязать). */
export function setShowPoster(showId: string, imageId: string | null) {
return apiRequest<void>(`/admin/metadata/shows/${showId}/poster-image`, {
method: 'PUT',
body: { imageId },
})
}
/** Довыгрузить метаданные серий из привязанного источника. Возвращает число обновлённых. */
export function refreshEpisodesMetadata(showId: string) {
return apiRequest<number>(`/admin/metadata/shows/${showId}/refresh-episodes`, { method: 'POST' })
}
/** Отчёт: каких серий не хватает в загруженных сезонах (по данным источника). */
export function findMissingEpisodes(showId: string) {
return apiRequest<MissingEpisodesReport>(`/admin/metadata/shows/${showId}/missing-episodes`)
}