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:
Thorsten Bus 2026-03-02 13:25:36 +01:00
parent 6c59922e96
commit 11f8681feb

View file

@ -2,6 +2,7 @@
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import SongEditModal from '@/Components/SongEditModal.vue'
import { Head } from '@inertiajs/vue3'
import axios from 'axios'
import { ref, watch, onMounted } from 'vue'
const songs = ref([])
@ -139,11 +140,12 @@ function handleDragLeave() {
isDragging.value = false
}
function handleDrop(e) {
async function handleDrop(e) {
e.preventDefault()
isDragging.value = false
uploadError.value = 'ProPresenter-Import (.pro) ist noch nicht verfügbar. Kommt bald!'
setTimeout(() => { uploadError.value = '' }, 4000)
const droppedFiles = Array.from(e.dataTransfer?.files || [])
if (droppedFiles.length === 0) return
await uploadProFiles(droppedFiles)
}
function triggerFileInput() {
@ -151,9 +153,42 @@ function triggerFileInput() {
}
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 = ''
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