Refactor ShowMetadataCard and API: remove obsolete poster upload functionality, streamline metadata saving process into a single mutation, and enhance UI for original name input. Update related state management and error handling for improved user experience.

This commit is contained in:
Leonid Pershin
2026-07-25 12:03:25 +03:00
parent 7efd616c29
commit afe6cc24aa
2 changed files with 22 additions and 87 deletions
+1 -27
View File
@@ -1,4 +1,4 @@
import { apiRequest, getAccessToken, HttpError } from '@/shared/api/client'
import { apiRequest } from '@/shared/api/client'
import type {
CreatedIdResponse,
MetadataCandidate,
@@ -84,29 +84,3 @@ export function setShowPoster(showId: string, imageId: string | null) {
export function refreshEpisodesMetadata(showId: string) {
return apiRequest<number>(`/admin/metadata/shows/${showId}/refresh-episodes`, { method: 'POST' })
}
/** Загрузка постера вручную (сырое тело, имя в query — как uploadMedia). */
export function uploadPoster(showId: string, file: File): Promise<void> {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
const q = new URLSearchParams({ fileName: file.name })
xhr.open('PUT', `/api/admin/metadata/shows/${showId}/poster?${q.toString()}`)
const token = getAccessToken()
if (token) xhr.setRequestHeader('Authorization', `Bearer ${token}`)
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) resolve()
else {
let detail = `HTTP ${xhr.status}`
try {
const p = JSON.parse(xhr.responseText) as { detail?: string; title?: string }
detail = p.detail ?? p.title ?? detail
} catch {
/* пусто */
}
reject(new HttpError({ detail }, xhr.status))
}
}
xhr.onerror = () => reject(new HttpError({ title: 'Network error' }, 0))
xhr.send(file)
})
}