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:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user