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
- 800cae06Records: #21 planmre
- 64bc7823Records: #21 causemre
- 76639655Records: B1 questionmre
- d7906b36Records: mission 005 startedmre
- d3df773cMission 005: doc linemre
- 6a5d840aMission 005: jukebox#22mre
- 13e5e748Records: mission 004 startedmre
- a8098271Mission 004: jukebox#21mre
- df8f5205Records: jukebox#19-21, #11 closedmre
- b7a4e692Records: hybriel#298mre
- 9bcbb017Records: day38b waits for day39 fixmre
- f80504e1Records: day38b repro sentmre
- 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
- 68aace7fRecords: mission 003 day38bmre
- d105d8a9Records: mpackdb integrity check cleanmre
- 6e980c53Records: mpackdb rule refinementmre
- 6d335ac4Records: storage copy rulingmre
- 7eb2898dRecords: mpackdb second-opener rule until day38mre
- b011f98eRecords: style form live on day35mre
- 60d90cb2Records: L1 woken for the restartmre