Add configurable library path with settings API and UI
This commit is contained in:
@@ -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)');
|
||||
}
|
||||
|
||||
@@ -358,10 +358,16 @@
|
||||
<h2>Library Settings</h2>
|
||||
<div class="form-group">
|
||||
<label>Library Path</label>
|
||||
<input type="text" id="libraryPath" value="./audio_library" readonly>
|
||||
<small style="color: #86868b;">Audio files location on server</small>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<input type="text" id="libraryPath" placeholder="/path/to/your/music" style="flex: 1; margin-bottom: 0;">
|
||||
<button class="btn btn-secondary" onclick="browseFolder()" style="white-space: nowrap;">💡 Help</button>
|
||||
</div>
|
||||
<small style="color: #86868b;">Full path or relative path to your audio files</small>
|
||||
</div>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<button class="btn btn-primary" onclick="saveLibraryPath()">Save Path</button>
|
||||
<button class="btn btn-secondary" onclick="scanLibrary()">Scan Library</button>
|
||||
</div>
|
||||
<button class="btn btn-primary" onclick="scanLibrary()">Scan Library Now</button>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
Reference in New Issue
Block a user