mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Adds favorites and aligns playlist and favorite pagination
This commit is contained in:
1 parent
2e9f7d8496
commit
525ac1348d
193 files changed
+10944
-643
No files matched your search
@@ -37,6 +37,7 @@ Lumina is growing, and this is what works right now:
|
||||
- **Media libraries that scan themselves.** Point Lumina at a folder or a drive, tell it what kind of media lives there, and it gets to work discovering and indexing what it finds. Scans run in the background, report their progress as they go, and can be started, cancelled or resumed.
|
||||
- **Written content.** Add a written content library and Lumina scans it, cataloguing the books and e-books it contains and dressing them up with metadata for browsing in the client. Open one and it renders in the browser through a reader plugin; the EPUB and PDF readers are bundled and can be enabled per library.
|
||||
- **Music.** Add a music library and Lumina indexes the artists, albums and tracks it contains, reading metadata from the tags inside the audio files. If you want more, enable a metadata provider and Lumina fills in the gaps from online sources, and artwork can come from your folders or from remote sources. You can also build your own playlists, order them the way you want and play them in the browser.
|
||||
- **Favorites.** Mark the artists, albums, tracks and books you love as favorites and come back to them from one page, filtered by kind. Favorites are private to your account.
|
||||
- **Metadata and artwork from plugins.** Plugins do the knowing. They supply the metadata and the artwork of a library, and you decide, library by library, which ones are switched on and which one wins when several of them recognize the same item.
|
||||
- **A file system browser.** Reach the drives, folders and files of the server machine from anywhere you can open the client, as if you were sitting right in front of it. Poke around, walk a path to its root or to its parent, and let Lumina generate thumbnails for what it finds.
|
||||
- **Accounts, roles, permissions and policies.** Create accounts, sign in with a password and optional two factor authentication, and hand out access through roles, fine grained permissions and policies that decide who may reach which library or content. Administrators manage all of it from the administration area.
|
||||
|
||||
@@ -90,11 +90,24 @@ From the playlists page you can open a playlist or select **Create** to open the
|
||||
|
||||
The playlist reflects the catalogue at the moment you open it. If a track is deleted from a library after it was added to a playlist, its row stays in the playlist as an unavailable track so you can remove it deliberately. Long playlists are shown in pages; select **Load more** to show the next page.
|
||||
|
||||
## Favorites
|
||||
|
||||
A favorite is a mark you place on an artist, album, track or book so you can find it again quickly. Favorites belong to your account and are not shared with other users. Marking an item never changes the item or its files. Videos and photos are not available as favorites yet.
|
||||
|
||||
Select the heart on an item's card, or on its row on an album page, to add or remove the mark. A blue heart means the item is not a favorite; a red heart means it is.
|
||||
|
||||
The **Favorites** page in the library section lists everything you marked, most recent first, with a count that follows the filter.
|
||||
|
||||
- **Filter by kind** with the **Show** picker.
|
||||
- **Open an item** from its card.
|
||||
- **Remove a favorite** with the heart on its card.
|
||||
- **Load more** when the list is long, or **Retry** if it does not load.
|
||||
|
||||
A favorite whose item was deleted, or whose library you can no longer access, stays in the list as an unavailable card so you can still remove it.
|
||||
|
||||
## Editing what is catalogued
|
||||
|
||||
Both book and music pages double as editors for the items that were scanned in. A book's details page groups its fields into general and release information, language and original language, genres, tags, identifiers, ISBNs, contributors and ratings, and lets you replace its cover. An artist's page lists the artist's albums first, then groups its fields into general information, contributors, ratings, genres, tags, aliases, areas and identifiers, and lets you replace the artist's cover. An album page groups its fields into general information, contributors, ratings, genres, tags, release types, release information, language and original language, and identifiers, and lets you replace the album's cover. A track page groups its fields into general information, contributors, ratings, genres, tags, moods, release information, language and original language, work, ISRCs, identifiers and audio properties. Saving sends the changes back to the server, and a confirmation or an error is shown in the corner of the screen.
|
||||
|
||||
Changes you make here live in Lumina's catalogue.
|
||||
Both book and music pages double as editors for the items that were scanned in. A book's details page groups its fields into general and release information, language and original language, genres, tags, identifiers, ISBNs, contributors and ratings, and lets you replace its cover. An artist's page lists the artist's albums first, then groups its fields into general information, contributors, ratings, genres, tags, aliases, areas and identifiers, and lets you replace the artist's cover. An album page groups its fields into general information, contributors, ratings, genres, tags, release types, release information, language and original language, and identifiers, and lets you replace the album's cover. A track page groups its fields into general information, contributors, ratings, genres, tags, moods, release information, language and original language, work, ISRCs, identifiers and audio properties. Saving applies the changes to Lumina's catalogue.
|
||||
|
||||
## The file system browser
|
||||
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
# Lumina API
|
||||
|
||||
- [Lumina API](#lumina-api)
|
||||
- [Favorites](#favorites)
|
||||
- [Add Favorite](#add-favorite)
|
||||
- [Add Favorite Request](#add-favorite-request)
|
||||
- [Add Favorite Response](#add-favorite-response)
|
||||
- [Remove Favorite](#remove-favorite)
|
||||
- [Remove Favorite Request](#remove-favorite-request)
|
||||
- [Remove Favorite Response](#remove-favorite-response)
|
||||
- [Get Favorites](#get-favorites)
|
||||
- [Get Favorites Request](#get-favorites-request)
|
||||
- [Get Favorites Response](#get-favorites-response)
|
||||
- [Get Favorite Status](#get-favorite-status)
|
||||
- [Get Favorite Status Request](#get-favorite-status-request)
|
||||
- [Get Favorite Status Response](#get-favorite-status-response)
|
||||
- [Media Kinds](#media-kinds)
|
||||
- [Scoping and Library Access](#scoping-and-library-access)
|
||||
- [Errors](#errors)
|
||||
- [Pagination Limits](#pagination-limits)
|
||||
|
||||
## Favorites
|
||||
|
||||
A favorite is the marker the current user places on a media item of any media kind. It references the item only by its kind and its Id, so the same four operations serve music artists, albums and tracks, books, and the kinds that are planned. A favorite belongs to the user that created it, and only that user can list it, check it or remove it. Every route is under `users/me`, because it always acts on the currently authenticated user, and every operation requires authentication.
|
||||
|
||||
Favorites are independent of the catalogue they point to. A favorite stores the kind and the Id of the item without a foreign key to it, so deleting the item from its library does not delete the favorite. A favorite is deleted together with the user that owns it. A favorite whose item was deleted, or whose library the user can no longer access, is still listed, as an unavailable item with empty display fields, so that its owner can see it and remove it.
|
||||
|
||||
All the responses of the four operations are private to the authenticated user: they carry `Cache-Control: private, no-store` and `Vary: Authorization`.
|
||||
|
||||
### Add Favorite
|
||||
|
||||
#### Add Favorite Request
|
||||
|
||||
```js
|
||||
POST api/v1/users/me/favorites
|
||||
Authorization: Bearer <token>
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"mediaKind": "MusicTrack",
|
||||
"mediaItemId": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Required | Meaning |
|
||||
| --- | --- | --- | --- |
|
||||
| `mediaKind` | string | yes | The kind of the media item: `MusicArtist`, `MusicAlbum`, `MusicTrack` or `Book`. `Video` and `Photo` are planned kinds and are rejected, see [Media Kinds](#media-kinds). |
|
||||
| `mediaItemId` | Guid | yes | The Id of the media item. It cannot be the empty Guid. |
|
||||
|
||||
Marks the media item as a favorite of the current user. The request is validated first, and then the media item is looked up in the catalogue of its kind. The item must exist, and the library that contains it must be accessible to the current user, see [Scoping and Library Access](#scoping-and-library-access). The user is always the authenticated user, so no user Id is accepted in the body.
|
||||
|
||||
#### Add Favorite Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "2c1b0a9f-8e7d-4c6b-5a4f-3e2d1c0b9a8f",
|
||||
"mediaKind": "MusicTrack",
|
||||
"mediaItemId": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
"favoritedOnUtc": "2026-10-21T12:00:00.0000000Z"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Meaning |
|
||||
| --- | --- |
|
||||
| `id` | The Id of the favorite. |
|
||||
| `mediaKind` | The kind of the favorited media item. |
|
||||
| `mediaItemId` | The Id of the favorited media item. |
|
||||
| `favoritedOnUtc` | The date and time when the item was favorited. |
|
||||
|
||||
The response is `200 Ok` both when the favorite was created and when it already existed, so a client does not need to tell the two apart. The favorite is read back from storage after it is saved, so `favoritedOnUtc` is the stored value. A favorite that was created raises a `FavoriteAdded` domain event; an existing favorite raises none.
|
||||
|
||||
### Remove Favorite
|
||||
|
||||
#### Remove Favorite Request
|
||||
|
||||
```js
|
||||
DELETE api/v1/users/me/favorites/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f
|
||||
Authorization: Bearer <token>
|
||||
```
|
||||
|
||||
| Route value | Meaning |
|
||||
| --- | --- |
|
||||
| `mediaKind` | The name of the media kind, matched case insensitively. Only the member names are accepted: a number that would parse as a kind is rejected. |
|
||||
| `mediaItemId` | The Id of the media item. It must be a Guid and cannot be the empty Guid. |
|
||||
|
||||
Removes the favorite of the current user on the media item identified by the route. Removal is scoped to the authenticated user and never touches another user's favorite. It does not look the media item up and does not evaluate the library access rule, so a user can always remove their own favorite even when the item was deleted or its library is no longer accessible. Another user's favorite is never visible to them, so it cannot be removed through this route. Removing a media kind that is planned but not supported is not an error by itself: it finds no favorite and the request succeeds without changing anything.
|
||||
|
||||
#### Remove Favorite Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
The response body is an empty JSON object.
|
||||
|
||||
Removing an item that the current user did not favorite succeeds without changing anything, and the same is true for a favorite of another user, which is never visible to the current user. Removing is therefore idempotent: the second removal of the same favorite also returns `200 Ok` and raises no event. A favorite that was actually removed raises a `FavoriteRemoved` domain event.
|
||||
|
||||
### Get Favorites
|
||||
|
||||
#### Get Favorites Request
|
||||
|
||||
```js
|
||||
GET api/v1/users/me/favorites?mediaKind=MusicTrack¤tPage=1&perPage=200
|
||||
Authorization: Bearer <token>
|
||||
```
|
||||
|
||||
| Query parameter | Type | Required | Meaning |
|
||||
| --- | --- | --- | --- |
|
||||
| `mediaKind` | string | no | Restricts the list to one kind: `MusicArtist`, `MusicAlbum`, `MusicTrack` or `Book`. Every kind is returned when it is omitted. |
|
||||
| `currentPage` | integer | no | The one based page of favorites to return. Defaults to `1` when `perPage` is provided. Values below `1` are raised to `1`. |
|
||||
| `perPage` | integer | no | The number of favorites per page. Defaults to `200` when `currentPage` is provided. Values below `1` are raised to `1`, and there is no maximum. |
|
||||
|
||||
Returns the favorites of the current user, from the most recently favorited. The page bounds one response, not the number of favorites a user can have: a client reads the next page until `currentPage` reaches `numberOfPages`, and `count` reports the total. When neither `currentPage` nor `perPage` is provided, every matching favorite is returned in a single page, the same way the other paginated collections of the API behave when pagination is omitted.
|
||||
|
||||
#### Get Favorites Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"mediaKind": "MusicTrack",
|
||||
"mediaItemId": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
"isAvailable": true,
|
||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
||||
"title": "Bohemian Rhapsody",
|
||||
"collectionId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
|
||||
"collectionTitle": "A Night at the Opera",
|
||||
"creatorId": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a",
|
||||
"creatorName": "Queen",
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
},
|
||||
{
|
||||
"mediaKind": "Book",
|
||||
"mediaItemId": "4a5b6c7d-8e9f-4a0b-9c1d-2e3f4a5b6c7d",
|
||||
"isAvailable": true,
|
||||
"libraryId": "5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f",
|
||||
"title": "The Hobbit",
|
||||
"collectionId": "00000000-0000-0000-0000-000000000000",
|
||||
"collectionTitle": "",
|
||||
"creatorId": "00000000-0000-0000-0000-000000000000",
|
||||
"creatorName": "J. R. R. Tolkien",
|
||||
"coverPath": null
|
||||
},
|
||||
{
|
||||
"mediaKind": "MusicAlbum",
|
||||
"mediaItemId": "0f1e2d3c-4b5a-4968-8776-5a4b3c2d1e0f",
|
||||
"isAvailable": false,
|
||||
"libraryId": "00000000-0000-0000-0000-000000000000",
|
||||
"title": "",
|
||||
"collectionId": "00000000-0000-0000-0000-000000000000",
|
||||
"collectionTitle": "",
|
||||
"creatorId": "00000000-0000-0000-0000-000000000000",
|
||||
"creatorName": "",
|
||||
"coverPath": null
|
||||
}
|
||||
],
|
||||
"currentPage": 1,
|
||||
"perPage": 200,
|
||||
"count": 3,
|
||||
"numberOfPages": 1
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Meaning |
|
||||
| --- | --- |
|
||||
| `data` | The favorites of the page, from the most recently favorited. |
|
||||
| `currentPage` | The one based page number. |
|
||||
| `perPage` | The number of favorites per page. |
|
||||
| `count` | The number of favorites that match the `mediaKind` filter, even when only a page of them is returned. |
|
||||
| `numberOfPages` | The total number of pages. |
|
||||
|
||||
Each item carries the kind and Id of the favorited media item together with its display details. The display fields are generic across media kinds, and "no value" is the empty Guid or the empty string:
|
||||
|
||||
| Field | Meaning |
|
||||
| --- | --- |
|
||||
| `mediaKind` | The kind of the favorited media item. |
|
||||
| `mediaItemId` | The Id of the favorited media item. |
|
||||
| `isAvailable` | Whether the item still exists and its library is accessible to the user. When it is `false`, every display field below is empty. |
|
||||
| `libraryId` | The Id of the library that contains the item. |
|
||||
| `title` | The title of the item. |
|
||||
| `collectionId`, `collectionTitle` | The Id and the title of the collection the item belongs to. |
|
||||
| `creatorId`, `creatorName` | The Id and the name of the creator of the item. |
|
||||
| `coverPath` | The stored path of the cover art of the item, the same kind of value the artist, album and book resources expose as `coverPath`, or `null` when it has none. The cover of a track is the cover of its album. |
|
||||
|
||||
How the generic fields map to each kind:
|
||||
|
||||
| Kind | `title` | `collection` | `creator` |
|
||||
| --- | --- | --- | --- |
|
||||
| `MusicArtist` | The artist name. | None. | None. |
|
||||
| `MusicAlbum` | The album title. | None. | The artist. |
|
||||
| `MusicTrack` | The track title. | The album. | The artist. |
|
||||
| `Book` | The book title. | None today: the series of a book is not catalogued yet, so the collection is always empty. | The first author, by display name. |
|
||||
|
||||
An item whose display details no longer exist, because the item was deleted, or whose library the current user cannot access, is returned with `isAvailable` set to `false` and every display field empty. It stays in `data` and in `count`, so its owner can see it and remove it with [Remove Favorite](#remove-favorite), and the response never exposes display data from a library the user cannot reach. The Id of the media item is the one the user favorited, and carries no information beyond that.
|
||||
|
||||
### Get Favorite Status
|
||||
|
||||
#### Get Favorite Status Request
|
||||
|
||||
```js
|
||||
GET api/v1/users/me/favorites/status?mediaKind=MusicTrack&mediaItemIds=9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f&mediaItemIds=8e9f0a1b-2c3d-4e5f-9a6b-7c8d9e0f1a2b
|
||||
Authorization: Bearer <token>
|
||||
```
|
||||
|
||||
| Query parameter | Type | Required | Meaning |
|
||||
| --- | --- | --- | --- |
|
||||
| `mediaKind` | string | yes | The kind of every media item checked: `MusicArtist`, `MusicAlbum`, `MusicTrack` or `Book`. |
|
||||
| `mediaItemIds` | Guid, repeated | yes | The Ids of the media items to check, one `mediaItemIds` parameter per Id, from 1 to 100. None can be the empty Guid. Repeated Ids are checked once. |
|
||||
|
||||
Tells which of the given media items are favorites of the current user. It reads only the favorites of the current user and evaluates no library access, so the answer reveals nothing about any other user, and an Id that is not a favorite, does not exist or belongs to an inaccessible library is simply absent from the answer. A page that renders many favorite toggles uses it to hydrate all of them with one request per kind.
|
||||
|
||||
#### Get Favorite Status Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"favoritedMediaItemIds": [
|
||||
"9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Meaning |
|
||||
| --- | --- |
|
||||
| `favoritedMediaItemIds` | The Ids, among the checked ones, that the current user favorited. Empty when none is. |
|
||||
|
||||
### Media Kinds
|
||||
|
||||
The media kind is stored by its name, together with the Id of the item.
|
||||
|
||||
| Kind | Status | Item |
|
||||
| --- | --- | --- |
|
||||
| `MusicArtist` | Supported | An artist of a music library. |
|
||||
| `MusicAlbum` | Supported | An album of a music library. |
|
||||
| `MusicTrack` | Supported | A track of a music library. |
|
||||
| `Book` | Supported | A book of a book library. |
|
||||
| `Video` | Planned | A video file. Video libraries are not catalogued yet. |
|
||||
| `Photo` | Planned | A photo. Photo libraries are not catalogued yet. |
|
||||
|
||||
### Scoping and Library Access
|
||||
|
||||
Every operation is scoped to the current user by the server: the user is read from the authenticated principal, never from the route, the query or the body, so a user cannot read or change the favorites of another user.
|
||||
|
||||
Adding a favorite also applies the library access rule. The server resolves the library that contains the item, through the catalogue of its kind, and then evaluates the library ownership policy of the current user for that library, exactly as the library routes do. An item that does not exist, and an item whose library is not accessible to the current user, are both reported with the same kind specific not found error, so the response cannot be used to find out whether an item exists in a library of another user. The not found error depends on the kind:
|
||||
|
||||
| Kind | Not found error |
|
||||
| --- | --- |
|
||||
| `MusicArtist` | `ArtistNotFound` |
|
||||
| `MusicAlbum` | `AlbumNotFound` |
|
||||
| `MusicTrack` | `TrackNotFound` |
|
||||
| `Book` | `BookNotFound` |
|
||||
|
||||
Removing, and checking the status of, favorites do not evaluate the rule, because they only touch the favorites of the current user. Listing evaluates the rule once for each distinct library among the items of the page, and an item of an inaccessible library is returned as unavailable, as described in [Get Favorites Response](#get-favorites-response).
|
||||
|
||||
### Errors
|
||||
|
||||
Errors are returned as problem details. A request without a valid token is rejected with `401 Unauthorized` before it reaches the operation.
|
||||
|
||||
| Status | Error | When |
|
||||
| --- | --- | --- |
|
||||
| `401` | | The request carries no token, or an invalid or expired one. The body is a problem whose `title` is `Unauthorized` and whose `detail` says why, for example `The token has expired`. |
|
||||
| `403` | `NotAuthorized` | The authenticated principal carries no user identity. |
|
||||
| `404` | `ArtistNotFound` | [Add Favorite](#add-favorite) of a `MusicArtist` that does not exist or whose library the user cannot access. |
|
||||
| `404` | `AlbumNotFound` | [Add Favorite](#add-favorite) of a `MusicAlbum` that does not exist or whose library the user cannot access. |
|
||||
| `404` | `TrackNotFound` | [Add Favorite](#add-favorite) of a `MusicTrack` that does not exist or whose library the user cannot access. |
|
||||
| `404` | `BookNotFound` | [Add Favorite](#add-favorite) of a `Book` that does not exist or whose library the user cannot access. |
|
||||
| `409` | `ConcurrencyConflict` | The storage reported a busy or locked database while the change was saved. Repeating the request is safe. |
|
||||
| `422` | see below | The request failed validation. |
|
||||
|
||||
The `404` and `409` problems carry the generic error code in `title` and the specific name in `detail`:
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "General.NotFound",
|
||||
"status": 404,
|
||||
"detail": "TrackNotFound",
|
||||
"instance": "/api/v1/users/me/favorites",
|
||||
"traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
|
||||
}
|
||||
```
|
||||
|
||||
A request that fails validation is rejected with `422 Unprocessable Entity` and a validation problem whose `errors` object lists the names of the validation errors under the generic `General.Validation` code:
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "General.Validation",
|
||||
"status": 422,
|
||||
"detail": "OneOrMoreValidationErrorsOccurred",
|
||||
"instance": "/api/v1/users/me/favorites",
|
||||
"errors": {
|
||||
"General.Validation": [
|
||||
"FavoriteMediaKindIsNotSupported"
|
||||
]
|
||||
},
|
||||
"traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
|
||||
}
|
||||
```
|
||||
|
||||
The validation errors of each operation are:
|
||||
|
||||
| Error | Operation | When |
|
||||
| --- | --- | --- |
|
||||
| `FavoriteMediaKindIsInvalid` | Add, Remove, Get Favorites, Get Favorite Status | The kind is missing where it is required, or it is a number that is not a member of the media kind enumeration. In the Remove route, the segment is not a member name of the enumeration, and numbers are not accepted. |
|
||||
| `FavoriteMediaKindIsNotSupported` | Add | The kind is `Video` or `Photo`, which are planned and cannot be favorited yet. |
|
||||
| `FavoriteMediaItemIdCannotBeEmpty` | Add, Remove, Get Favorite Status | The item Id is missing or is the empty Guid. In the Remove route it is also reported when the segment is not a Guid. For the status request, any of the Ids is the empty Guid. |
|
||||
| `FavoriteMediaItemIdsCannotBeEmpty` | Get Favorite Status | No `mediaItemIds` were given. |
|
||||
| `FavoriteMediaItemIdsExceedMaximumCount` | Get Favorite Status | More than 100 Ids were given. |
|
||||
|
||||
A value that cannot be bound is not reported by the validators. This covers a `mediaKind` that is not a member of `FavoriteMediaKind` (for example `"Song"`, or a number outside the enumeration), an item Id that is not a Guid in the Add body or the status query, and a `currentPage` or `perPage` that is not an integer. The endpoints do not catch binding failures, so the request is answered by the exception handling middleware as a generic `500 Internal Server Error` problem, exactly like every other endpoint of the API that binds an enumeration or a number, and not with the `422` problem above. The web client never sends such values, because its proxy endpoints rebuild the query from typed values.
|
||||
|
||||
`FavoriteAlreadyExists` is defined among the favorites errors, but adding is idempotent, so no operation returns it. `FavoriteNotFound` remains defined for the storage read that follows an add, but removing is idempotent, so a remove request no longer returns it.
|
||||
|
||||
### Pagination Limits
|
||||
|
||||
| Limit | Value |
|
||||
| --- | --- |
|
||||
| Default per page of Get Favorites | 200 favorites, when a page is requested. |
|
||||
| Minimum per page of Get Favorites | 1 favorite. |
|
||||
| Maximum per page of Get Favorites | None. The server has no separate maximum page size, matching the other paginated collections of the API. |
|
||||
| Ids of one Get Favorite Status request | From 1 to 100, one kind per request. The Ids travel in the query string, so the limit keeps the request line under the 8 KB default of Kestrel. |
|
||||
|
||||
The limits bound a response or a request, not the number of favorites a user can have. A client that needs more than 100 Ids checked splits them into several requests, as the bundled web client does.
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
# Architecture Decision Record (ADR): 0017 - One Generic Favorites Aggregate Keyed by Media Kind and Item Id
|
||||
|
||||
## Status
|
||||
|
||||
**Accepted** (2026-10-21)
|
||||
|
||||
## Context
|
||||
|
||||
A user must be able to mark any media item as a favorite: today the artists, albums and tracks of a music library and the books of a book library, and later videos and photos. Playlists already reference media items across bounded contexts by storing a media kind and a media item Id without a foreign key.
|
||||
|
||||
Favorites raise the same question with different constraints:
|
||||
|
||||
1. **One concept, many contexts**: a favorite is the same fact for every media kind, so a table and an aggregate per media kind would repeat one model four times now, and again for every media kind that is added.
|
||||
2. **Bounded context isolation**: as specified by DDD, an aggregate does not reference objects of another bounded context, only identifiers placed in `ExternalIdentifiers` directories. A favorites aggregate that held an `Artist`, a `Book` or any other media entity would couple favorites to every media context.
|
||||
3. **Referential integrity across kinds**: one table cannot declare a foreign key to the tables of several media kinds. A favorite must also outlive the item it references, because a library scan or a manual delete can remove an item, and the owner of the favorite has to be able to see and remove it afterwards instead of the favorite silently disappearing.
|
||||
4. **Concurrent toggles**: a favorite toggle is rendered on many pages, and a user can have several tabs open, so the same add can arrive twice at nearly the same moment.
|
||||
5. **Access control**: favoriting an item must not reveal whether an item exists in a library the user cannot access, and listing must not expose the display data of such a library.
|
||||
|
||||
## Decision
|
||||
|
||||
Store favorites as one generic `Favorite` aggregate in `FavoriteBoundedContext`, in one `Favorites` table. The table has a surrogate `FavoriteId` primary key and a unique business key `(UserId, MediaKind, MediaItemId)`. A media item is referenced only by its `FavoriteMediaKind` and the external `MediaItemId`; there is no foreign key to a media table. There are no per-kind favorite aggregates, tables, endpoints or contracts.
|
||||
|
||||
The decision includes these rules:
|
||||
|
||||
- **Add is idempotent.** Adding an item the user already favorited returns the existing favorite and raises no event.
|
||||
- **Remove is idempotent.** Removing a favorite that is already absent succeeds without changing anything and raises no event.
|
||||
- **The owner always comes from the authenticated principal.** No route, query or body carries the owner, and no administrator or library-owner override exposes another user's favorites.
|
||||
- **Access is checked where it can leak.** Adding evaluates the library ownership policy of the item's library. Listing evaluates it for each distinct library in the returned page and hides the display data of inaccessible libraries. Removing and checking the status read only the current user's own favorites, so they evaluate no library policy.
|
||||
- **Dangling favorites stay visible.** A favorite whose item no longer exists, or whose library is no longer accessible, is returned as an unavailable item with empty display fields so its owner can see and remove it.
|
||||
- **Reads use the shared pagination contract.** The repository accepts the shared `PaginationDataDto` and returns the shared `PaginatedResultDto<T>`, like every other paginated listing. When the request provides neither `currentPage` nor `perPage`, every matching favorite is returned in a single page; when a page is requested, the page defaults to `1` and the page size defaults to `200`. A page beyond the last one is clamped to the last page, and there is no separate maximum page size. The status check accepts 1 to 100 Ids of one kind per request.
|
||||
|
||||
### Model
|
||||
|
||||
| Element | Decision |
|
||||
|---|---|
|
||||
| Aggregate | `Favorite` is the root, with a `FavoriteId`, a `UserId`, a `MediaItemId`, a `FavoriteMediaKind` and the audit columns. It has no entities. The user and the media item are referenced only through the identifier types in the context's `ExternalIdentifiers` directories; the kind is the shared `FavoriteMediaKind` enumeration. The media item identifier is generic across artists, albums, tracks, books and the planned video and photo kinds. |
|
||||
| Media kind | `FavoriteMediaKind` has `MusicArtist`, `MusicAlbum`, `MusicTrack`, `Book`, `Video` and `Photo`, and it is stored by name. `Favorite.IsSupported` is `true` for the first four, and creating a favorite of the planned `Video` and `Photo` kinds is rejected with the validation error `FavoriteMediaKindIsNotSupported`. A planned kind becomes supported by lifting the restriction, with no change to the storage schema. |
|
||||
| Domain events | `FavoriteAdded` is raised when a favorite is created, and `FavoriteRemoved` when it is removed. |
|
||||
| Storage | The `Favorites` table holds the Id, the owner, the media kind, the media item Id and the audit columns. The owner is a foreign key that cascades, so favorites leave with their user. The media item is not a foreign key. |
|
||||
| Invariant | A unique index on `(UserId, MediaKind, MediaItemId)` makes the storage medium the owner of the rule "one favorite per user and item", and serves the status check that looks up a user's favorites among checked Ids. Indexes on `(UserId, CreatedOnUtc)` and `(UserId, MediaKind, CreatedOnUtc)` serve the listing of every kind and of one kind. |
|
||||
| Display data | The repository resolves, per kind and with projections that do not materialize the entities, the library Id of an item and the generic display fields of a page of favorites. The display fields are the title, the collection Id and title, the creator Id and name, and the cover path. Each kind fills what it has, and "no value" is the empty Guid or the empty string. Adding a media kind adds one branch to each resolution and one entry to the enumeration, with no new table, endpoint or contract. |
|
||||
|
||||
### Operations
|
||||
|
||||
- **Add**: the handler validates, requires the current user, rejects an unsupported kind, resolves the library of the item, evaluates the library ownership policy and returns the existing favorite without an event when the user already favorited the item. Otherwise it creates the aggregate, inserts it, saves the unit of work, queues the aggregate's events and reads the row back. If the unique index rejects a concurrent add, the handler re-reads the existing favorite and returns it without an event.
|
||||
- **Remove**: the handler validates, requires the current user and loads the favorite by user, kind and item. A missing favorite is a successful removal with no event. Otherwise it removes the aggregate, deletes the row, saves the unit of work and queues the removal event. A concurrent removal is treated as success; any other concurrency conflict is reported.
|
||||
- **List**: the repository scopes the query to the current user inside the storage query and returns the paginated listing ordered by the time of favoriting, with the shared pagination metadata. The handler evaluates the library policy once per distinct library in the page and maps a favorite with missing or inaccessible display data to an unavailable item with empty display fields.
|
||||
- **Status**: the repository scopes the check to the current user and returns the Ids, among the checked ones, that the user favorited. The response carries only those Ids.
|
||||
- **Errors**: `FavoriteAlreadyExists` remains defined but no operation produces it. `FavoriteNotFound` is used only where a stored favorite cannot be read back; removal of an absent favorite succeeds. `FavoriteMediaKindIsNotSupported` is returned by Add for the planned kinds.
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive Outcomes
|
||||
|
||||
| Aspect | Benefit |
|
||||
|---|---|
|
||||
| One model | Multiple media kinds share one aggregate, one table, four operations and one set of contracts |
|
||||
| Context isolation | The aggregate holds identifiers only, so favorites depend on no media bounded context and could move to their own service |
|
||||
| Survives deletion | A favorite is not removed by deleting or rescanning its item, and its owner is shown an unavailable item that can be removed |
|
||||
| Race safe | The storage unique index, not the existence check alone, guarantees a single favorite per user and item, and a concurrent duplicate add resolves to the existing favorite |
|
||||
| No existence oracle | An inaccessible item and a missing item are indistinguishable when adding, and inaccessible display data is never listed |
|
||||
| No schema change for new kinds | The kind is stored by name, so a planned kind only needs its restriction lifted and its two resolutions written |
|
||||
|
||||
### Risks and Mitigations
|
||||
|
||||
| Risk | Mitigation Strategy |
|
||||
|---|---|
|
||||
| Without a foreign key, rows can point at items that no longer exist | This is intended: the listing returns such rows as unavailable and removal never needs the item. Nothing relies on the item being present |
|
||||
| The per-kind resolution is a switch in the repository, so a new kind could be added to the enumeration without a resolution | `GetMediaItemLibraryIdAsync` reports no library for a kind without a branch, so an add of it is reported as not found, and `Favorite.IsSupported` has to be extended together with the branch |
|
||||
| The listing evaluates the library policy once per distinct library of a page | The policy is evaluated once per distinct library, not once per favorite, so the cost grows with the number of distinct libraries rather than with the number of favorites. A client that needs a bound requests a page size, like every other paginated listing |
|
||||
| The display projections can drift from how the catalogues show their items | The projections reuse the same sources as the listings of each catalogue, so a change to how a catalogue shows an item has to be mirrored in the matching branch |
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
### 1. One favorites table and aggregate per media kind
|
||||
|
||||
A `FavoriteArtist`, `FavoriteAlbum`, `FavoriteTrack` and `FavoriteBook` aggregate, each with a real foreign key to its media table.
|
||||
|
||||
**Rejected**: it repeats the same model, endpoints and contracts per kind, and again for every planned kind. The foreign keys would also make the favorite die with its item, which removes the user's ability to see and remove it, and each aggregate would need to reference a media bounded context directly.
|
||||
|
||||
### 2. A flag on each media entity
|
||||
|
||||
An `IsFavorite` column on artists, albums, tracks and books.
|
||||
|
||||
**Rejected**: a favorite is private to a user, and a flag on a shared catalogue row cannot be. A join table per user would be needed anyway, which brings back the first alternative.
|
||||
|
||||
### 3. Reuse the playlist model with a system playlist
|
||||
|
||||
Store favorites as the entries of a special playlist per user.
|
||||
|
||||
**Rejected**: a playlist is an ordered list that allows duplicates and is positioned by the user, while a favorite is an unordered set with exactly one entry per item and a listing ordered by the time of favoriting. The playlist operations, the position keys and the entry limits do not apply, and the favorites of artists, albums and books are not playable entries.
|
||||
|
||||
### 4. Enforce uniqueness only in the handler
|
||||
|
||||
Check for an existing favorite and rely on it, with no unique index.
|
||||
|
||||
**Rejected**: two requests of the same user can both pass the check, so duplicates would be created under concurrency. The storage medium must own the invariant, and the handler's check is kept only to make the common repeated add idempotent without a failure.
|
||||
|
||||
### 5. Return a conflict when an item is already a favorite
|
||||
|
||||
Report `FavoriteAlreadyExists` instead of returning the existing favorite.
|
||||
|
||||
**Rejected**: a toggle rendered on several pages, and several open tabs, make a repeated add a normal event rather than an error. An idempotent add keeps the client simple, since it does not have to distinguish a created favorite from an existing one. `FavoriteAlreadyExists` remains defined in the favorites error set, but no operation produces it.
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
- _**Metadata**_: Information describing a media item
|
||||
- _**User**_: A person who interacts with the media library
|
||||
- _**Playlist**_: A curated list of media items, potentially cross-media-type
|
||||
- _**Favorite**_: The marker a user places on a media item of any media kind, private to that user. It references the item only by its kind and its Id, so one concept serves music, books and the media kinds that are planned
|
||||
- _**FavoriteMediaKind**_: The set of media item kinds that can be marked as a favorite
|
||||
- _**Tag**_: A label for categorizing and organizing media items
|
||||
- _**Collection**_: A user-defined group of any media items
|
||||
- _**File**_: The actual digital file of a media item
|
||||
@@ -95,6 +97,7 @@
|
||||
- PhotoAlbum
|
||||
- User
|
||||
- Playlist
|
||||
- Favorite
|
||||
- Collection
|
||||
- SubtitleFile
|
||||
- Lyrics
|
||||
@@ -114,6 +117,7 @@
|
||||
- PhotoLibrary (root: PhotoLibrary, entities: Photo, PhotoAlbum, AlbumArtwork, MoviePoster)
|
||||
- UserProfile (root: User, entities: Collection)
|
||||
- PlaylistManagement (root: Playlist, entities: PlaylistEntry)
|
||||
- Favorites (root: Favorite, no entities)
|
||||
- SupplementaryContentLibrary (root: SupplementaryContentLibrary, entities: SubtitleFile, Lyrics, LanguageTrack)
|
||||
- FileSystemManagement (root: File, entities: Stream)
|
||||
|
||||
@@ -213,6 +217,8 @@
|
||||
- PlaylistEntryRemoved
|
||||
- PlaylistEntriesReordered
|
||||
- PlaylistDeleted
|
||||
- FavoriteAdded
|
||||
- FavoriteRemoved
|
||||
- UserPreferencesChanged
|
||||
- MetadataUpdated
|
||||
- FileTranscoded
|
||||
@@ -229,6 +235,8 @@
|
||||
- Services: RecommendationEngine, ContentCurationService, UserActivityTrackingService
|
||||
- PlaylistManagement
|
||||
- Aggregates: Playlist
|
||||
- Favorites
|
||||
- Aggregates: Favorite
|
||||
- ContentDelivery
|
||||
- Aggregates: FileSystemManagement
|
||||
- Services: StreamingService, ContentSynchronizationService
|
||||
@@ -244,6 +252,7 @@
|
||||
- PhotoRepository
|
||||
- UserRepository
|
||||
- PlaylistRepository
|
||||
- FavoriteRepository
|
||||
- CollectionRepository
|
||||
- FileRepository
|
||||
- StreamRepository
|
||||
@@ -0,0 +1,8 @@
|
||||
POST {{host}}/api/v1/users/me/favorites
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"mediaKind": "MusicTrack",
|
||||
"mediaItemId": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
GET {{host}}/api/v1/users/me/favorites/status?mediaKind=MusicTrack&mediaItemIds=9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f&mediaItemIds=8e9f0a1b-2c3d-4e5f-9a6b-7c8d9e0f1a2b
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
@@ -0,0 +1,2 @@
|
||||
GET {{host}}/api/v1/users/me/favorites?mediaKind=MusicTrack¤tPage=1&perPage=200
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
@@ -0,0 +1,2 @@
|
||||
DELETE {{host}}/api/v1/users/me/favorites/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
@@ -19,6 +19,11 @@ The web client of Lumina is a themed shell: every page is rendered inside the te
|
||||
- [The audio player sub templates](#the-audio-player-sub-templates)
|
||||
- [The Navigation Template (shared/nav-menu)](#the-navigation-template-sharednav-menu)
|
||||
- [Page Templates](#page-templates)
|
||||
- [The Playlist Pages](#the-playlist-pages)
|
||||
- [The Shared Add to Playlist Action](#the-shared-add-to-playlist-action)
|
||||
- [The Album Track Actions Menu](#the-album-track-actions-menu)
|
||||
- [The Favorites Page](#the-favorites-page)
|
||||
- [Favorite Toggles](#favorite-toggles)
|
||||
- [The Scripts Section](#the-scripts-section)
|
||||
- [Assets](#assets)
|
||||
- [Configuration Options](#configuration-options)
|
||||
@@ -171,6 +176,7 @@ Known page keys:
|
||||
| `library/written-content-library/book-library/books/index` | The books browsing page. |
|
||||
| `playlists/index` | The page that lists and deletes the playlists of the current user. |
|
||||
| `playlists/item` | The page that creates a playlist, or edits, reorders, plays and deletes an existing playlist of the current user. The `isNew` page data field tells the two modes apart. |
|
||||
| `favorites/index` | The page that lists, filters and removes the favorites of the current user across media kinds. |
|
||||
| `shared/file-system-browser` | The file system browser component shell. |
|
||||
| `shared/file-system-browser/tree-node` | The tree view node of the file system browser. |
|
||||
| `shared/file-system-browser/explorer-item` | The file system entry of the file system browser. |
|
||||
@@ -523,11 +529,11 @@ Page templates are rendered into a content section that the layout wraps. A page
|
||||
| --- | --- |
|
||||
| `isNew` | `true` on the create page, `false` on the page of an existing playlist. The same page key serves both modes. |
|
||||
| `playlistId` | The Id of the playlist the page shows, or the empty Id on the create page. |
|
||||
| `playlistJson` | The playlist metadata and only the first window of its ordered entries, serialized as JSON. `entryCount` is the total number of entries. Each entry carries `mediaItemId` and `mediaItemType`, which are generic across media kinds, together with the generic display fields `libraryId`, `collectionId`, `creatorId`, `mediaItemTitle`, `collectionTitle`, `creatorName`, `durationInSeconds` and `coverPath`. For a music entry, the collection is the album and the creator is the artist. On the create page it is an empty music playlist. |
|
||||
| `entriesWindowSize` | The number of entries in the first window. The page fetches the next windows with `getPlaylistUrl` and the same size. |
|
||||
| `playlistJson` | The playlist metadata and only the first page of its ordered entries, serialized as JSON. `entries.count` is the total number of entries, and `entries.currentPage`, `entries.perPage` and `entries.numberOfPages` describe the page. Each entry carries `mediaItemId` and `mediaItemType`, which are generic across media kinds, together with the generic display fields `libraryId`, `collectionId`, `creatorId`, `mediaItemTitle`, `collectionTitle`, `creatorName`, `durationInSeconds` and `coverPath`. For a music entry, the collection is the album and the creator is the artist. On the create page it is an empty music playlist. |
|
||||
| `entriesPerPage` | The number of entries per page the page requests. The page fetches the next pages with `getPlaylistUrl` and the same size. |
|
||||
| `createPlaylistUrl` | The route that creates a playlist. Only meaningful when `isNew` is `true`. |
|
||||
| `itemUrl` | The route template of the page of an existing playlist. The trailing `00000000-0000-0000-0000-000000000000` is replaced by the Id of the playlist, and the page script navigates to it after a successful create. |
|
||||
| `getPlaylistUrl` | The route that returns a window of the playlist. It takes `offset` and `limit` query parameters and returns `entryCount` with the window. The limit is a response-window bound of at most 1000 entries, not a cap on the playlist size. |
|
||||
| `getPlaylistUrl` | The route that returns a page of the playlist. It takes `currentPage` and `perPage` query parameters and returns `entries` with `data`, `currentPage`, `perPage`, `count` and `numberOfPages`. When both pagination parameters are omitted, every entry is returned in one page. The `perPage` is the page size the theme requests. |
|
||||
| `updatePlaylistUrl` | The route that updates the name and description of the playlist. |
|
||||
| `deletePlaylistUrl` | The route that deletes the playlist. |
|
||||
| `addEntryUrl` | The route that adds a track to the playlist. |
|
||||
@@ -543,7 +549,7 @@ Page templates are rendered into a content section that the layout wraps. A page
|
||||
|
||||
The fallback views keep these element hooks, which the application script drives: on the list page, `playlists-container`, `no-playlists` and `playlist-count`; on the item page, `playlist-details-form`, `playlist-title`, `playlist-name-input`, `playlist-description-input`, `save-playlist-button`, `cancel-playlist-button`, `play-playlist-button`, `delete-playlist-button`, `playlist-entries`, `no-tracks`, `load-more-entries-button`, `playlist-library-combobox`, `playlist-artist-combobox`, `playlist-album-combobox`, `playlist-track-combobox`, `add-track-button` and `no-music-libraries`. The four track picker controls are standard application combo boxes, not native `select` elements. A theme that restructures a page must keep the hooks the page script needs for that page.
|
||||
|
||||
The playlist rows use the same play affordance contract as the music pages: an element with `data-audio-player-play` and the `data-track-id`, `data-library-id`, `data-album-id`, `data-artist-id`, `data-title`, `data-album-title`, `data-duration` and `data-cover-art-path` attributes is handed to the global player by event delegation. The page fills `data-track-id` from the entry `mediaItemId`, because a music entry references a track. The Play playlist control fetches every window of the playlist in order, builds an explicit queue from the playable entries and starts it through the player control API, so a theme template must keep the `play-playlist-button` hook for that control.
|
||||
The playlist rows use the same play affordance contract as the music pages: an element with `data-audio-player-play` and the `data-track-id`, `data-library-id`, `data-album-id`, `data-artist-id`, `data-title`, `data-album-title`, `data-duration` and `data-cover-art-path` attributes is handed to the global player by event delegation. The page fills `data-track-id` from the entry `mediaItemId`, because a music entry references a track. The Play playlist control fetches every page of the playlist in order, builds an explicit queue from the playable entries and starts it through the player control API, so a theme template must keep the `play-playlist-button` hook for that control.
|
||||
|
||||
The playlist rows are reordered by dragging the handle with the `playlist-entry-drag-handle` class, and the row carries the `is-dragging` class while it is being dragged. The up and down controls remain available for keyboard and touch users, and the page uses the `playlist-entry-move-up`, `playlist-entry-move-down` and `playlist-entry-remove` classes to disable them while an entry mutation is in flight. A theme template that changes the row structure must keep the `playlist-entry` class and the `data-entry-id` attribute on the row, so the page script can find the row and commit its new position.
|
||||
|
||||
@@ -569,6 +575,82 @@ The player queue action does not use `addToPlaylistLabel`. Its label comes from
|
||||
|
||||
Every rendered track row of the album details page carries the same `card-actions-trigger` button with the vertical dots as the card menus, plus the `track-actions-trigger` class that places it inline in the row. The page script creates the same `card-actions-menu` markup on demand. The menu has three application actions: `card-action-add-to-playlist` opens the shared add-to-playlist dialog for that track, `card-action-add-to-queue` calls `window.LuminaAudioPlayer.instance.appendToQueueAsync(descriptor)`, and `card-action-play-all-from-here` calls `playAsync` with an explicit queue built from the clicked track and every track that follows it in the album order. The player starts the clicked track for the last action, and replaces the queue. A theme that renders the album page must keep the track row markup and the script behavior, or provide its own equivalent.
|
||||
|
||||
#### The Favorites Page
|
||||
|
||||
`favorites/index` receives a model with the following fields:
|
||||
|
||||
| Field | Content |
|
||||
| --- | --- |
|
||||
| `getFavoritesUrl` | The route that returns a page of the favorites of the current user. It takes the optional `mediaKind`, `currentPage` and `perPage` query parameters, and returns `data`, `currentPage`, `perPage`, `count` and `numberOfPages`. When both pagination parameters are omitted, every matching favorite is returned in one page. The `perPage` is the page size the theme requests; the server has no separate maximum page size, like every other paginated collection of the API. |
|
||||
| `getFavoriteStatusUrl` | The route that tells which of a list of media items of one kind are favorites of the current user. It takes the `mediaKind` query parameter and one `mediaItemIds` parameter per Id, with at most 100 Ids. |
|
||||
| `addFavoriteUrl` | The route that marks a media item as a favorite. The body carries `mediaKind` and `mediaItemId`. |
|
||||
| `removeFavoriteUrl` | The route template that removes a favorite. Its named `{mediaKind}` and `{mediaItemId}` placeholders are replaced by the media kind name and the Id of the media item. |
|
||||
| `artistUrl` | The route template of an artist page. The trailing `00000000-0000-0000-0000-000000000000` is replaced by the Id of the artist. |
|
||||
| `albumUrl` | The route template of an album page. The two `00000000-0000-0000-0000-000000000000` segments are replaced, in order, by the Ids of the artist and the album. |
|
||||
| `trackUrl` | The route template of a track page. The three `00000000-0000-0000-0000-000000000000` segments are replaced, in order, by the Ids of the artist, the album and the track. |
|
||||
| `bookUrl` | The route template of a book page. The trailing `00000000-0000-0000-0000-000000000000` is replaced by the Id of the book. |
|
||||
| `antiforgeryToken` | The anti-forgery token the page submits with its mutating requests. |
|
||||
| `strings` | The localized strings of the page, keyed by their resource names. |
|
||||
|
||||
The pages of the media items read the library of the item from the `libraryId` query parameter, so the page script appends `libraryId` to the link of an item from the `libraryId` of the favorite. The link of a track needs the artist and the album of the item, which are the `creatorId` and the `collectionId` of the favorite. An item of the response with `isAvailable` set to `false` has no library and no display fields, so the page shows it as an unavailable item, without a link, and keeps its heart so the favorite can still be removed. The generic display fields of an item are `title`, `collectionTitle`, `creatorName` and `coverPath`; for a track the collection is the album and the creator is the artist, for an album the creator is the artist, for a book the creator is its first author, and for an artist there is neither. The series of a book is not catalogued yet, so a book has no collection.
|
||||
|
||||
The fallback view keeps these element hooks, which the application script drives: `favorites-container`, `no-favorites`, `favorite-count`, `favorites-kind-filter`, `load-more-favorites-button` and `retry-favorites-button`. The bundled themes ship no template for `favorites/index`, so the fallback view is what a healthy site shows, and a theme that wants its own page provides `templates/favorites/index.html` and must keep the hooks the page script needs.
|
||||
|
||||
The fallback view renders one card per favorite, from the most recently favorited, in pages of 50 that `load-more-favorites-button` extends. Each card carries a favorite heart (a `card-favorite-toggle` button, described below), already in the favorited state, and a favorite is removed from the page by unfavoriting its card: the page script does not call the remove route itself, the global favorites script does, and the page listens to the `lumina:favorite-changed` event described below, removes the card of an item that is no longer a favorite, and updates the counter and the empty state without another request. A failed first page or reload clears the rendered cards and shows the localized failure message with `retry-favorites-button`, so the user can load the current filter again instead of being left with a truncated list. A theme template that renders the page itself gets the same behavior by rendering hearts on its cards and handling that event.
|
||||
|
||||
#### Favorite Toggles
|
||||
|
||||
A favorite toggle is the heart of a media card or of a track row. It is rendered by a page or by a theme template, and it is driven entirely by the global script `wwwroot/js/favorites.js`, which every layout loads next to `playlists.js`. The script binds one click listener and one mutation observer on the document, so a toggle works anywhere in the swapped page content, including toggles that a page script adds later, and a page needs no script of its own. A theme owns the look of the toggle, and the script never renders markup: it only writes the attributes, the class and the texts described below.
|
||||
|
||||
A toggle is any focusable element, normally a `button`, that carries these attributes:
|
||||
|
||||
| Attribute | Meaning |
|
||||
| --- | --- |
|
||||
| `data-favorite-toggle` | Required. Marks the element as a favorite toggle. |
|
||||
| `data-favorite-media-kind` | Required. The media kind of the item: `MusicArtist`, `MusicAlbum`, `MusicTrack` or `Book`. The name is matched case insensitively. The planned kinds `Video` and `Photo` cannot be favorited yet, so a toggle that carries one stays in the `failed` state. |
|
||||
| `data-favorite-media-item-id` | Required. The Id of the media item. An empty or malformed Id leaves the toggle in the `failed` state. |
|
||||
|
||||
The script reads which items the current user favorited with `getFavoriteStatusUrl` and writes the result on the toggle. It collects the toggles of a tick and sends one status request per kind, deduplicates the Ids, and splits the Ids of a kind into requests of at most 100, so a page that renders many toggles costs few requests. The script writes these on the element:
|
||||
|
||||
| Written on the toggle | Meaning |
|
||||
| --- | --- |
|
||||
| `aria-pressed` | `true` when the item is a favorite, `false` otherwise. It keeps the previous value while a request is in flight. |
|
||||
| `data-favorite-state` | `favorited` or `not-favorited` when the state is known, `loading` while the state is read or a change is in flight, and `failed` when the state could not be read or the attributes are invalid. |
|
||||
| `is-favorite` class | Present exactly when the item is a favorite. |
|
||||
| `aria-busy` | `true` only while the state is loading or a change is in flight. |
|
||||
| `aria-label` | The localized name of the action the next click performs: the `remove` string when the item is a favorite, the `add` string otherwise. |
|
||||
| `title` | The same localized text as the `aria-label`. It is the hover text of a heart, which has no visible text. |
|
||||
| The text of `.favorite-toggle-label` | When the toggle contains an element with the `favorite-toggle-label` class, the same localized text as the `aria-label`. The bundled themes and the application views render no such element. |
|
||||
|
||||
A theme restyles a toggle from the `is-favorite` class or from the `aria-pressed` and `data-favorite-state` attributes. Until the first state arrives the toggle shows `loading`, so a theme should not style a toggle that has no state yet as pressed.
|
||||
|
||||
A click on a toggle adds the favorite when the item is not one, and removes it otherwise, through the add and remove routes of the configuration. A click is ignored while a request for the same item is in flight, whichever toggle of the item it comes from, and a click on a toggle whose state is unknown reads the state again instead of guessing. The script keeps every toggle of the same item on the page in sync. When a change fails, every toggle returns to the state it had, and the global API helper shows the failure as a notification. When a state read fails, the global API helper shows the failure as a notification. The click handler prevents the default action, so a toggle inside a link or a card does not also navigate.
|
||||
|
||||
After every successful change the script dispatches the `lumina:favorite-changed` event on `document`, with `detail` carrying `mediaKind` (the canonical kind name), `mediaItemId` (the lowercase Id) and `isFavorite` (the new state), so a page that lists favorites can react while it stays decoupled from the toggle that caused the change.
|
||||
|
||||
The layout provides the shared configuration as `window.favoritesConfiguration`:
|
||||
|
||||
| Field | Content |
|
||||
| --- | --- |
|
||||
| `getFavoriteStatusUrl` | The route that tells which of the checked media items are favorites. |
|
||||
| `addFavoriteUrl` | The route that marks a media item as a favorite. The body carries `mediaKind` and `mediaItemId`. |
|
||||
| `removeFavoriteUrlTemplate` | The route template that removes a favorite. Its named `{mediaKind}` and `{mediaItemId}` placeholders are replaced by the media kind name and the Id of the media item. |
|
||||
| `strings` | The localized labels: `add` and `remove`. |
|
||||
|
||||
The script also exposes `window.LuminaFavorites` for page scripts that need more than the markup contract:
|
||||
|
||||
| Member | Behavior |
|
||||
| --- | --- |
|
||||
| `hydrate(rootElement)` | Reads the state of the toggles inside the element, the whole document by default, and writes it on them. It never rejects. The script already hydrates the toggles of the page and the ones added to it, so this is only needed for toggles in an element that is not attached to the document. |
|
||||
| `isFavorite(mediaKind, mediaItemId)` | Returns a promise of whether the item is a favorite. The answer always comes from the server, and the check is batched with the others of the same tick. It rejects when the kind or the Id is invalid, or when the request failed. |
|
||||
| `setFavoriteAsync(mediaKind, mediaItemId, shouldFavorite)` | Adds or removes the favorite, with the same in-flight rule, synchronization and failure notification from the global API helper as a click, and returns a promise of whether the item now has the requested state. A call for an item that is already being changed returns the running change when it asks for the same state, and `false` otherwise. |
|
||||
|
||||
The hearts are rendered on the cards of the books list, of the artists list and of the albums on the artist page (the kinds `Book`, `MusicArtist` and `MusicAlbum`), on the cards of the favorites page, and on the rows of the track table of the album page (the kind `MusicTrack`, after the duration). The detail pages of an artist, an album, a track and a book render no toggle. The audio player bar and the playlist rows have none either, so a theme should not assume they exist.
|
||||
|
||||
A card heart is a plain `button` with the `card-favorite-toggle` class, with the three data attributes and nothing else, appended to the `media-card` element as a sibling of the `media-panel` link and of the `card-actions-trigger`. The stylesheet draws the heart with `::after`, like the dots of the actions trigger. The heart has the box of the actions trigger, sits immediately on its left, is shown on hover, while the actions menu of the card is open, and while any control of the card has the focus, shows the heart in the blue of the trigger, and shows it in red when the item is a favorite (`aria-pressed="true"` or the `is-favorite` class). A heart in the `loading` state is dimmed, and one in the `failed` state has an error border. A `media-card` that has no `card-actions-trigger`, like the cards of the favorites page, gets the heart in the place of the trigger, always visible so that it stays reachable by keyboard and on touch screens. A track row heart is a `button` with the `card-favorite-toggle track-favorite-toggle` classes inside a `td` with the `track-favorite-cell` class that follows the duration cell, and the `colgroup` of the table gets a `col` with the `track-favorite-column` class after the duration column. It is static, always visible and centered, like the actions trigger of the row. The hover text of every heart is the `title` that the script writes.
|
||||
|
||||
The bundled themes render the hearts on those cards and rows, and carry the card rules in their `assets/site.css`; the rules of the track row and of its columns are in the application stylesheet, `wwwroot/css/site.css`, which every page loads. The application fallback views render the same hearts. A custom theme that replaces one of these templates must render the hearts again to keep favoriting reachable from that page.
|
||||
|
||||
### The Scripts Section
|
||||
|
||||
JavaScript is always allowed in themes: script elements in templates are served and rendered as-is, and script files under `assets/` are served normally. A theme relies on scripts for the client side navigation of the application, because pages are swapped in place by the global AJAX navigator, so themes are expected to ship their own JavaScript. Because JavaScript is enabled, *themes can execute malicious code*, so, be aware about the source of your installed themes! Themes bundled with the application are reviewed and safe.
|
||||
|
||||
Reference in new issue
Block a user