feat(songs): implement .pro file upload in SongDB page
- Replace placeholder exception with real uploadProFiles() function - POST files to /api/songs/import-pro endpoint - Show success/error toast and refresh song list after import
This commit is contained in:
parent
6c59922e96
commit
11f8681feb
|
|
@ -2,6 +2,7 @@
|
||||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
|
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
|
||||||
import SongEditModal from '@/Components/SongEditModal.vue'
|
import SongEditModal from '@/Components/SongEditModal.vue'
|
||||||
import { Head } from '@inertiajs/vue3'
|
import { Head } from '@inertiajs/vue3'
|
||||||
|
import axios from 'axios'
|
||||||
import { ref, watch, onMounted } from 'vue'
|
import { ref, watch, onMounted } from 'vue'
|
||||||
|
|
||||||
const songs = ref([])
|
const songs = ref([])
|
||||||
|
|
@ -139,11 +140,12 @@ function handleDragLeave() {
|
||||||
isDragging.value = false
|
isDragging.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDrop(e) {
|
async function handleDrop(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
isDragging.value = false
|
isDragging.value = false
|
||||||
uploadError.value = 'ProPresenter-Import (.pro) ist noch nicht verfügbar. Kommt bald!'
|
const droppedFiles = Array.from(e.dataTransfer?.files || [])
|
||||||
setTimeout(() => { uploadError.value = '' }, 4000)
|
if (droppedFiles.length === 0) return
|
||||||
|
await uploadProFiles(droppedFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerFileInput() {
|
function triggerFileInput() {
|
||||||
|
|
@ -151,9 +153,42 @@ function triggerFileInput() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFileSelect() {
|
function handleFileSelect() {
|
||||||
uploadError.value = 'ProPresenter-Import (.pro) ist noch nicht verfügbar. Kommt bald!'
|
const selectedFiles = Array.from(fileInput.value?.files || [])
|
||||||
if (fileInput.value) fileInput.value.value = ''
|
if (fileInput.value) fileInput.value.value = ''
|
||||||
setTimeout(() => { uploadError.value = '' }, 4000)
|
if (selectedFiles.length === 0) return
|
||||||
|
uploadProFiles(selectedFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadProFiles(files) {
|
||||||
|
uploadError.value = ''
|
||||||
|
loading.value = true
|
||||||
|
let successCount = 0
|
||||||
|
let errors = []
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('file', file)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios.post('/api/songs/import-pro', formData, {
|
||||||
|
headers: { 'Content-Type': 'multipart/form-data' },
|
||||||
|
})
|
||||||
|
successCount++
|
||||||
|
} catch (err) {
|
||||||
|
const message = err.response?.data?.message || `Fehler bei "${file.name}"`
|
||||||
|
errors.push(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successCount > 0) {
|
||||||
|
await fetchSongs(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.length > 0) {
|
||||||
|
uploadError.value = errors.join(', ')
|
||||||
|
setTimeout(() => { uploadError.value = '' }, 6000)
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page range for pagination
|
// Page range for pagination
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue