gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchrecords-day39d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmrerecords-day39/lib/settings.hl

2.1 KB

  1. // lib/settings.hl — THE SETTINGS, kept in storage/settings.json: the library paths to watch and how often to rescan.
  2. // They are the app's own data; the library is only ever read.
  3. import { readFile, writeFile, exists, mkDir } from 'hl:fs'
  4. import { storageRoot, settingsFile, coverDir, storageDir } from './util.hl'
  5. static defaultSettings = () => {
  6. return { libraryPaths = ['/media/SLOW1TB1/Musik'] rescanMinutes = 30 }
  7. }
  8. // the storage folders exist (the first start)
  9. static ensureStorage = () => {
  10. mkDir(storageRoot)
  11. mkDir(storageDir)
  12. mkDir(coverDir)
  13. }
  14. static loadSettings = () => {
  15. d = defaultSettings()
  16. if (!exists(settingsFile)) { return d }
  17. text = readFile(settingsFile)
  18. if (text == null || !text.trim().startsWith('{')) { return d }
  19. j = JSON.parse(text)
  20. if (j == null) { return d }
  21. if (j.libraryPaths != null && j.libraryPaths.length != null && j.libraryPaths.length > 0) {
  22. paths = []
  23. for (p of j.libraryPaths) {
  24. if (hlTypeName(p) == 'String' && p.startsWith('/')) { paths.push(p) }
  25. }
  26. if (paths.length > 0) { d.libraryPaths = paths }
  27. }
  28. if (j.rescanMinutes != null && hlTypeName(j.rescanMinutes) == 'Number' && j.rescanMinutes >= 1) { d.rescanMinutes = j.rescanMinutes }
  29. return d
  30. }
  31. // the input is checked field by field; answers the saved settings, or { error } for something wrong
  32. static saveSettings = (given) => {
  33. if (given == null || given.libraryPaths == null || given.libraryPaths.length == null) { return { error = 'libraryPaths must be a list of absolute folder paths' } }
  34. paths = []
  35. for (p of given.libraryPaths) {
  36. if (hlTypeName(p) != 'String' || !p.startsWith('/') || p.includes('..')) { return { error = 'every library path must be an absolute folder path' } }
  37. paths.push(p)
  38. }
  39. if (paths.length == 0) { return { error = 'at least one library path is needed' } }
  40. let mins = 30
  41. if (given.rescanMinutes != null) {
  42. if (hlTypeName(given.rescanMinutes) != 'Number' || given.rescanMinutes < 1) { return { error = 'rescanMinutes must be a number of at least 1' } }
  43. mins = given.rescanMinutes
  44. }
  45. s = { libraryPaths = paths rescanMinutes = mins }
  46. ensureStorage()
  47. writeFile(settingsFile, JSON.stringify(s), 420)
  48. return s
  49. }

Branches

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