-
-
Notifications
You must be signed in to change notification settings - Fork 79
feat(lidarr): show only available music in the Library by default #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { | ||
| cleanupIsolatedState, | ||
| resetDatabase, | ||
| setupIsolatedBackend, | ||
| } from "../helpers/backendTestHarness.js"; | ||
|
|
||
| const [isolatedState, { db }, { dbOps }, libraryStore] = await setupIsolatedBackend( | ||
| "canonical-available-only-route", | ||
| "backend/config/db-sqlite.js", | ||
| "backend/db/helpers/index.js", | ||
| "backend/services/libraryMediaStore.js", | ||
| ); | ||
|
|
||
| const { registerCanonical } = await import( | ||
| "../../backend/routes/library/handlers/canonical.js" | ||
| ); | ||
| const { | ||
| linkLibraryAlbumTrack, | ||
| upsertLibraryAlbum, | ||
| upsertLibraryArtist, | ||
| upsertLibraryMediaFile, | ||
| upsertLibraryTrack, | ||
| } = libraryStore; | ||
|
|
||
| function getRoute(path) { | ||
| const routes = new Map(); | ||
| registerCanonical({ | ||
| get(routePath, ...handlers) { | ||
| routes.set(`GET ${routePath}`, handlers.at(-1)); | ||
| }, | ||
| post(routePath, ...handlers) { | ||
| routes.set(`POST ${routePath}`, handlers.at(-1)); | ||
| }, | ||
| }); | ||
| return routes.get(path); | ||
| } | ||
|
|
||
| function callCanonical(query) { | ||
| let body; | ||
| getRoute("GET /canonical")( | ||
| { query }, | ||
| { | ||
| status() { | ||
| return this; | ||
| }, | ||
| json(value) { | ||
| body = value; | ||
| return this; | ||
| }, | ||
| }, | ||
| ); | ||
| return body; | ||
| } | ||
|
|
||
| function setAvailableOnly(value) { | ||
| dbOps.updateSettings({ integrations: { lidarr: { availableOnly: value } } }); | ||
| } | ||
|
|
||
| test.before(() => { | ||
| resetDatabase(db); | ||
|
|
||
| // Artist who owns some but not all of their discography (the issue's "Muse" case). | ||
| const partialArtist = upsertLibraryArtist({ | ||
| identityKey: "partial-artist", | ||
| name: "Owns Some", | ||
| }); | ||
| const ownedAlbum = upsertLibraryAlbum({ | ||
| identityKey: "owned-album", | ||
| artistId: partialArtist.id, | ||
| title: "Owned Album", | ||
| }); | ||
| const ownedTrack = upsertLibraryTrack({ | ||
| identityKey: "owned-track", | ||
| title: "Owned Track", | ||
| artistName: partialArtist.name, | ||
| }); | ||
| linkLibraryAlbumTrack({ albumId: ownedAlbum.id, trackId: ownedTrack.id, trackNumber: 1 }); | ||
| upsertLibraryMediaFile({ | ||
| trackId: ownedTrack.id, | ||
| albumId: ownedAlbum.id, | ||
| source: "lidarr", | ||
| path: "/library/Owns Some/Owned Album/01 Owned Track.flac", | ||
| available: true, | ||
| }); | ||
|
|
||
| const catalogAlbum = upsertLibraryAlbum({ | ||
| identityKey: "catalog-album", | ||
| artistId: partialArtist.id, | ||
| title: "Catalog Album", | ||
| }); | ||
| const catalogTrack = upsertLibraryTrack({ | ||
| identityKey: "catalog-track", | ||
| title: "Catalog Track", | ||
| artistName: partialArtist.name, | ||
| }); | ||
| linkLibraryAlbumTrack({ albumId: catalogAlbum.id, trackId: catalogTrack.id, trackNumber: 1 }); | ||
| upsertLibraryMediaFile({ | ||
| trackId: catalogTrack.id, | ||
| albumId: catalogAlbum.id, | ||
| source: "lidarr", | ||
| path: "/library/Owns Some/Catalog Album/01 Catalog Track.flac", | ||
| available: false, | ||
| }); | ||
|
|
||
| // Artist who owns nothing (e.g. deleted in Lidarr but lingering) — issue #750. | ||
| const emptyArtist = upsertLibraryArtist({ | ||
| identityKey: "empty-artist", | ||
| name: "Owns Nothing", | ||
| }); | ||
| const emptyAlbum = upsertLibraryAlbum({ | ||
| identityKey: "empty-album", | ||
| artistId: emptyArtist.id, | ||
| title: "Unowned Album", | ||
| }); | ||
| const emptyTrack = upsertLibraryTrack({ | ||
| identityKey: "empty-track", | ||
| title: "Unowned Track", | ||
| artistName: emptyArtist.name, | ||
| }); | ||
| linkLibraryAlbumTrack({ albumId: emptyAlbum.id, trackId: emptyTrack.id, trackNumber: 1 }); | ||
| upsertLibraryMediaFile({ | ||
| trackId: emptyTrack.id, | ||
| albumId: emptyAlbum.id, | ||
| source: "lidarr", | ||
| path: "/library/Owns Nothing/Unowned Album/01 Unowned Track.flac", | ||
| available: false, | ||
| }); | ||
| }); | ||
|
|
||
| test.after(async () => { | ||
| await cleanupIsolatedState(isolatedState); | ||
| }); | ||
|
|
||
| test("albums list hides unavailable albums when the setting is on (default)", () => { | ||
| setAvailableOnly(true); | ||
| const page = callCanonical({ kind: "albums", page: "1", pageSize: "50" }); | ||
| assert.deepEqual(page.items.map((album) => album.title), ["Owned Album"]); | ||
| assert.equal(page.total, 1); | ||
| }); | ||
|
|
||
| test("albums list shows the full catalog when the setting is off", () => { | ||
| setAvailableOnly(false); | ||
| const page = callCanonical({ kind: "albums", page: "1", pageSize: "50" }); | ||
| assert.deepEqual( | ||
| page.items.map((album) => album.title).sort(), | ||
| ["Catalog Album", "Owned Album", "Unowned Album"], | ||
| ); | ||
| assert.equal(page.total, 3); | ||
| }); | ||
|
|
||
| test("artists with zero available albums disappear when the setting is on (#750)", () => { | ||
| setAvailableOnly(true); | ||
| const page = callCanonical({ kind: "artists", page: "1", pageSize: "50" }); | ||
| assert.deepEqual(page.items.map((entry) => entry.name), ["Owns Some"]); | ||
| assert.equal(page.total, 1); | ||
| }); | ||
|
|
||
| test("artists with zero available albums remain when the setting is off", () => { | ||
| setAvailableOnly(false); | ||
| const page = callCanonical({ kind: "artists", page: "1", pageSize: "50" }); | ||
| assert.deepEqual( | ||
| page.items.map((entry) => entry.name).sort(), | ||
| ["Owns Nothing", "Owns Some"], | ||
| ); | ||
| assert.equal(page.total, 2); | ||
| }); | ||
|
|
||
| test("an explicit availableOnly query param overrides the setting", () => { | ||
| setAvailableOnly(false); | ||
| const filtered = callCanonical({ | ||
| kind: "albums", | ||
| page: "1", | ||
| pageSize: "50", | ||
| availableOnly: "true", | ||
| }); | ||
| assert.deepEqual(filtered.items.map((album) => album.title), ["Owned Album"]); | ||
|
|
||
| setAvailableOnly(true); | ||
| const unfiltered = callCanonical({ | ||
| kind: "albums", | ||
| page: "1", | ||
| pageSize: "50", | ||
| availableOnly: "false", | ||
| }); | ||
| assert.equal(unfiltered.total, 3); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { resolveCanonicalAvailableOnly } from "../../backend/routes/library/handlers/canonical.js"; | ||
|
|
||
| test("explicit availableOnly query param overrides the configured default", () => { | ||
| const settingsOn = { integrations: { lidarr: { availableOnly: true } } }; | ||
| const settingsOff = { integrations: { lidarr: { availableOnly: false } } }; | ||
|
|
||
| assert.equal(resolveCanonicalAvailableOnly("true", settingsOff), true); | ||
| assert.equal(resolveCanonicalAvailableOnly("false", settingsOn), false); | ||
| }); | ||
|
|
||
| test("absent availableOnly query param follows the lidarr setting", () => { | ||
| assert.equal( | ||
| resolveCanonicalAvailableOnly(undefined, { integrations: { lidarr: { availableOnly: true } } }), | ||
| true, | ||
| ); | ||
| assert.equal( | ||
| resolveCanonicalAvailableOnly(undefined, { integrations: { lidarr: { availableOnly: false } } }), | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| test("absent query param and unset setting defaults to available-only (on)", () => { | ||
| assert.equal(resolveCanonicalAvailableOnly(undefined, undefined), true); | ||
| assert.equal(resolveCanonicalAvailableOnly(undefined, {}), true); | ||
| assert.equal(resolveCanonicalAvailableOnly(undefined, { integrations: {} }), true); | ||
| assert.equal( | ||
| resolveCanonicalAvailableOnly(undefined, { integrations: { lidarr: {} } }), | ||
| true, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.