jukebox
All repositories: gitoria
2.1 KB
// lib/settings.hl — THE SETTINGS, kept in storage/settings.json: the library paths to watch and how often to rescan.// They are the app's own data; the library is only ever read.import { readFile, writeFile, exists, mkDir } from 'hl:fs'import { storageRoot, settingsFile, coverDir, storageDir } from './util.hl'static defaultSettings = () => {return { libraryPaths = ['/media/SLOW1TB1/Musik'] rescanMinutes = 30 }}// the storage folders exist (the first start)static ensureStorage = () => {mkDir(storageRoot)mkDir(storageDir)mkDir(coverDir)}static loadSettings = () => {d = defaultSettings()if (!exists(settingsFile)) { return d }text = readFile(settingsFile)if (text == null || !text.trim().startsWith('{')) { return d }j = JSON.parse(text)if (j == null) { return d }if (j.libraryPaths != null && j.libraryPaths.length != null && j.libraryPaths.length > 0) {paths = []for (p of j.libraryPaths) {if (hlTypeName(p) == 'String' && p.startsWith('/')) { paths.push(p) }}if (paths.length > 0) { d.libraryPaths = paths }}if (j.rescanMinutes != null && hlTypeName(j.rescanMinutes) == 'Number' && j.rescanMinutes >= 1) { d.rescanMinutes = j.rescanMinutes }return d}// the input is checked field by field; answers the saved settings, or { error } for something wrongstatic saveSettings = (given) => {if (given == null || given.libraryPaths == null || given.libraryPaths.length == null) { return { error = 'libraryPaths must be a list of absolute folder paths' } }paths = []for (p of given.libraryPaths) {if (hlTypeName(p) != 'String' || !p.startsWith('/') || p.includes('..')) { return { error = 'every library path must be an absolute folder path' } }paths.push(p)}if (paths.length == 0) { return { error = 'at least one library path is needed' } }let mins = 30if (given.rescanMinutes != null) {if (hlTypeName(given.rescanMinutes) != 'Number' || given.rescanMinutes < 1) { return { error = 'rescanMinutes must be a number of at least 1' } }mins = given.rescanMinutes}s = { libraryPaths = paths rescanMinutes = mins }ensureStorage()writeFile(settingsFile, JSON.stringify(s), 420)return s}
Branches
Latest commits
- b58e4495jukebox JB11 (jukebox#11): the next song starts in the ended event on the same audio element, so it also starts with the screen locked; gate tests/jb11.mjs (hidden tab, no frames)mre
- 12a26233jukebox JB12 (jukebox#12): the long lists get a scroll handle a finger can use on touch screens (44 px tap area, slim look, drag through all rows), gate tests/touch.mjsmre
- 0f2157a9jukebox JV1: onto Hybriel set-day27b: readBytes and stat for /stream and the mp3 tags (no dd, head or tail), startup fault exits 1, fs and mpackdb plugins re-vendored; songs with a comma in the title are indexed againmre
- 63d0f2eejukebox ST1 (jukebox#2): styles of main, songs and search moved into their own Style blocks (styles.hl 81 to 8 rules, pixel-identical at 390 and 1280); artist and album wait for an hl:web fixmre
- c5b8fde9jukebox JB3b: keyboard gap repro as a reportmre
- 9daebb4bjukebox JB3b: shuffle, now-playing overlay, next and previous, play counting, media session, gates; keyboard left open (Hybriel gap)mre
- 59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre
- 2a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre
- 93a44212jukebox: report, numbers of the full scan, notes on the index key rulemre
- bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
- 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre
- d13987dfjukebox: library scanner, ID3 reader, mpackdb database and JSON API, with fixtures and a gatemre