diff --git a/.gitignore b/.gitignore index 834b758..27cd9fb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ build/ # Local runtime data data/ media/ +config/library.yaml config/users.yaml *.db *.db-shm diff --git a/README.md b/README.md index 5e08784..a0f76e2 100644 --- a/README.md +++ b/README.md @@ -25,18 +25,20 @@ mkdir -p media/music media/longform library: folders: - id: 1 - name: "Alice - Music" + name: "Music" type: music - path: /absolute/path/to/music/alice + path: ./media/music - id: 10 name: "Audiobooks & Podcasts" type: longform - path: /absolute/path/to/longform + path: ./media/longform ``` +The example file already uses these relative paths, so no edit is needed for local development. Relative paths are resolved from the working directory (`./gradlew run` uses the project root). For deployment, replace them with absolute paths such as `/mnt/media/music/alice` (see Section 6.1). + - `type: music` roots are assigned per user; `type: longform` roots are shared with every user. - `id` must be stable and unique (integers). It is part of song IDs, so do not renumber it after a scan. -- Paths must exist and be readable, otherwise the server refuses to start. +- Paths must exist and be readable, otherwise the server refuses to start with a clear error naming the folder. ### 3. Configure users diff --git a/config/library.example.yaml b/config/library.example.yaml index 182d566..38822b0 100644 --- a/config/library.example.yaml +++ b/config/library.example.yaml @@ -1,4 +1,11 @@ -# Example library configuration. Mount the real file as a ConfigMap. +# Example library configuration. +# +# The paths below are relative to the working directory and are meant for local +# development: `./gradlew run` creates a `./media` tree after you run +# `mkdir -p media/music media/longform`. +# +# In Kubernetes the real file is mounted as a ConfigMap and should use absolute +# paths, e.g. /mnt/media/music/alice and /mnt/media/longform. # # Folder IDs are stable identifiers used by songs and users. Never reuse an ID # for a different path. @@ -7,8 +14,8 @@ library: - id: 1 name: "Music" type: music - path: /mnt/media/music + path: ./media/music - id: 10 name: "Audiobooks & Podcasts" type: longform - path: /mnt/media/longform + path: ./media/longform diff --git a/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt b/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt index 1453999..f554655 100644 --- a/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt +++ b/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt @@ -35,17 +35,24 @@ data class LibraryConfig(val folders: List) { fun validatePaths() { folders.forEach { folder -> require(Files.isDirectory(folder.path)) { - "Library folder ${folder.id} (${folder.name}) is not a directory: ${folder.path}" + "Library folder ${folder.id} (${folder.name}) is not a directory: ${folder.path}. " + + "Create the directory or fix the path in the library config (LIBRARY_CONFIG). " + + "For local development, copy config/library.example.yaml and run " + + "`mkdir -p media/music media/longform`." } require(Files.isReadable(folder.path)) { - "Library folder ${folder.id} (${folder.name}) is not readable: ${folder.path}" + "Library folder ${folder.id} (${folder.name}) is not readable: ${folder.path}. " + + "Check the directory permissions." } } } companion object { fun load(path: Path): LibraryConfig { - require(Files.isRegularFile(path)) { "Library config not found: $path" } + require(Files.isRegularFile(path)) { + "Library config not found: $path. Copy config/library.example.yaml to " + + "config/library.yaml or point LIBRARY_CONFIG at an existing file." + } val text = Files.readString(path) return parse(text) } diff --git a/src/main/kotlin/win/taptap/musicmanager/config/UsersConfig.kt b/src/main/kotlin/win/taptap/musicmanager/config/UsersConfig.kt index 1121b4e..ffb6619 100644 --- a/src/main/kotlin/win/taptap/musicmanager/config/UsersConfig.kt +++ b/src/main/kotlin/win/taptap/musicmanager/config/UsersConfig.kt @@ -53,7 +53,10 @@ data class UsersConfig(val users: List) { private val NAME_PATTERN = Regex("[A-Za-z0-9._-]{1,64}") fun load(path: Path): UsersConfig { - require(Files.isRegularFile(path)) { "Users file not found: $path" } + require(Files.isRegularFile(path)) { + "Users file not found: $path. Copy config/users.example.yaml to config/users.yaml " + + "or point USERS_FILE at the Vault-managed file." + } val text = Files.readString(path) return parse(text) }