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
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
- 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
- 1fecd6a7Merge branch 'records-day39' into mainJukebox
- 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