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
- code-order
- day39
- day41
- day72
- mainmain branch
- reconnect-retry
- records-1119
- records-1123
- records-day39
- records-day41
- status-22-pr
Latest commits
- d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
- 5fa19e89Merge branch 'day39' into mainJukebox
- cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
- f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
- 9f5c6532Merge branch 'status-22-pr' into mainJukebox
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre
- a01f3aa8ui gate: back to the top before the sort checks (the screen reopens where it was left)mre
- f7936c20Lists keep their scroll position across a reload (jukebox#20): per-list offsets in storage/ui.json, gate jb20mre
- d67906devirtual-list and icons from components.hybriel e5b98ec (centerId, scrollTop, onScroll)mre
- df7920ceRecords: R3 startedmre