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
- 7eb2898dRecords: mpackdb second-opener rule until day38mre
- b011f98eRecords: style form live on day35mre
- 60d90cb2Records: L1 woken for the restartmre
- 75ae544fRecords: restart waits for the connection to closemre
- e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
- f2b5db98styles: format styles with nested rules and bare queriesmre
- f036bab4search: format styles with nested rules and bare queriesmre
- ef9a9d4asongs: format styles with nested rules and bare queriesmre
- f22f9aacmain: format styles with nested rules and bare queriesmre
- f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre
- d56e5054Sync theme and shared tokens from layouts 17e0f03mre
- b1362547Re-vendor to Hybriel set day35mre
- 89e10f08Records: mission 002 rollback wordingmre
- 9485dee7Records: mission 002 brief (live step)mre
- 9ba68fe7Records: S1b reviewedmre
- 193dfff1Records: S1 result, S1b startedmre
- 028ed776Records: mission 001 continuation S1bmre
- 1838d7e8Records: S1 startedmre
- a43fca3fRecords: mission 001 decided pointsmre
- 41773828Records: statusmre