Add maintenance management features: implement maintenance endpoints in the API, enhance media upload handling to skip duplicate files, and update frontend routes and translations for maintenance operations.
This commit is contained in:
@@ -64,15 +64,31 @@ export function MediaPanel() {
|
||||
const deleteMutation = useMutation({ mutationFn: deleteMedia, onSuccess: invalidate, onError })
|
||||
|
||||
// Массовая загрузка: файлы отправляются по одному (обработка всё равно в очереди по одному),
|
||||
// прогресс — «текущий/всего · %». Список обновляется после каждого файла.
|
||||
// прогресс — «текущий/всего · %». Дубликаты по имени пропускаются заранее (сервер тоже отклонит).
|
||||
const handleFiles = async (files: FileList) => {
|
||||
const list = Array.from(files)
|
||||
|
||||
let existing = new Set<string>()
|
||||
try {
|
||||
const all = await listMedia({
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
statuses: ['Pending', 'Processing', 'Ready'],
|
||||
})
|
||||
existing = new Set(all.items.map((a) => a.originalFileName))
|
||||
} catch {
|
||||
// Не удалось получить список — положимся на серверную проверку дубликатов.
|
||||
}
|
||||
|
||||
const toUpload = list.filter((f) => !existing.has(f.name))
|
||||
const skipped = list.length - toUpload.length
|
||||
|
||||
let uploaded = 0
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
setUpload({ current: i + 1, total: list.length, percent: 0 })
|
||||
for (let i = 0; i < toUpload.length; i++) {
|
||||
setUpload({ current: i + 1, total: toUpload.length, percent: 0 })
|
||||
try {
|
||||
await uploadMedia(list[i], (percent) =>
|
||||
setUpload({ current: i + 1, total: list.length, percent }),
|
||||
await uploadMedia(toUpload[i], (percent) =>
|
||||
setUpload({ current: i + 1, total: toUpload.length, percent }),
|
||||
)
|
||||
uploaded++
|
||||
invalidate()
|
||||
@@ -83,6 +99,7 @@ export function MediaPanel() {
|
||||
setUpload(null)
|
||||
if (fileInput.current) fileInput.current.value = ''
|
||||
if (uploaded > 0) toast.success(t('admin.media.uploadedCount', { count: uploaded }))
|
||||
if (skipped > 0) toast.message(t('admin.media.skippedDuplicates', { count: skipped }))
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user