31 lines
952 B
JavaScript
31 lines
952 B
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
// ---------------------------------------------------------------------------
|
||
|
|
// M3U import
|
||
|
|
// ---------------------------------------------------------------------------
|
||
|
|
|
||
|
|
async function importM3U(input) {
|
||
|
|
const file = input.files[0];
|
||
|
|
if (!file) return;
|
||
|
|
const status = document.getElementById('import-status');
|
||
|
|
status.textContent = 'Importiere …';
|
||
|
|
|
||
|
|
const form = new FormData();
|
||
|
|
form.append('file', file);
|
||
|
|
form.append('csrfmiddlewaretoken', getCsrfToken());
|
||
|
|
|
||
|
|
try {
|
||
|
|
const res = await fetch('/radio/import/', { method: 'POST', body: form });
|
||
|
|
const data = await res.json();
|
||
|
|
if (data.ok) {
|
||
|
|
status.textContent = `✓ ${data.added} hinzugefügt, ${data.skipped} schon gespeichert`;
|
||
|
|
if (data.added > 0) location.reload();
|
||
|
|
} else {
|
||
|
|
status.textContent = `Fehler: ${_germanError(data.error)}`;
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
status.textContent = 'Hochladen fehlgeschlagen';
|
||
|
|
}
|
||
|
|
input.value = '';
|
||
|
|
}
|