gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchcode-order95f5faae|||PR jukebox#7 Drop needless let declarationsmrecode-order/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

  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 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