Add configurable library path with settings API and UI

This commit is contained in:
2025-12-07 22:40:06 +00:00
parent cb220cc5f0
commit d87af1383d
6 changed files with 3292 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ const API_BASE = window.location.origin;
document.addEventListener('DOMContentLoaded', () => {
loadDashboard();
updateSubsonicUrl();
loadSettings();
});
// Switch between tabs
@@ -296,3 +297,48 @@ function updateSubsonicUrl() {
const url = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/rest`;
document.getElementById('subsonicUrl').value = url;
}
// Load settings
async function loadSettings() {
try {
const res = await fetch(`${API_BASE}/api/settings`);
const settings = await res.json();
document.getElementById('libraryPath').value = settings.libraryPath;
} catch (error) {
console.error('Error loading settings:', error);
}
}
// Save library path
async function saveLibraryPath() {
const libraryPath = document.getElementById('libraryPath').value;
if (!libraryPath) {
alert('Please enter a library path');
return;
}
try {
const res = await fetch(`${API_BASE}/api/settings`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ libraryPath })
});
const data = await res.json();
if (res.ok) {
alert('Library path updated! Please restart the server for changes to take effect.');
} else {
alert(`Error: ${data.error}`);
}
} catch (error) {
console.error('Error saving settings:', error);
alert('Failed to save settings');
}
}
// Browse for folder (note: web browsers can't actually browse filesystem)
function browseFolder() {
alert('Enter the full path to your audio library folder.\n\nExamples:\n- /Users/username/Music\n- /home/user/music\n- C:\\Users\\username\\Music\n- ./audio_library (relative to server)');
}