mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Merge pull request #270 from BinaryAlley/feature/save-provider-configuration-with-library
Configures library providers in the same step as the library
This commit is contained in:
292 files changed
+12023
-8429
No files matched your search
@@ -21,7 +21,7 @@ A media library is how you tell Lumina where a part of your collection lives and
|
|||||||
|
|
||||||
## What a library is
|
## What a library is
|
||||||
|
|
||||||
A library is a name, a media type, and one or more content locations. It belongs to the user who created it, but administrators, and anyone holding the permission to create libraries, can manage any library, including the ones they did not create.
|
A library is a name, a media type, and one or more content locations. It belongs to the user who created it. Only its owner can change or delete it, and only while they hold the permission to create libraries, so withholding that permission keeps a user from changing even the libraries they own. Administrators can change and delete any library. The libraries page only shows the edit and delete actions to users who hold that permission and to administrators.
|
||||||
|
|
||||||
The library keeps a catalogue of the items it indexed, together with their metadata and artwork. Your actual files stay exactly where they are and are only read, except for the one opt-in setting that writes metadata back (see below).
|
The library keeps a catalogue of the items it indexed, together with their metadata and artwork. Your actual files stay exactly where they are and are only read, except for the one opt-in setting that writes metadata back (see below).
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ The library keeps a catalogue of the items it indexed, together with their metad
|
|||||||
|
|
||||||
Lumina can scan two kinds of libraries today:
|
Lumina can scan two kinds of libraries today:
|
||||||
|
|
||||||
- **Book** libraries, for books and e-books. During discovery Lumina recognizes these file extensions: `.pdf`, `.epub`, `.mobi`, `.azw`, `.azw3`, `.cbz`, `.cbr`, `.djvu`, `.fb2`, `.lit`, `.prc`, `.txt`, `.doc`, `.docx` and `.rtf`. Of those, the ones a user can open and read in the browser depend on the enabled reader plugins. The EPUB and PDF readers are bundled with Lumina, but readers are disabled by default, so a freshly created book library cannot open any book until you enable one for it. The rest are still indexed and listed in the catalogue, but cannot be opened for reading until a reader for their format is enabled.
|
- **Book** libraries, for books and e-books. During discovery Lumina recognizes these file extensions: `.pdf`, `.epub`, `.mobi`, `.azw`, `.azw3`, `.cbz`, `.cbr`, `.djvu`, `.fb2`, `.lit`, `.prc`, `.txt`, `.doc`, `.docx` and `.rtf`. Of those, the ones a user can open and read in the browser depend on the enabled reader plugins. The EPUB and PDF readers are bundled with Lumina, but readers are disabled by default, so a book library cannot open any book until you enable a reader for it. The rest are still indexed and listed in the catalogue, but cannot be opened for reading until a reader for their format is enabled.
|
||||||
- **Music** libraries, for artists, albums and tracks. During discovery Lumina recognizes these file extensions: `.mp3`, `.flac`, `.m4a`, `.aac`, `.ogg`, `.opus`, `.wav`, `.wma`, `.aiff`, `.aif`, `.ape`, `.wv`, `.dsf`, `.dff` and `.mka`.
|
- **Music** libraries, for artists, albums and tracks. During discovery Lumina recognizes these file extensions: `.mp3`, `.flac`, `.m4a`, `.aac`, `.ogg`, `.opus`, `.wav`, `.wma`, `.aiff`, `.aif`, `.ape`, `.wv`, `.dsf`, `.dff` and `.mka`.
|
||||||
|
|
||||||
The other types in Lumina's model, such as movies, TV shows, comics, manga, photos, podcasts and audiobooks, are designed but not implemented yet. There is no scanner for them, so they cannot be scanned.
|
The other types in Lumina's model, such as movies, TV shows, comics, manga, photos, podcasts and audiobooks, are designed but not implemented yet. There is no scanner for them, so they cannot be scanned.
|
||||||
@@ -55,9 +55,12 @@ Open the Libraries management page, choose to add a library, and fill in the for
|
|||||||
| Track consumption progress | the type default | Whether the latest playback or reading position of the library's items is remembered, so a user can resume where they left off. |
|
| Track consumption progress | the type default | Whether the latest playback or reading position of the library's items is remembered, so a user can resume where they left off. |
|
||||||
| Completion threshold | the type default | The percentage of an item that must be consumed for a stopped session to be recorded as completed. Empty means completion is recorded only when it is reported explicitly. |
|
| Completion threshold | the type default | The percentage of an item that must be consumed for a stopped session to be recorded as completed. Empty means completion is recorded only when it is reported explicitly. |
|
||||||
| Path template | the type's ideal structure | Tells Lumina how your folders are arranged on disk. Unless you customize it, it holds the default template of the library type, which is exactly the structure Lumina expects. Optional, and explained in full below. |
|
| Path template | the type's ideal structure | Tells Lumina how your folders are arranged on disk. Unless you customize it, it holds the default template of the library type, which is exactly the structure Lumina expects. Optional, and explained in full below. |
|
||||||
|
| Metadata providers, artwork providers, book readers | all off | The plugins that fill in the library's metadata and artwork, and, for a book library, open its books. The form lists the ones that support the selected type and refreshes the lists when you change the type. Each is switched on or off, and providers are put in order. A section is hidden when no installed plugin offers that kind of provider for the type. See [Plugins](../plugins/index.md). |
|
||||||
|
|
||||||
A library that is disabled or locked is never scanned, so those two settings double as a pause switch, and `Locked` also freezes edits.
|
A library that is disabled or locked is never scanned, so those two settings double as a pause switch, and `Locked` also freezes edits.
|
||||||
|
|
||||||
|
Everything on the form, provider choices included, is saved in one step when you save the library.
|
||||||
|
|
||||||
## Path templates
|
## Path templates
|
||||||
|
|
||||||
To make sense of your files, Lumina needs to know how they are arranged. A path template describes that arrangement as an ordered list of parts, and Lumina uses it to pull values such as an author and a title, or an artist, a release and a track number, straight out of the folder and file names.
|
To make sense of your files, Lumina needs to know how they are arranged. A path template describes that arrangement as an ordered list of parts, and Lumina uses it to pull values such as an author and a title, or an artist, a release and a track number, straight out of the folder and file names.
|
||||||
@@ -132,7 +135,7 @@ A disabled or locked library is refused a scan, and a library whose type has no
|
|||||||
|
|
||||||
Editing a library reopens the same form, and changes take effect on the next scan. Beyond the fields above, two things change the wider picture:
|
Editing a library reopens the same form, and changes take effect on the next scan. Beyond the fields above, two things change the wider picture:
|
||||||
|
|
||||||
- Changing the **type** of an existing library also reconciles the metadata, artwork and reader provider settings of that library, so they match the plugins that support the new type.
|
- Changing the **type** of an existing library updates the provider lists on the form right away, so you can adjust them before saving: providers the library already has keep their on or off setting and their order when the new type still supports them, providers that only the new type supports are added switched off, and providers the new type does not support are removed, together with their settings, when you save.
|
||||||
- Changing the **content locations** takes effect on the next scan. Items found under a location you removed are dropped from the catalogue, along with the metadata and artwork Lumina had stored for them, and items under a location you added are picked up.
|
- Changing the **content locations** takes effect on the next scan. Items found under a location you removed are dropped from the catalogue, along with the metadata and artwork Lumina had stored for them, and items under a location you added are picked up.
|
||||||
|
|
||||||
## Progress tracking and completion thresholds
|
## Progress tracking and completion thresholds
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ There is no uninstall button. To remove a plugin, delete its assembly (and any f
|
|||||||
|
|
||||||
## Enabling, ranking and configuring
|
## Enabling, ranking and configuring
|
||||||
|
|
||||||
Plugins themselves are installed once, but they are turned on per library. Open a library to edit it and you will find a section for metadata providers and one for artwork providers. A book library has one more, for its book readers:
|
Plugins themselves are installed once, but they are turned on per library. The form has a section for metadata providers and one for artwork providers, and a book library has one more, for its book readers. Your choices are saved together with the rest of the library:
|
||||||
|
|
||||||
- **Metadata providers.** Each is switched on or off, and ordered. The providers are tried in that order, the first one that produces a result is used, and, when you enable the `Aggregate metadata when missing` setting, the fields it left empty are filled from the providers that come after it.
|
- **Metadata providers.** Each is switched on or off, and ordered. The providers are tried in that order, the first one that produces a result is used, and, when you enable the `Aggregate metadata when missing` setting, the fields it left empty are filled from the providers that come after it.
|
||||||
- **Artwork providers.** The same idea for images: switched on or off, and ordered, so you decide which source wins when more than one has something.
|
- **Artwork providers.** The same idea for images: switched on or off, and ordered, so you decide which source wins when more than one has something.
|
||||||
|
|||||||
@@ -68,10 +68,25 @@ POST api/v1/libraries
|
|||||||
"isContentOnSsd": false,
|
"isContentOnSsd": false,
|
||||||
"shouldTrackConsumptionProgress": true,
|
"shouldTrackConsumptionProgress": true,
|
||||||
"completionThresholdPercentage": 100,
|
"completionThresholdPercentage": 100,
|
||||||
"pathTemplateParts": []
|
"pathTemplateParts": [],
|
||||||
|
"metadataProviders": [
|
||||||
|
{
|
||||||
|
"pluginId": "f4c1a7de-3b52-4e6a-9d21-8c7e5b04a1f3",
|
||||||
|
"isEnabled": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"artworkProviders": null,
|
||||||
|
"bookReaders": [
|
||||||
|
{
|
||||||
|
"pluginId": "f0d1a2b3-4c5d-4e6f-8a7b-9c0d1e2f3a4b",
|
||||||
|
"isEnabled": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `metadataProviders`, `artworkProviders` and `bookReaders` lists configure the providers and readers of the library in the same request: each entry names a plugin returned by the matching `GET api/v1/libraries/{metadata-providers|artwork-providers|book-readers}/{libraryType}` request, and whether it is enabled, and the order of the provider entries is the order in which the providers are tried. A supported plugin left out of a list is added disabled, after the listed ones. The `isEnabled` of an entry can be omitted, in which case the stored state is kept and a provider without one starts disabled, so a list can reorder providers without changing their state. A list that is `null` or absent adds every supported plugin disabled, in alphabetical order. A plugin that does not support the library type fails the request with `PluginNotSupportedForLibraryType`.
|
||||||
|
|
||||||
#### Add Library Response
|
#### Add Library Response
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@@ -231,7 +246,6 @@ PUT api/v1/libraries/{id}
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"id": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
"id": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
||||||
"userId": "2cff0c0f-3a67-4e30-b94f-f4e948a3b64f",
|
|
||||||
"title": "Books",
|
"title": "Books",
|
||||||
"libraryType": "Book",
|
"libraryType": "Book",
|
||||||
"contentLocations": [
|
"contentLocations": [
|
||||||
@@ -246,10 +260,22 @@ PUT api/v1/libraries/{id}
|
|||||||
"isContentOnSsd": false,
|
"isContentOnSsd": false,
|
||||||
"shouldTrackConsumptionProgress": true,
|
"shouldTrackConsumptionProgress": true,
|
||||||
"completionThresholdPercentage": 100,
|
"completionThresholdPercentage": 100,
|
||||||
"pathTemplateParts": []
|
"pathTemplateParts": [],
|
||||||
|
"metadataProviders": [
|
||||||
|
{
|
||||||
|
"pluginId": "f4c1a7de-3b52-4e6a-9d21-8c7e5b04a1f3",
|
||||||
|
"isEnabled": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"artworkProviders": null,
|
||||||
|
"bookReaders": null
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Updating a library requires being its owner and holding the `CanCreateLibraries` permission, or being an admin, who can update any library; any other user is answered with `403 NotAuthorized` before the cover image is read. The owner of the library is the user who created it: an update never changes it, so the request carries no owner.
|
||||||
|
|
||||||
|
The `metadataProviders`, `artworkProviders` and `bookReaders` lists work as for [Add Library](#add-library). A list that is sent also removes the stored configurations of the plugins that do not support the library type, even when the list does not name them, and keeps the stored state of the supported plugins it leaves out, ordering them after the listed ones. A list that is `null` or absent keeps the stored configurations when the library type is unchanged, and when the type changes, removes the configurations of the plugins that do not support the new type and adds the newly supported plugins disabled.
|
||||||
|
|
||||||
#### Update Library Response
|
#### Update Library Response
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@@ -288,6 +314,8 @@ PUT api/v1/libraries/{id}
|
|||||||
DELETE api/v1/libraries/{id}
|
DELETE api/v1/libraries/{id}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Deleting a library requires being its owner and holding the `CanCreateLibraries` permission, or being an admin, who can delete any library; any other user is answered with `403 NotAuthorized`.
|
||||||
|
|
||||||
#### Delete Library Response
|
#### Delete Library Response
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@@ -17,27 +17,21 @@
|
|||||||
- [Get Library Metadata Providers](#get-library-metadata-providers)
|
- [Get Library Metadata Providers](#get-library-metadata-providers)
|
||||||
- [Get Library Metadata Providers Request](#get-library-metadata-providers-request)
|
- [Get Library Metadata Providers Request](#get-library-metadata-providers-request)
|
||||||
- [Get Library Metadata Providers Response](#get-library-metadata-providers-response)
|
- [Get Library Metadata Providers Response](#get-library-metadata-providers-response)
|
||||||
- [Set Library Metadata Provider Enabled](#set-library-metadata-provider-enabled)
|
|
||||||
- [Set Library Metadata Provider Enabled Request](#set-library-metadata-provider-enabled-request)
|
|
||||||
- [Set Library Metadata Provider Enabled Response](#set-library-metadata-provider-enabled-response)
|
|
||||||
- [Reorder Library Metadata Providers](#reorder-library-metadata-providers)
|
|
||||||
- [Reorder Library Metadata Providers Request](#reorder-library-metadata-providers-request)
|
|
||||||
- [Reorder Library Metadata Providers Response](#reorder-library-metadata-providers-response)
|
|
||||||
- [Get Library Artwork Providers](#get-library-artwork-providers)
|
- [Get Library Artwork Providers](#get-library-artwork-providers)
|
||||||
- [Get Library Artwork Providers Request](#get-library-artwork-providers-request)
|
- [Get Library Artwork Providers Request](#get-library-artwork-providers-request)
|
||||||
- [Get Library Artwork Providers Response](#get-library-artwork-providers-response)
|
- [Get Library Artwork Providers Response](#get-library-artwork-providers-response)
|
||||||
- [Set Library Artwork Provider Enabled](#set-library-artwork-provider-enabled)
|
|
||||||
- [Set Library Artwork Provider Enabled Request](#set-library-artwork-provider-enabled-request)
|
|
||||||
- [Set Library Artwork Provider Enabled Response](#set-library-artwork-provider-enabled-response)
|
|
||||||
- [Reorder Library Artwork Providers](#reorder-library-artwork-providers)
|
|
||||||
- [Reorder Library Artwork Providers Request](#reorder-library-artwork-providers-request)
|
|
||||||
- [Reorder Library Artwork Providers Response](#reorder-library-artwork-providers-response)
|
|
||||||
- [Get Library Book Readers](#get-library-book-readers)
|
- [Get Library Book Readers](#get-library-book-readers)
|
||||||
- [Get Library Book Readers Request](#get-library-book-readers-request)
|
- [Get Library Book Readers Request](#get-library-book-readers-request)
|
||||||
- [Get Library Book Readers Response](#get-library-book-readers-response)
|
- [Get Library Book Readers Response](#get-library-book-readers-response)
|
||||||
- [Set Library Book Reader Enabled](#set-library-book-reader-enabled)
|
- [Get Library Type Metadata Providers](#get-library-type-metadata-providers)
|
||||||
- [Set Library Book Reader Enabled Request](#set-library-book-reader-enabled-request)
|
- [Get Library Type Metadata Providers Request](#get-library-type-metadata-providers-request)
|
||||||
- [Set Library Book Reader Enabled Response](#set-library-book-reader-enabled-response)
|
- [Get Library Type Metadata Providers Response](#get-library-type-metadata-providers-response)
|
||||||
|
- [Get Library Type Artwork Providers](#get-library-type-artwork-providers)
|
||||||
|
- [Get Library Type Artwork Providers Request](#get-library-type-artwork-providers-request)
|
||||||
|
- [Get Library Type Artwork Providers Response](#get-library-type-artwork-providers-response)
|
||||||
|
- [Get Library Type Book Readers](#get-library-type-book-readers)
|
||||||
|
- [Get Library Type Book Readers Request](#get-library-type-book-readers-request)
|
||||||
|
- [Get Library Type Book Readers Response](#get-library-type-book-readers-response)
|
||||||
- [Music Plugins](#music-plugins)
|
- [Music Plugins](#music-plugins)
|
||||||
|
|
||||||
## Plugins
|
## Plugins
|
||||||
@@ -200,7 +194,7 @@ PUT api/v1/plugins/{pluginId}/settings
|
|||||||
GET api/v1/libraries/{libraryId}/metadata-providers
|
GET api/v1/libraries/{libraryId}/metadata-providers
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the metadata providers available for the media library, one entry per plugin that provides metadata, along with whether the provider is enabled for the media library and its rank, which determines the order in which the providers are tried.
|
Returns the metadata providers available for the media library, one entry per plugin that provides metadata, along with whether the provider is enabled for the media library and its rank, which determines the order in which the providers are tried. The enabled state and the rank are changed by sending the `metadataProviders` of the [Add Library](../library/management/Api.Libraries.md#add-library) or [Update Library](../library/management/Api.Libraries.md#update-library) request.
|
||||||
|
|
||||||
#### Get Library Metadata Providers Response
|
#### Get Library Metadata Providers Response
|
||||||
|
|
||||||
@@ -219,52 +213,6 @@ Returns the metadata providers available for the media library, one entry per pl
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set Library Metadata Provider Enabled
|
|
||||||
|
|
||||||
#### Set Library Metadata Provider Enabled Request
|
|
||||||
|
|
||||||
```js
|
|
||||||
PUT api/v1/libraries/{libraryId}/metadata-providers/{pluginId}/enabled
|
|
||||||
```
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
|
||||||
"pluginId": "f4c1a7de-3b52-4e6a-9d21-8c7e5b04a1f3",
|
|
||||||
"isEnabled": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Set Library Metadata Provider Enabled Response
|
|
||||||
|
|
||||||
```js
|
|
||||||
200 Ok
|
|
||||||
```
|
|
||||||
|
|
||||||
### Reorder Library Metadata Providers
|
|
||||||
|
|
||||||
#### Reorder Library Metadata Providers Request
|
|
||||||
|
|
||||||
```js
|
|
||||||
PUT api/v1/libraries/{libraryId}/metadata-providers/reorder
|
|
||||||
```
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
|
||||||
"pluginIds": [
|
|
||||||
"f4c1a7de-3b52-4e6a-9d21-8c7e5b04a1f3",
|
|
||||||
"a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Reorder Library Metadata Providers Response
|
|
||||||
|
|
||||||
```js
|
|
||||||
200 Ok
|
|
||||||
```
|
|
||||||
|
|
||||||
### Get Library Artwork Providers
|
### Get Library Artwork Providers
|
||||||
|
|
||||||
#### Get Library Artwork Providers Request
|
#### Get Library Artwork Providers Request
|
||||||
@@ -273,7 +221,7 @@ PUT api/v1/libraries/{libraryId}/metadata-providers/reorder
|
|||||||
GET api/v1/libraries/{libraryId}/artwork-providers
|
GET api/v1/libraries/{libraryId}/artwork-providers
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the artwork providers available for the media library, one entry per plugin that provides artwork, along with whether the provider is enabled for the media library and its rank, which determines the order in which the providers are tried when resolving the artwork.
|
Returns the artwork providers available for the media library, one entry per plugin that provides artwork, along with whether the provider is enabled for the media library and its rank, which determines the order in which the providers are tried when resolving the artwork. The enabled state and the rank are changed by sending the `artworkProviders` of the [Add Library](../library/management/Api.Libraries.md#add-library) or [Update Library](../library/management/Api.Libraries.md#update-library) request.
|
||||||
|
|
||||||
#### Get Library Artwork Providers Response
|
#### Get Library Artwork Providers Response
|
||||||
|
|
||||||
@@ -298,52 +246,6 @@ Returns the artwork providers available for the media library, one entry per plu
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set Library Artwork Provider Enabled
|
|
||||||
|
|
||||||
#### Set Library Artwork Provider Enabled Request
|
|
||||||
|
|
||||||
```js
|
|
||||||
PUT api/v1/libraries/{libraryId}/artwork-providers/{pluginId}/enabled
|
|
||||||
```
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
|
||||||
"pluginId": "b7e4c2a9-1f38-4d65-9a02-3e6b8f5c7d14",
|
|
||||||
"isEnabled": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Set Library Artwork Provider Enabled Response
|
|
||||||
|
|
||||||
```js
|
|
||||||
200 Ok
|
|
||||||
```
|
|
||||||
|
|
||||||
### Reorder Library Artwork Providers
|
|
||||||
|
|
||||||
#### Reorder Library Artwork Providers Request
|
|
||||||
|
|
||||||
```js
|
|
||||||
PUT api/v1/libraries/{libraryId}/artwork-providers/reorder
|
|
||||||
```
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
|
||||||
"pluginIds": [
|
|
||||||
"c9f1a7d3-2b64-4e18-8f05-7a3d9c1b6e42",
|
|
||||||
"b7e4c2a9-1f38-4d65-9a02-3e6b8f5c7d14"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Reorder Library Artwork Providers Response
|
|
||||||
|
|
||||||
```js
|
|
||||||
200 Ok
|
|
||||||
```
|
|
||||||
|
|
||||||
### Get Library Book Readers
|
### Get Library Book Readers
|
||||||
|
|
||||||
#### Get Library Book Readers Request
|
#### Get Library Book Readers Request
|
||||||
@@ -352,7 +254,7 @@ PUT api/v1/libraries/{libraryId}/artwork-providers/reorder
|
|||||||
GET api/v1/libraries/{libraryId}/book-readers
|
GET api/v1/libraries/{libraryId}/book-readers
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the book readers available for the media library, one entry per plugin that provides a book reader, along with whether the reader is enabled for the media library. A book can be opened for reading only through a book reader that is enabled for its media library.
|
Returns the book readers available for the media library, one entry per plugin that provides a book reader, along with whether the reader is enabled for the media library. A book can be opened for reading only through a book reader that is enabled for its media library. The enabled state is changed by sending the `bookReaders` of the [Add Library](../library/management/Api.Libraries.md#add-library) or [Update Library](../library/management/Api.Libraries.md#update-library) request.
|
||||||
|
|
||||||
#### Get Library Book Readers Response
|
#### Get Library Book Readers Response
|
||||||
|
|
||||||
@@ -381,31 +283,98 @@ Returns the book readers available for the media library, one entry per plugin t
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set Library Book Reader Enabled
|
### Get Library Type Metadata Providers
|
||||||
|
|
||||||
#### Set Library Book Reader Enabled Request
|
#### Get Library Type Metadata Providers Request
|
||||||
|
|
||||||
```js
|
```js
|
||||||
PUT api/v1/libraries/{libraryId}/book-readers/{pluginId}/enabled
|
GET api/v1/libraries/metadata-providers/{libraryType}
|
||||||
```
|
```
|
||||||
|
|
||||||
```json
|
Returns the metadata providers available for a media library type, without a media library, so that the providers of a library can be chosen before it is created or before a change of its type is saved. The providers are returned the way a new media library of the type starts with them: disabled, and ranked in alphabetical order.
|
||||||
{
|
|
||||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
|
||||||
"pluginId": "f0d1a2b3-4c5d-4e6f-8a7b-9c0d1e2f3a4b",
|
|
||||||
"isEnabled": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Set Library Book Reader Enabled Response
|
#### Get Library Type Metadata Providers Response
|
||||||
|
|
||||||
```js
|
```js
|
||||||
200 Ok
|
200 Ok
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pluginId": "f4c1a7de-3b52-4e6a-9d21-8c7e5b04a1f3",
|
||||||
|
"name": "MusicBrainz Metadata",
|
||||||
|
"isEnabled": false,
|
||||||
|
"rank": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Get Library Type Artwork Providers
|
||||||
|
|
||||||
|
#### Get Library Type Artwork Providers Request
|
||||||
|
|
||||||
|
```js
|
||||||
|
GET api/v1/libraries/artwork-providers/{libraryType}
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns the artwork providers available for a media library type, without a media library, disabled and ranked in alphabetical order.
|
||||||
|
|
||||||
|
#### Get Library Type Artwork Providers Response
|
||||||
|
|
||||||
|
```js
|
||||||
|
200 Ok
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pluginId": "b7e4c2a9-1f38-4d65-9a02-3e6b8f5c7d14",
|
||||||
|
"name": "Cover Art Archive",
|
||||||
|
"isEnabled": false,
|
||||||
|
"rank": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pluginId": "c9f1a7d3-2b64-4e18-8f05-7a3d9c1b6e42",
|
||||||
|
"name": "Local Music Artwork",
|
||||||
|
"isEnabled": false,
|
||||||
|
"rank": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Get Library Type Book Readers
|
||||||
|
|
||||||
|
#### Get Library Type Book Readers Request
|
||||||
|
|
||||||
|
```js
|
||||||
|
GET api/v1/libraries/book-readers/{libraryType}
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns the book readers available for a media library type, without a media library, with their supported file extensions, disabled and in alphabetical order.
|
||||||
|
|
||||||
|
#### Get Library Type Book Readers Response
|
||||||
|
|
||||||
|
```js
|
||||||
|
200 Ok
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pluginId": "f0d1a2b3-4c5d-4e6f-8a7b-9c0d1e2f3a4b",
|
||||||
|
"name": "EPUB Reader",
|
||||||
|
"supportedExtensions": [
|
||||||
|
".epub"
|
||||||
|
],
|
||||||
|
"isEnabled": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## Music Plugins
|
## Music Plugins
|
||||||
|
|
||||||
The music media library type is served by four plugins, which register their capabilities through `IPluginServiceRegistrator`. A single plugin can expose more than one capability, and the capabilities are enabled and ranked per media library through the endpoints above.
|
The music media library type is served by four plugins, which register their capabilities through `IPluginServiceRegistrator`. A single plugin can expose more than one capability, and the capabilities are enabled and ranked per media library by sending the provider lists of the [Add Library](../library/management/Api.Libraries.md#add-library) or [Update Library](../library/management/Api.Libraries.md#update-library) request.
|
||||||
|
|
||||||
| Plugin | Capability | Web access | Description |
|
| Plugin | Capability | Web access | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
|||||||
@@ -123,17 +123,35 @@ class GetLibraryBookReadersQueryHandler {
|
|||||||
+ HandleAsync(query: GetLibraryBookReadersQuery, token: CancellationToken): Task<Result<IReadOnlyList<LibraryBookReaderResponse>>>
|
+ HandleAsync(query: GetLibraryBookReadersQuery, token: CancellationToken): Task<Result<IReadOnlyList<LibraryBookReaderResponse>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
class SetLibraryBookReaderEnabledCommandHandler {
|
class GetLibraryTypeBookReadersQueryHandler {
|
||||||
- _unitOfWork: IUnitOfWork
|
- _unitOfWork: IUnitOfWork
|
||||||
- _enablementCache: IBookReaderEnablementCache
|
- _providerConfigurationStore: IMediaLibraryProviderConfigurationStore
|
||||||
+ HandleAsync(command: SetLibraryBookReaderEnabledCommand, token: CancellationToken): Task<Result<Success>>
|
- _bookReaderRegistry: IBookReaderRegistry
|
||||||
|
+ HandleAsync(query: GetLibraryTypeBookReadersQuery, token: CancellationToken): Task<Result<IReadOnlyList<LibraryBookReaderResponse>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of SetLibraryBookReaderEnabledCommandHandler
|
note right of GetLibraryTypeBookReadersQueryHandler
|
||||||
Enables or disables the book reader of a plugin for a media
|
Lists the book readers that support a library type, disabled,
|
||||||
library by upserting its configuration row, then invalidates
|
so that they can be chosen before a library is created or
|
||||||
the enablement cache so that a disabled reader stops being
|
before a change of its type is saved.
|
||||||
served immediately.
|
end note
|
||||||
|
|
||||||
|
class MediaLibraryProviderConfigurationStore {
|
||||||
|
- _unitOfWork: IUnitOfWork
|
||||||
|
- _enablementCache: IBookReaderEnablementCache
|
||||||
|
+ ConfigureProvidersAsync(libraryId: Guid, libraryType: LibraryType, metadataProviders: IReadOnlyList<LibraryProviderSelectionDto>?, artworkProviders: IReadOnlyList<LibraryProviderSelectionDto>?, bookReaders: IReadOnlyList<LibraryProviderSelectionDto>?, shouldReconcileOmittedKinds: bool, token: CancellationToken): Task<Result<Success>>
|
||||||
|
+ GetSupportedBookReaderPluginIds(libraryType: LibraryType): IReadOnlyList<Guid>
|
||||||
|
}
|
||||||
|
|
||||||
|
note right of MediaLibraryProviderConfigurationStore
|
||||||
|
Called by the add and update library commands. Applies the
|
||||||
|
chosen metadata providers, artwork providers and book readers
|
||||||
|
of a media library by upserting their configuration rows in
|
||||||
|
the same save as the library. When shouldReconcileOmittedKinds
|
||||||
|
is set, the kinds without explicit choices are reconciled with
|
||||||
|
the library type first. Book reader changes invalidate the
|
||||||
|
enablement cache of the library so that a disabled reader
|
||||||
|
stops being served immediately.
|
||||||
end note
|
end note
|
||||||
|
|
||||||
' ============================== BOOK READER PLUGINS ==============================
|
' ============================== BOOK READER PLUGINS ==============================
|
||||||
@@ -221,8 +239,10 @@ BookReaderRegistry ..> IBookReader : reads the supported extensions of loaded pl
|
|||||||
|
|
||||||
GetLibraryBookReadersQueryHandler --> ILibraryBookReaderConfigurationRepository : reads configurations
|
GetLibraryBookReadersQueryHandler --> ILibraryBookReaderConfigurationRepository : reads configurations
|
||||||
GetLibraryBookReadersQueryHandler --> IBookReaderRegistry : reads supported extensions
|
GetLibraryBookReadersQueryHandler --> IBookReaderRegistry : reads supported extensions
|
||||||
SetLibraryBookReaderEnabledCommandHandler --> ILibraryBookReaderConfigurationRepository : upserts the configuration
|
GetLibraryTypeBookReadersQueryHandler --> MediaLibraryProviderConfigurationStore : reads the supported readers
|
||||||
SetLibraryBookReaderEnabledCommandHandler --> IBookReaderEnablementCache : invalidates the entry
|
GetLibraryTypeBookReadersQueryHandler --> IBookReaderRegistry : reads supported extensions
|
||||||
|
MediaLibraryProviderConfigurationStore --> ILibraryBookReaderConfigurationRepository : upserts the configurations
|
||||||
|
MediaLibraryProviderConfigurationStore --> IBookReaderEnablementCache : invalidates the library entries
|
||||||
|
|
||||||
ILibraryBookReaderConfigurationRepository --> LibraryBookReaderConfigurationEntity : persists
|
ILibraryBookReaderConfigurationRepository --> LibraryBookReaderConfigurationEntity : persists
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" data-diagram-type="CLASS" style="width:2978px;height:2599px;background:#FFFFFF;" width="2978px" height="2599px" viewBox="0 0 2978 2599" zoomAndPan="magnify" preserveAspectRatio="none" contentStyleType="text/css"><?plantuml 1.2026.7?><defs/><g font-family="sans-serif" lengthAdjust="spacing"><g class="title" data-source-line="4"><text x="1274.748" y="24.533" fill="#000" font-size="14" textLength="422.413" font-weight="700">Code diagram for Book Reading 3.2.2 and Book Reader Plugins</text></g><!--class IBookReadingService--><g class="entity" data-qualified-name="IBookReadingService" id="ent0001" data-source-line="13"><rect x="1079.5" y="45.609" width="310.054" height="558.672" fill="#FFF" style="stroke:#000;stroke-width:0.5;" rx="2.5" ry="2.5"/><ellipse cx="1162.96" cy="61.609" rx="11" ry="11" fill="#B4A7E5" style="stroke:#181818;stroke-width:1;"/><path d="M1163.913,58.25 L1163.913,64.906 L1165.632,64.906 Q1166.241,64.906 1166.507,65.141 Q1166.772,65.375 1166.772,65.766 Q1166.772,66.141 1166.507,66.375 Q1166.241,66.609 1165.632,66.609 L1160.491,66.609 Q1159.882,66.609 1159.616,66.375 Q1159.351,66.141 1159.351,65.75 Q1159.351,65.375 1159.616,65.141 Q1159.882,64.906 1160.491,64.906 L1162.21,64.906 L1162.21,58.25 L1160.491,58.25 Q1159.882,58.25 1159.616,58.016 Q1159.351,57.781 1159.351,57.391 Q1159.351,57.016 1159.616,56.781 Q1159.882,56.547 1160.491,56.547 L1165.632,56.547 Q1166.241,56.547 1166.507,56.781 Q1166.772,57.016 1166.772,57.391 Q1166.772,57.781 1166.507,58.016 Q1166.241,58.25 1165.632,58.25 L1163.913,58.25 Z " fill="#000"/><text x="1183.46" y="67.338" fill="#000" font-size="14" textLength="134.634" font-style="italic">IBookReadingService</text><line x1="1080.5" y1="77.609" x2="1388.554" y2="77.609" style="stroke:#000;stroke-width:0.5;"/><line x1="1080.5" y1="85.609" x2="1388.554" y2="85.609" style="stroke:#000;stroke-width:0.5;"/><g data-visibility-modifier="PUBLIC_METHOD"><ellipse cx="1090.5" cy="152.742" rx="3" ry="3" fill="#84BE84" style="stroke:#038048;stroke-width:1;"/></g><text x="1099.5" y="104.143" fill="#000" font-size="14" textLength="164.186">GetManifestAsync(bookId:</text><text x="1099.5" y="121.752" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1132.962" y="121.752" fill="#000" font-size="14"> </text><text x="1136.852" y="121.752" fill="#000" font-size="14" textLength="53.683">libraryId:</text><text x="1190.534" y="121.752" fill="#000" font-size="14"> </text><text x="1194.424" y="121.752" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1227.886" y="121.752" fill="#000" font-size="14"> </text><text x="1231.775" y="121.752" fill="#000" font-size="14" textLength="31.138">path:</text><text x="1099.5" y="139.361" fill="#000" font-size="14" textLength="38.124">string,</text><text x="1137.624" y="139.361" fill="#000" font-size="14"> </text><text x="1141.514" y="139.361" fill="#000" font-size="14" textLength="73.131">libraryType:</text><text x="1214.645" y="139.361" fill="#000" font-size="14"> </text><text x="1218.534" y="139.361" fill="#000" font-size="14" textLength="77.807">LibraryType,</text><text x="1099.5" y="156.971" fill="#000" font-size="14" textLength="174.323">shouldRenderPdfAsImages:</text><text x="1099.5" y="174.58" fill="#000" font-size="14" textLength="30.358">bool,</text><text x="1129.858" y="174.58" fill="#000" font-size="14"> </text><text x="1133.748" y="174.58" fill="#000" font-size="14" textLength="38.138">token:</text><text x="1099.5" y="192.189" fill="#000" font-size="14" textLength="124.51">CancellationToken):</text><text x="1099.5" y="209.799" fill="#000" font-size="14" textLength="270.826">Task<Result<ReadingManifestResponse>></text><g data-visibility-modifier="PUBLIC_METHOD"><ellipse cx="1090.5" cy="293.617" rx="3" ry="3" fill="#84BE84" style="stroke:#038048;stroke-width:1;"/></g><text x="1099.5" y="227.408" fill="#000" font-size="14" textLength="157.972">GetSectionAsync(bookId:</text><text x="1257.472" y="227.408" fill="#000" font-size="14"> </text><text x="1261.361" y="227.408" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1099.5" y="245.018" fill="#000" font-size="14" textLength="53.683">libraryId:</text><text x="1153.183" y="245.018" fill="#000" font-size="14"> </text><text x="1157.072" y="245.018" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1190.534" y="245.018" fill="#000" font-size="14"> </text><text x="1194.424" y="245.018" fill="#000" font-size="14" textLength="31.138">path:</text><text x="1225.562" y="245.018" fill="#000" font-size="14"> </text><text x="1229.451" y="245.018" fill="#000" font-size="14" textLength="38.124">string,</text><text x="1099.5" y="262.627" fill="#000" font-size="14" textLength="73.131">libraryType:</text><text x="1172.631" y="262.627" fill="#000" font-size="14"> </text><text x="1176.521" y="262.627" fill="#000" font-size="14" textLength="7Line truncated
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" data-diagram-type="CLASS" style="width:3081px;height:2599px;background:#FFFFFF;" width="3081px" height="2599px" viewBox="0 0 3081 2599" zoomAndPan="magnify" preserveAspectRatio="none" contentStyleType="text/css"><?plantuml 1.2026.7?><defs/><g font-family="sans-serif" lengthAdjust="spacing"><g class="title" data-source-line="4"><text x="1326.081" y="24.533" fill="#000" font-size="14" textLength="422.413" font-weight="700">Code diagram for Book Reading 3.2.2 and Book Reader Plugins</text></g><!--class IBookReadingService--><g class="entity" data-qualified-name="IBookReadingService" id="ent0001" data-source-line="13"><rect x="1606" y="45.609" width="310.054" height="558.672" fill="#FFF" style="stroke:#000;stroke-width:0.5;" rx="2.5" ry="2.5"/><ellipse cx="1689.46" cy="61.609" rx="11" ry="11" fill="#B4A7E5" style="stroke:#181818;stroke-width:1;"/><path d="M1690.413,58.25 L1690.413,64.906 L1692.132,64.906 Q1692.741,64.906 1693.007,65.141 Q1693.272,65.375 1693.272,65.766 Q1693.272,66.141 1693.007,66.375 Q1692.741,66.609 1692.132,66.609 L1686.991,66.609 Q1686.382,66.609 1686.116,66.375 Q1685.851,66.141 1685.851,65.75 Q1685.851,65.375 1686.116,65.141 Q1686.382,64.906 1686.991,64.906 L1688.71,64.906 L1688.71,58.25 L1686.991,58.25 Q1686.382,58.25 1686.116,58.016 Q1685.851,57.781 1685.851,57.391 Q1685.851,57.016 1686.116,56.781 Q1686.382,56.547 1686.991,56.547 L1692.132,56.547 Q1692.741,56.547 1693.007,56.781 Q1693.272,57.016 1693.272,57.391 Q1693.272,57.781 1693.007,58.016 Q1692.741,58.25 1692.132,58.25 L1690.413,58.25 Z " fill="#000"/><text x="1709.96" y="67.338" fill="#000" font-size="14" textLength="134.634" font-style="italic">IBookReadingService</text><line x1="1607" y1="77.609" x2="1915.054" y2="77.609" style="stroke:#000;stroke-width:0.5;"/><line x1="1607" y1="85.609" x2="1915.054" y2="85.609" style="stroke:#000;stroke-width:0.5;"/><g data-visibility-modifier="PUBLIC_METHOD"><ellipse cx="1617" cy="152.742" rx="3" ry="3" fill="#84BE84" style="stroke:#038048;stroke-width:1;"/></g><text x="1626" y="104.143" fill="#000" font-size="14" textLength="164.186">GetManifestAsync(bookId:</text><text x="1626" y="121.752" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1659.462" y="121.752" fill="#000" font-size="14"> </text><text x="1663.352" y="121.752" fill="#000" font-size="14" textLength="53.683">libraryId:</text><text x="1717.034" y="121.752" fill="#000" font-size="14"> </text><text x="1720.924" y="121.752" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1754.386" y="121.752" fill="#000" font-size="14"> </text><text x="1758.275" y="121.752" fill="#000" font-size="14" textLength="31.138">path:</text><text x="1626" y="139.361" fill="#000" font-size="14" textLength="38.124">string,</text><text x="1664.124" y="139.361" fill="#000" font-size="14"> </text><text x="1668.014" y="139.361" fill="#000" font-size="14" textLength="73.131">libraryType:</text><text x="1741.145" y="139.361" fill="#000" font-size="14"> </text><text x="1745.034" y="139.361" fill="#000" font-size="14" textLength="77.807">LibraryType,</text><text x="1626" y="156.971" fill="#000" font-size="14" textLength="174.323">shouldRenderPdfAsImages:</text><text x="1626" y="174.58" fill="#000" font-size="14" textLength="30.358">bool,</text><text x="1656.358" y="174.58" fill="#000" font-size="14"> </text><text x="1660.248" y="174.58" fill="#000" font-size="14" textLength="38.138">token:</text><text x="1626" y="192.189" fill="#000" font-size="14" textLength="124.51">CancellationToken):</text><text x="1626" y="209.799" fill="#000" font-size="14" textLength="270.826">Task<Result<ReadingManifestResponse>></text><g data-visibility-modifier="PUBLIC_METHOD"><ellipse cx="1617" cy="293.617" rx="3" ry="3" fill="#84BE84" style="stroke:#038048;stroke-width:1;"/></g><text x="1626" y="227.408" fill="#000" font-size="14" textLength="157.972">GetSectionAsync(bookId:</text><text x="1783.972" y="227.408" fill="#000" font-size="14"> </text><text x="1787.861" y="227.408" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1626" y="245.018" fill="#000" font-size="14" textLength="53.683">libraryId:</text><text x="1679.683" y="245.018" fill="#000" font-size="14"> </text><text x="1683.572" y="245.018" fill="#000" font-size="14" textLength="33.462">Guid,</text><text x="1717.034" y="245.018" fill="#000" font-size="14"> </text><text x="1720.924" y="245.018" fill="#000" font-size="14" textLength="31.138">path:</text><text x="1752.062" y="245.018" fill="#000" font-size="14"> </text><text x="1755.951" y="245.018" fill="#000" font-size="14" textLength="38.124">string,</text><text x="1626" y="262.627" fill="#000" font-size="14" textLength="73.131">libraryType:</text><text x="1699.131" y="262.627" fill="#000" font-size="14"> </text><text x="1703.021" y="262.627" fill="#000" font-size="14" textLength="77.807">LibraryType,</text><texLine truncated
|
||||||
|
Before Width: | Height: | Size: 155 KiB After Width: | Height: | Size: 173 KiB |
@@ -20,5 +20,8 @@ Content-Type: application/json
|
|||||||
"pathTemplateParts": [
|
"pathTemplateParts": [
|
||||||
{ "kind": "Artist", "representation": "{0}", "isOptional": false },
|
{ "kind": "Artist", "representation": "{0}", "isOptional": false },
|
||||||
{ "kind": "Separator", "representation": "", "isOptional": false }
|
{ "kind": "Separator", "representation": "", "isOptional": false }
|
||||||
]
|
],
|
||||||
|
"metadataProviders": null,
|
||||||
|
"artworkProviders": null,
|
||||||
|
"bookReaders": null
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@ Content-Type: application/json
|
|||||||
|
|
||||||
{
|
{
|
||||||
"id": "{{$guid}}",
|
"id": "{{$guid}}",
|
||||||
"userId": "{{$guid}}",
|
|
||||||
"title": "Books",
|
"title": "Books",
|
||||||
"libraryType": "Book",
|
"libraryType": "Book",
|
||||||
"contentLocations": [
|
"contentLocations": [
|
||||||
@@ -22,5 +21,8 @@ Content-Type: application/json
|
|||||||
"pathTemplateParts": [
|
"pathTemplateParts": [
|
||||||
{ "kind": "Artist", "representation": "{0}", "isOptional": false },
|
{ "kind": "Artist", "representation": "{0}", "isOptional": false },
|
||||||
{ "kind": "Separator", "representation": "", "isOptional": false }
|
{ "kind": "Separator", "representation": "", "isOptional": false }
|
||||||
]
|
],
|
||||||
|
"metadataProviders": null,
|
||||||
|
"artworkProviders": null,
|
||||||
|
"bookReaders": null
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GET {{host}}/api/v1/libraries/artwork-providers/Book
|
||||||
|
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GET {{host}}/api/v1/libraries/book-readers/Book
|
||||||
|
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GET {{host}}/api/v1/libraries/metadata-providers/Book
|
||||||
|
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
PUT {{host}}/api/v1/libraries/{{$guid}}/artwork-providers/reorder
|
|
||||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"libraryId": "{{$guid}}",
|
|
||||||
"pluginIds": [
|
|
||||||
"{{$guid}}",
|
|
||||||
"{{$guid}}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
PUT {{host}}/api/v1/libraries/{{$guid}}/metadata-providers/reorder
|
|
||||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"libraryId": "{{$guid}}",
|
|
||||||
"pluginIds": [
|
|
||||||
"{{$guid}}",
|
|
||||||
"{{$guid}}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
PUT {{host}}/api/v1/libraries/{{$guid}}/artwork-providers/{{$guid}}/enabled
|
|
||||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"libraryId": "{{$guid}}",
|
|
||||||
"pluginId": "{{$guid}}",
|
|
||||||
"isEnabled": true
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
PUT {{host}}/api/v1/libraries/{{$guid}}/book-readers/{{$guid}}/enabled
|
|
||||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"libraryId": "{{$guid}}",
|
|
||||||
"pluginId": "{{$guid}}",
|
|
||||||
"isEnabled": true
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
PUT {{host}}/api/v1/libraries/{{$guid}}/metadata-providers/{{$guid}}/enabled
|
|
||||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"libraryId": "{{$guid}}",
|
|
||||||
"pluginId": "{{$guid}}",
|
|
||||||
"isEnabled": true
|
|
||||||
}
|
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data transfer object for the choice made for one metadata provider, artwork provider or book reader of a media library, carried by the commands that create or update a media library.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="PluginId">The Id of the plugin providing the metadata provider, artwork provider or book reader.</param>
|
||||||
|
/// <param name="IsEnabled">Whether the provider or reader is enabled for the media library. When absent, the stored state is kept, and a provider or reader without a stored state starts disabled.</param>
|
||||||
|
[DebuggerDisplay("PluginId: {PluginId}; IsEnabled: {IsEnabled}")]
|
||||||
|
public record LibraryProviderSelectionDto(
|
||||||
|
Guid PluginId,
|
||||||
|
bool? IsEnabled
|
||||||
|
);
|
||||||
+43
-33
@@ -1,5 +1,6 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||||
|
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||||
using Lumina.Domain.Common.Primitives;
|
using Lumina.Domain.Common.Primitives;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
using System;
|
using System;
|
||||||
@@ -11,7 +12,7 @@ using System.Threading.Tasks;
|
|||||||
namespace Lumina.Application.Common.Infrastructure.Plugins;
|
namespace Lumina.Application.Common.Infrastructure.Plugins;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Store of the metadata and artwork provider configurations of the media libraries.
|
/// Store of the metadata provider, artwork provider and book reader configurations of the media libraries.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IMediaLibraryProviderConfigurationStore
|
public interface IMediaLibraryProviderConfigurationStore
|
||||||
{
|
{
|
||||||
@@ -24,25 +25,18 @@ public interface IMediaLibraryProviderConfigurationStore
|
|||||||
Task<Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>> GetConfigurationsAsync(Guid libraryId, CancellationToken cancellationToken);
|
Task<Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>> GetConfigurationsAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a disabled provider configuration for every loaded plugin that supports the provided library type and has no
|
/// Adds a disabled metadata provider, artwork provider and book reader configuration for every loaded plugin that supports the provided library type and has no
|
||||||
/// configuration yet for the media library identified by <paramref name="libraryId"/>.
|
/// configuration yet for the media library identified by <paramref name="libraryId"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The added configurations are only staged until the unit of work is saved, and are not visible to a later ensure, so it must be called at most once per media library before the changes are saved.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="libraryId">The Id of the media library whose provider configurations are ensured.</param>
|
/// <param name="libraryId">The Id of the media library whose provider configurations are ensured.</param>
|
||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
Task<Result<Success>> EnsureProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
Task<Result<Success>> EnsureProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Replaces the provider configurations of the media library identified by <paramref name="libraryId"/> so that they
|
|
||||||
/// match the plugins supporting the provided library type.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="libraryId">The Id of the media library whose provider configurations are reconciled.</param>
|
|
||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
||||||
Task<Result<Success>> ReconcileProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes all the provider configurations of the media library identified by <paramref name="libraryId"/>.
|
/// Deletes all the provider configurations of the media library identified by <paramref name="libraryId"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -60,36 +54,52 @@ public interface IMediaLibraryProviderConfigurationStore
|
|||||||
Task<Result<Deleted>> RemoveProviderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
|
Task<Result<Deleted>> RemoveProviderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a disabled book reader configuration for every loaded plugin that supports the provided library type and has no configuration yet, for the media library identified by <paramref name="libraryId"/>.
|
/// Makes the provider and book reader configurations of the media library identified by <paramref name="libraryId"/> match the plugins supporting the provided library type, and applies the choices made for them.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are ensured.</param>
|
/// <remarks>
|
||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
/// A list that is provided reconciles that kind of configuration with the library type and applies the choices: the configurations of the plugins that do not support the library type
|
||||||
|
/// are removed, even when the list does not name them, every supported plugin gets a configuration, and the list sets the enabled state of every provider or reader it names and, for the
|
||||||
|
/// metadata and artwork providers, their order. A choice without an enabled state keeps the stored state, the supported plugins the list does not name keep their stored state and are
|
||||||
|
/// ordered after the named ones, and a plugin without a stored configuration starts disabled. A list that is <see langword="null"/> leaves that kind of configuration untouched, unless
|
||||||
|
/// <paramref name="shouldReconcileOmittedKinds"/> is <see langword="true"/>, in which case it is reconciled the same way, without choices. Whenever the book reader configurations are
|
||||||
|
/// reconciled or chosen, the cached reader enablements of the library are dropped.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="libraryId">The Id of the media library whose provider and book reader configurations are configured.</param>
|
||||||
|
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers and book readers apply.</param>
|
||||||
|
/// <param name="metadataProviders">The choices made for the metadata providers, in the order in which they are tried.</param>
|
||||||
|
/// <param name="artworkProviders">The choices made for the artwork providers, in the order in which they are tried.</param>
|
||||||
|
/// <param name="bookReaders">The choices made for the book readers.</param>
|
||||||
|
/// <param name="shouldReconcileOmittedKinds">Whether the kinds of configuration whose list of choices is <see langword="null"/> are reconciled with the library type, which is needed when the
|
||||||
|
/// library is new or its type changed.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error when a choice names a plugin that does not support the library type.</returns>
|
||||||
Task<Result<Success>> EnsureBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
Task<Result<Success>> ConfigureProvidersAsync(
|
||||||
|
Guid libraryId,
|
||||||
|
LibraryType libraryType,
|
||||||
|
IReadOnlyList<LibraryProviderSelectionDto>? metadataProviders,
|
||||||
|
IReadOnlyList<LibraryProviderSelectionDto>? artworkProviders,
|
||||||
|
IReadOnlyList<LibraryProviderSelectionDto>? bookReaders,
|
||||||
|
bool shouldReconcileOmittedKinds,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces the book reader configurations of the media library identified by <paramref name="libraryId"/> so that they match the plugins supporting the provided library type.
|
/// Gets the Ids of the loaded plugins that provide metadata for the provided library type, ordered alphabetically by plugin name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are reconciled.</param>
|
/// <param name="libraryType">The type of the media library the metadata providers must support.</param>
|
||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
/// <returns>The Ids of the plugins providing metadata for the library type.</returns>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
IReadOnlyList<Guid> GetSupportedMetadataProviderPluginIds(LibraryType libraryType);
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
||||||
Task<Result<Success>> ReconcileBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes all the book reader configurations of the media library identified by <paramref name="libraryId"/>.
|
/// Gets the Ids of the loaded plugins that provide artwork for the provided library type, ordered alphabetically by plugin name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are deleted.</param>
|
/// <param name="libraryType">The type of the media library the artwork providers must support.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <returns>The Ids of the plugins providing artwork for the library type.</returns>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
IReadOnlyList<Guid> GetSupportedArtworkProviderPluginIds(LibraryType libraryType);
|
||||||
Task<Result<Deleted>> RemoveBookReaderConfigurationsForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes all the book reader configurations referencing the plugin identified by <paramref name="pluginId"/>.
|
/// Gets the Ids of the loaded plugins that provide a book reader for the provided library type, ordered alphabetically by plugin name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pluginId">The Id of the plugin whose book reader configurations are deleted.</param>
|
/// <param name="libraryType">The type of the media library the book readers must support.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <returns>The Ids of the plugins providing a book reader for the library type.</returns>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
IReadOnlyList<Guid> GetSupportedBookReaderPluginIds(LibraryType libraryType);
|
||||||
Task<Result<Deleted>> RemoveBookReaderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
|
|
||||||
}
|
}
|
||||||
+9
-1
@@ -2,6 +2,7 @@
|
|||||||
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -15,6 +16,10 @@ public static class AddMediaLibraryRequestMapping
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
|
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// A path template part that is <see langword="null"/> is converted to a part without a kind, and a provider or book reader choice that is <see langword="null"/> is
|
||||||
|
/// converted to a choice without a plugin Id, so that the validation of the command reports them, instead of the conversion failing before the command is validated.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="request">The request to be converted.</param>
|
/// <param name="request">The request to be converted.</param>
|
||||||
/// <returns>The converted command.</returns>
|
/// <returns>The converted command.</returns>
|
||||||
public static AddLibraryCommand ToCommand(this AddLibraryRequest request)
|
public static AddLibraryCommand ToCommand(this AddLibraryRequest request)
|
||||||
@@ -32,7 +37,10 @@ public static class AddMediaLibraryRequestMapping
|
|||||||
request.IsContentOnSsd,
|
request.IsContentOnSsd,
|
||||||
request.ShouldTrackConsumptionProgress,
|
request.ShouldTrackConsumptionProgress,
|
||||||
request.CompletionThresholdPercentage,
|
request.CompletionThresholdPercentage,
|
||||||
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
|
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part?.Kind, part?.Representation, part?.IsOptional ?? false)).ToArray(),
|
||||||
|
request.MetadataProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||||
|
request.ArtworkProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||||
|
request.BookReaders?.Select(reader => new LibraryProviderSelectionDto(reader?.PluginId ?? Guid.Empty, reader?.IsEnabled)).ToArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+9
-2
@@ -2,6 +2,7 @@
|
|||||||
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
||||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -15,13 +16,16 @@ public static class UpdateLibraryRequestMapping
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts <paramref name="request"/> to <see cref="UpdateLibraryCommand"/>.
|
/// Converts <paramref name="request"/> to <see cref="UpdateLibraryCommand"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// A path template part that is <see langword="null"/> is converted to a part without a kind, and a provider or book reader choice that is <see langword="null"/> is
|
||||||
|
/// converted to a choice without a plugin Id, so that the validation of the command reports them, instead of the conversion failing before the command is validated.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="request">The request to be converted.</param>
|
/// <param name="request">The request to be converted.</param>
|
||||||
/// <returns>The converted command.</returns>
|
/// <returns>The converted command.</returns>
|
||||||
public static UpdateLibraryCommand ToCommand(this UpdateLibraryRequest request)
|
public static UpdateLibraryCommand ToCommand(this UpdateLibraryRequest request)
|
||||||
{
|
{
|
||||||
return new UpdateLibraryCommand(
|
return new UpdateLibraryCommand(
|
||||||
request.Id,
|
request.Id,
|
||||||
request.UserId,
|
|
||||||
request.Title,
|
request.Title,
|
||||||
request.LibraryType,
|
request.LibraryType,
|
||||||
request.ContentLocations,
|
request.ContentLocations,
|
||||||
@@ -34,7 +38,10 @@ public static class UpdateLibraryRequestMapping
|
|||||||
request.IsContentOnSsd,
|
request.IsContentOnSsd,
|
||||||
request.ShouldTrackConsumptionProgress,
|
request.ShouldTrackConsumptionProgress,
|
||||||
request.CompletionThresholdPercentage,
|
request.CompletionThresholdPercentage,
|
||||||
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
|
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part?.Kind, part?.Representation, part?.IsOptional ?? false)).ToArray(),
|
||||||
|
request.MetadataProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||||
|
request.ArtworkProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
|
||||||
|
request.BookReaders?.Select(reader => new LibraryProviderSelectionDto(reader?.PluginId ?? Guid.Empty, reader?.IsEnabled)).ToArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for converting <see cref="GetLibraryTypeArtworkProvidersRequest"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class GetLibraryTypeArtworkProvidersRequestMapping
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeArtworkProvidersQuery"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The request to be converted.</param>
|
||||||
|
/// <returns>The converted query.</returns>
|
||||||
|
public static GetLibraryTypeArtworkProvidersQuery ToQuery(this GetLibraryTypeArtworkProvidersRequest request)
|
||||||
|
{
|
||||||
|
return new GetLibraryTypeArtworkProvidersQuery(
|
||||||
|
request.LibraryType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for converting <see cref="GetLibraryTypeBookReadersRequest"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class GetLibraryTypeBookReadersRequestMapping
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeBookReadersQuery"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The request to be converted.</param>
|
||||||
|
/// <returns>The converted query.</returns>
|
||||||
|
public static GetLibraryTypeBookReadersQuery ToQuery(this GetLibraryTypeBookReadersRequest request)
|
||||||
|
{
|
||||||
|
return new GetLibraryTypeBookReadersQuery(
|
||||||
|
request.LibraryType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Common.Mapping.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for converting <see cref="GetLibraryTypeMetadataProvidersRequest"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class GetLibraryTypeMetadataProvidersRequestMapping
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeMetadataProvidersQuery"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The request to be converted.</param>
|
||||||
|
/// <returns>The converted query.</returns>
|
||||||
|
public static GetLibraryTypeMetadataProvidersQuery ToQuery(this GetLibraryTypeMetadataProvidersRequest request)
|
||||||
|
{
|
||||||
|
return new GetLibraryTypeMetadataProvidersQuery(
|
||||||
|
request.LibraryType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for converting <see cref="ReorderLibraryArtworkProvidersRequest"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static class ReorderLibraryArtworkProvidersRequestMapping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Converts <paramref name="request"/> to <see cref="ReorderLibraryArtworkProvidersCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request to be converted.</param>
|
|
||||||
/// <returns>The converted command.</returns>
|
|
||||||
public static ReorderLibraryArtworkProvidersCommand ToCommand(this ReorderLibraryArtworkProvidersRequest request)
|
|
||||||
{
|
|
||||||
return new ReorderLibraryArtworkProvidersCommand(
|
|
||||||
LibraryId: request.LibraryId,
|
|
||||||
PluginIds: request.PluginIds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-22
@@ -1,22 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for converting <see cref="ReorderLibraryMetadataProvidersRequest"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static class ReorderLibraryMetadataProvidersRequestMapping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Converts <paramref name="request"/> to <see cref="ReorderLibraryMetadataProvidersCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request to be converted.</param>
|
|
||||||
/// <returns>The converted command.</returns>
|
|
||||||
public static ReorderLibraryMetadataProvidersCommand ToCommand(this ReorderLibraryMetadataProvidersRequest request)
|
|
||||||
{
|
|
||||||
return new ReorderLibraryMetadataProvidersCommand(request.LibraryId, request.PluginIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for converting <see cref="SetLibraryArtworkProviderEnabledRequest"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static class SetLibraryArtworkProviderEnabledRequestMapping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Converts <paramref name="request"/> to <see cref="SetLibraryArtworkProviderEnabledCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request to be converted.</param>
|
|
||||||
/// <returns>The converted command.</returns>
|
|
||||||
public static SetLibraryArtworkProviderEnabledCommand ToCommand(this SetLibraryArtworkProviderEnabledRequest request)
|
|
||||||
{
|
|
||||||
return new SetLibraryArtworkProviderEnabledCommand(
|
|
||||||
LibraryId: request.LibraryId,
|
|
||||||
PluginId: request.PluginId,
|
|
||||||
IsEnabled: request.IsEnabled
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for converting <see cref="SetLibraryBookReaderEnabledRequest"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static class SetLibraryBookReaderEnabledRequestMapping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Converts <paramref name="request"/> to <see cref="SetLibraryBookReaderEnabledCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request to be converted.</param>
|
|
||||||
/// <returns>The converted command.</returns>
|
|
||||||
public static SetLibraryBookReaderEnabledCommand ToCommand(this SetLibraryBookReaderEnabledRequest request)
|
|
||||||
{
|
|
||||||
return new SetLibraryBookReaderEnabledCommand(
|
|
||||||
request.LibraryId,
|
|
||||||
request.PluginId,
|
|
||||||
request.IsEnabled
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-22
@@ -1,22 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for converting <see cref="SetLibraryMetadataProviderEnabledRequest"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static class SetLibraryMetadataProviderEnabledRequestMapping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Converts <paramref name="request"/> to <see cref="SetLibraryMetadataProviderEnabledCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request to be converted.</param>
|
|
||||||
/// <returns>The converted command.</returns>
|
|
||||||
public static SetLibraryMetadataProviderEnabledCommand ToCommand(this SetLibraryMetadataProviderEnabledRequest request)
|
|
||||||
{
|
|
||||||
return new SetLibraryMetadataProviderEnabledCommand(request.LibraryId, request.PluginId, request.IsEnabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+6
-4
@@ -4,7 +4,6 @@ using Lumina.Application.Common.Utilities;
|
|||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Favorites.Commands.RemoveFavorite;
|
namespace Lumina.Application.Core.Favorites.Commands.RemoveFavorite;
|
||||||
@@ -26,9 +25,12 @@ public class RemoveFavoriteCommandValidator : AbstractValidator<RemoveFavoriteCo
|
|||||||
// Only the member names other than the default None are accepted, so a numeric route value that happens to parse as an
|
// Only the member names other than the default None are accepted, so a numeric route value that happens to parse as an
|
||||||
// enumeration value, or the explicit default value, is rejected.
|
// enumeration value, or the explicit default value, is rejected.
|
||||||
RuleFor(command => command.MediaKind)
|
RuleFor(command => command.MediaKind)
|
||||||
.Must(mediaKind => Enum.GetNames<FavoriteMediaKind>()
|
.IsInEnum<RemoveFavoriteCommand, FavoriteMediaKind>()
|
||||||
.Where(mediaKindName => !string.Equals(mediaKindName, nameof(FavoriteMediaKind.None), StringComparison.Ordinal))
|
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
||||||
.Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
|
.WithError(Errors.Favorites.FavoriteMediaKindIsInvalid);
|
||||||
|
|
||||||
|
RuleFor(command => command.MediaKind)
|
||||||
|
.Must(mediaKind => !string.Equals(mediaKind, nameof(FavoriteMediaKind.None), StringComparison.OrdinalIgnoreCase))
|
||||||
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
||||||
.WithError(Errors.Favorites.FavoriteMediaKindIsInvalid);
|
.WithError(Errors.Favorites.FavoriteMediaKindIsInvalid);
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -4,7 +4,6 @@ using Lumina.Application.Common.Utilities;
|
|||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Lumina.Application.Core.MediaConsumption.Commands.StartConsumption;
|
namespace Lumina.Application.Core.MediaConsumption.Commands.StartConsumption;
|
||||||
@@ -35,7 +34,7 @@ public class StartConsumptionCommandValidator : AbstractValidator<StartConsumpti
|
|||||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||||
|
|
||||||
RuleFor(command => command.MediaKind)
|
RuleFor(command => command.MediaKind)
|
||||||
.Must(mediaKind => Enum.GetNames<MediaKind>().Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
|
.IsInEnum<StartConsumptionCommand, MediaKind>()
|
||||||
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
.When(command => command.MediaKind is not null && command.MediaKind.Length > 0)
|
||||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -4,7 +4,6 @@ using Lumina.Application.Common.Utilities;
|
|||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetResumePoint;
|
namespace Lumina.Application.Core.MediaConsumption.Queries.GetResumePoint;
|
||||||
@@ -25,7 +24,7 @@ public class GetResumePointQueryValidator : AbstractValidator<GetResumePointQuer
|
|||||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||||
|
|
||||||
RuleFor(query => query.MediaKind)
|
RuleFor(query => query.MediaKind)
|
||||||
.Must(mediaKind => Enum.GetNames<MediaKind>().Contains(mediaKind, StringComparer.OrdinalIgnoreCase))
|
.IsInEnum<GetResumePointQuery, MediaKind>()
|
||||||
.When(query => query.MediaKind is not null && query.MediaKind.Length > 0)
|
.When(query => query.MediaKind is not null && query.MediaKind.Length > 0)
|
||||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -22,6 +22,9 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
|||||||
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. When absent, the default of the library type is used.</param>
|
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. When absent, the default of the library type is used.</param>
|
||||||
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. When absent, the default of the library type is used on creation.</param>
|
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. When absent, the default of the library type is used on creation.</param>
|
||||||
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk.</param>
|
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk.</param>
|
||||||
|
/// <param name="MetadataProviders">The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, every provider supported by the library type is added disabled.</param>
|
||||||
|
/// <param name="ArtworkProviders">The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, every provider supported by the library type is added disabled.</param>
|
||||||
|
/// <param name="BookReaders">The book readers of the media library, and whether each one is enabled. When absent, every reader supported by the library type is added disabled.</param>
|
||||||
[DebuggerDisplay("Title: {Title}")]
|
[DebuggerDisplay("Title: {Title}")]
|
||||||
public record AddLibraryCommand(
|
public record AddLibraryCommand(
|
||||||
string? Title,
|
string? Title,
|
||||||
@@ -36,5 +39,8 @@ public record AddLibraryCommand(
|
|||||||
bool IsContentOnSsd,
|
bool IsContentOnSsd,
|
||||||
bool? ShouldTrackConsumptionProgress,
|
bool? ShouldTrackConsumptionProgress,
|
||||||
int? CompletionThresholdPercentage,
|
int? CompletionThresholdPercentage,
|
||||||
LibraryPathTemplatePartDto[]? PathTemplateParts
|
LibraryPathTemplatePartDto[]? PathTemplateParts,
|
||||||
|
LibraryProviderSelectionDto[]? MetadataProviders,
|
||||||
|
LibraryProviderSelectionDto[]? ArtworkProviders,
|
||||||
|
LibraryProviderSelectionDto[]? BookReaders
|
||||||
) : ICommand;
|
) : ICommand;
|
||||||
+7
-7
@@ -114,7 +114,7 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
|
|||||||
return DomainErrors.Library.CoverFileMustBeAnImage;
|
return DomainErrors.Library.CoverFileMustBeAnImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryType libraryType = Enum.Parse<LibraryType>(command.LibraryType!);
|
LibraryType libraryType = Enum.Parse<LibraryType>(command.LibraryType!, ignoreCase: true);
|
||||||
|
|
||||||
// A library created without explicit consumption settings uses the defaults of its type. When progress tracking is on and no threshold is
|
// A library created without explicit consumption settings uses the defaults of its type. When progress tracking is on and no threshold is
|
||||||
// supplied, the default threshold of the type is used; a type without one keeps no threshold, which means completion is recorded explicitly.
|
// supplied, the default threshold of the type is used; a type without one keeps no threshold, which means completion is recorded explicitly.
|
||||||
@@ -158,15 +158,15 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
|
|||||||
|
|
||||||
// Convert the domain library entity to a repository library entity.
|
// Convert the domain library entity to a repository library entity.
|
||||||
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
|
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
|
||||||
// Insert the repository entity, seed the provider configurations of the new library so that it lists the plugins
|
// Insert the repository entity, seed the provider configurations of the new library so that it lists the plugins providing metadata,
|
||||||
// providing metadata or artwork for its type, and save the changes.
|
// artwork or book readers for its type, with the choices made for them, and save the changes.
|
||||||
Result<Created> insertLibraryResult = await _unitOfWork.LibraryRepository.InsertAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
|
Result<Created> insertLibraryResult = await _unitOfWork.LibraryRepository.InsertAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
|
||||||
if (insertLibraryResult.IsFailure)
|
if (insertLibraryResult.IsFailure)
|
||||||
return insertLibraryResult.Errors;
|
return insertLibraryResult.Errors;
|
||||||
Result<Success> ensureProviderConfigurationsResult = await _providerConfigurationStore.EnsureProviderConfigurationsAsync(
|
Result<Success> configureProvidersResult = await _providerConfigurationStore.ConfigureProvidersAsync(
|
||||||
createLibraryResult.Value.Id.Value, libraryType, cancellationToken).ConfigureAwait(false);
|
createLibraryResult.Value.Id.Value, libraryType, command.MetadataProviders, command.ArtworkProviders, command.BookReaders, shouldReconcileOmittedKinds: true, cancellationToken).ConfigureAwait(false);
|
||||||
if (ensureProviderConfigurationsResult.IsFailure)
|
if (configureProvidersResult.IsFailure)
|
||||||
return ensureProviderConfigurationsResult.Errors;
|
return configureProvidersResult.Errors;
|
||||||
|
|
||||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||||
if (saveChangesResult.IsFailure)
|
if (saveChangesResult.IsFailure)
|
||||||
|
|||||||
+29
-1
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
|||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||||
@@ -21,7 +22,7 @@ public class AddLibraryCommandValidator : AbstractValidator<AddLibraryCommand>
|
|||||||
RuleFor(command => command.LibraryType)
|
RuleFor(command => command.LibraryType)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||||
.Must(libraryType => Enum.TryParse<LibraryType>(libraryType, out _))
|
.IsInEnum<AddLibraryCommand, LibraryType>()
|
||||||
.WithError(Errors.Library.UnknownLibraryType);
|
.WithError(Errors.Library.UnknownLibraryType);
|
||||||
|
|
||||||
RuleFor(command => command.ContentLocations)
|
RuleFor(command => command.ContentLocations)
|
||||||
@@ -61,5 +62,32 @@ public class AddLibraryCommandValidator : AbstractValidator<AddLibraryCommand>
|
|||||||
.When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase))
|
.When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase))
|
||||||
.WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty);
|
.WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RuleForEach(command => command.MetadataProviders)
|
||||||
|
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||||
|
|
||||||
|
RuleFor(command => command.MetadataProviders)
|
||||||
|
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||||
|
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||||
|
|
||||||
|
RuleForEach(command => command.ArtworkProviders)
|
||||||
|
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||||
|
|
||||||
|
RuleFor(command => command.ArtworkProviders)
|
||||||
|
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||||
|
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||||
|
|
||||||
|
RuleForEach(command => command.BookReaders)
|
||||||
|
.ChildRules(reader => reader.RuleFor(selection => selection.PluginId)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||||
|
|
||||||
|
RuleFor(command => command.BookReaders)
|
||||||
|
.Must(readers => readers is null || readers.Select(selection => selection.PluginId).Distinct().Count() == readers.Length)
|
||||||
|
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-4
@@ -13,6 +13,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
|
|||||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||||
using Lumina.Domain.Common.Events;
|
using Lumina.Domain.Common.Events;
|
||||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -85,10 +86,12 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
|
|||||||
else if (getLibraryResult.Value is null)
|
else if (getLibraryResult.Value is null)
|
||||||
return DomainErrors.Library.LibraryNotFound;
|
return DomainErrors.Library.LibraryNotFound;
|
||||||
|
|
||||||
// Admins can delete any library; for everyone else, only the libraries they own.
|
// Admins can delete any library. Everyone else can only delete the libraries they own, and only while they hold the permission to manage media
|
||||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
// libraries, which can be withheld to keep a user from deleting even the libraries they own.
|
||||||
userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false);
|
if (!await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false))
|
||||||
if (!canAccessLibrary)
|
return ApplicationErrors.Authorization.NotAuthorized;
|
||||||
|
if (!await _authorizationService.IsInRoleAsync(userId, AuthorizationRoles.ADMIN, cancellationToken).ConfigureAwait(false) &&
|
||||||
|
!await _authorizationService.HasPermissionAsync(userId, AuthorizationPermission.CanCreateLibraries, cancellationToken).ConfigureAwait(false))
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
return ApplicationErrors.Authorization.NotAuthorized;
|
||||||
|
|
||||||
// Create a domain library object.
|
// Create a domain library object.
|
||||||
|
|||||||
+7
-3
@@ -11,7 +11,6 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
|
|||||||
/// Command for updating a media library.
|
/// Command for updating a media library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Id">The unique identifier of the media library.</param>
|
/// <param name="Id">The unique identifier of the media library.</param>
|
||||||
/// <param name="OwnerId">The unique identifier of the user owning the media library.</param>
|
|
||||||
/// <param name="Title">The title of the media library.</param>
|
/// <param name="Title">The title of the media library.</param>
|
||||||
/// <param name="LibraryType">The type of the media library.</param>
|
/// <param name="LibraryType">The type of the media library.</param>
|
||||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located.</param>
|
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located.</param>
|
||||||
@@ -25,10 +24,12 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
|
|||||||
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. When absent, the stored value is kept.</param>
|
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. When absent, the stored value is kept.</param>
|
||||||
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. When absent, the stored value is kept.</param>
|
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. When absent, the stored value is kept.</param>
|
||||||
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk.</param>
|
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk.</param>
|
||||||
|
/// <param name="MetadataProviders">The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||||
|
/// <param name="ArtworkProviders">The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||||
|
/// <param name="BookReaders">The book readers of the media library, and whether each one is enabled. When absent, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||||
[DebuggerDisplay("Title: {Title}")]
|
[DebuggerDisplay("Title: {Title}")]
|
||||||
public record UpdateLibraryCommand(
|
public record UpdateLibraryCommand(
|
||||||
Guid Id,
|
Guid Id,
|
||||||
Guid OwnerId,
|
|
||||||
string? Title,
|
string? Title,
|
||||||
string? LibraryType,
|
string? LibraryType,
|
||||||
string[]? ContentLocations,
|
string[]? ContentLocations,
|
||||||
@@ -41,5 +42,8 @@ public record UpdateLibraryCommand(
|
|||||||
bool IsContentOnSsd,
|
bool IsContentOnSsd,
|
||||||
bool? ShouldTrackConsumptionProgress,
|
bool? ShouldTrackConsumptionProgress,
|
||||||
int? CompletionThresholdPercentage,
|
int? CompletionThresholdPercentage,
|
||||||
LibraryPathTemplatePartDto[]? PathTemplateParts
|
LibraryPathTemplatePartDto[]? PathTemplateParts,
|
||||||
|
LibraryProviderSelectionDto[]? MetadataProviders,
|
||||||
|
LibraryProviderSelectionDto[]? ArtworkProviders,
|
||||||
|
LibraryProviderSelectionDto[]? BookReaders
|
||||||
) : ICommand;
|
) : ICommand;
|
||||||
+22
-15
@@ -105,6 +105,16 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
|||||||
else if (getLibraryResult.Value is null)
|
else if (getLibraryResult.Value is null)
|
||||||
return DomainErrors.Library.LibraryNotFound;
|
return DomainErrors.Library.LibraryNotFound;
|
||||||
|
|
||||||
|
// Admins can update any library. Everyone else can only update the libraries they own, and only while they hold the permission to manage media
|
||||||
|
// libraries, which can be withheld to keep a user from changing even the libraries they own. Authorization comes before the cover image is
|
||||||
|
// read, so a user who may not update the library can never make the server open a path on their behalf.
|
||||||
|
if (!await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false))
|
||||||
|
return ApplicationErrors.Authorization.NotAuthorized;
|
||||||
|
if (!await _authorizationService.IsInRoleAsync(userId, AuthorizationRoles.ADMIN, cancellationToken).ConfigureAwait(false) &&
|
||||||
|
!await _authorizationService.HasPermissionAsync(userId, AuthorizationPermission.CanCreateLibraries, cancellationToken).ConfigureAwait(false))
|
||||||
|
return ApplicationErrors.Authorization.NotAuthorized;
|
||||||
|
bool hasProviderChoices = command.MetadataProviders is not null || command.ArtworkProviders is not null || command.BookReaders is not null;
|
||||||
|
|
||||||
// Make sure the file is an actual supported image, but only when a new cover image was chosen; the stored cover image is
|
// Make sure the file is an actual supported image, but only when a new cover image was chosen; the stored cover image is
|
||||||
// relative to the application base directory and is already validated, so it must not block saving unrelated changes.
|
// relative to the application base directory and is already validated, so it must not block saving unrelated changes.
|
||||||
if (command.CoverImage is not null && command.CoverImage != getLibraryResult.Value.CoverImage)
|
if (command.CoverImage is not null && command.CoverImage != getLibraryResult.Value.CoverImage)
|
||||||
@@ -120,15 +130,8 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
|||||||
return DomainErrors.Library.CoverFileMustBeAnImage;
|
return DomainErrors.Library.CoverFileMustBeAnImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Admins or users with the permission to manage media libraries can update any library; other users can only update the libraries they own.
|
|
||||||
bool hasManagePermission = await _authorizationService.HasPermissionAsync(userId, AuthorizationPermission.CanCreateLibraries, cancellationToken).ConfigureAwait(false);
|
|
||||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
|
||||||
userId, new LibraryOwnershipPolicyContext(command.Id), cancellationToken).ConfigureAwait(false);
|
|
||||||
if (!hasManagePermission && !canAccessLibrary)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
|
|
||||||
// Create a domain library object.
|
// Create a domain library object.
|
||||||
LibraryType newLibraryType = Enum.Parse<LibraryType>(command.LibraryType!);
|
LibraryType newLibraryType = Enum.Parse<LibraryType>(command.LibraryType!, ignoreCase: true);
|
||||||
|
|
||||||
// Keep the stored consumption settings unless the request explicitly changes them. When progress tracking is enabled and
|
// Keep the stored consumption settings unless the request explicitly changes them. When progress tracking is enabled and
|
||||||
// no threshold is supplied, the stored threshold is kept; the value object never retains a threshold while tracking is disabled.
|
// no threshold is supplied, the stored threshold is kept; the value object never retains a threshold while tracking is disabled.
|
||||||
@@ -157,9 +160,10 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
|||||||
if (pathTemplateResult.IsFailure)
|
if (pathTemplateResult.IsFailure)
|
||||||
return pathTemplateResult.Errors;
|
return pathTemplateResult.Errors;
|
||||||
|
|
||||||
|
// The owner of a library is the user who created it, and an update never changes it.
|
||||||
Result<Library> createLibraryResult = Library.Create(
|
Result<Library> createLibraryResult = Library.Create(
|
||||||
LibraryId.Create(command.Id),
|
LibraryId.Create(command.Id),
|
||||||
UserId.Create(command.OwnerId),
|
UserId.Create(getLibraryResult.Value.UserId),
|
||||||
command.Title!,
|
command.Title!,
|
||||||
newLibraryType,
|
newLibraryType,
|
||||||
command.ContentLocations!,
|
command.ContentLocations!,
|
||||||
@@ -179,16 +183,19 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
|
|||||||
// Convert the domain library entity to a repository library entity.
|
// Convert the domain library entity to a repository library entity.
|
||||||
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
|
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
|
||||||
|
|
||||||
// Update the repository entity, and when the library type changed, reconcile the provider configurations so that
|
// Update the repository entity, apply the choices made for the providers, and when the library type changed, also reconcile the kinds of
|
||||||
// they match the plugins supporting the new type, and save the changes.
|
// configuration that were not chosen, so they match the plugins supporting the new type; then save the changes. When the type is unchanged,
|
||||||
|
// a kind of configuration that was not chosen is left untouched.
|
||||||
Result<Updated> updateLibraryResult = await _unitOfWork.LibraryRepository.UpdateAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
|
Result<Updated> updateLibraryResult = await _unitOfWork.LibraryRepository.UpdateAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
|
||||||
if (updateLibraryResult.IsFailure)
|
if (updateLibraryResult.IsFailure)
|
||||||
return updateLibraryResult.Errors;
|
return updateLibraryResult.Errors;
|
||||||
if (getLibraryResult.Value.LibraryType != newLibraryType)
|
bool isLibraryTypeChanged = getLibraryResult.Value.LibraryType != newLibraryType;
|
||||||
|
if (isLibraryTypeChanged || hasProviderChoices)
|
||||||
{
|
{
|
||||||
Result<Success> reconcileResult = await _providerConfigurationStore.ReconcileProviderConfigurationsAsync(command.Id, newLibraryType, cancellationToken).ConfigureAwait(false);
|
Result<Success> configureProvidersResult = await _providerConfigurationStore.ConfigureProvidersAsync(
|
||||||
if (reconcileResult.IsFailure)
|
command.Id, newLibraryType, command.MetadataProviders, command.ArtworkProviders, command.BookReaders, isLibraryTypeChanged, cancellationToken).ConfigureAwait(false);
|
||||||
return reconcileResult.Errors;
|
if (configureProvidersResult.IsFailure)
|
||||||
|
return configureProvidersResult.Errors;
|
||||||
}
|
}
|
||||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||||
if (saveChangesResult.IsFailure)
|
if (saveChangesResult.IsFailure)
|
||||||
|
|||||||
+29
-7
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
|||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
||||||
@@ -24,16 +25,10 @@ public class UpdateLibraryCommandValidator : AbstractValidator<UpdateLibraryComm
|
|||||||
.Must(id => id != Guid.Empty)
|
.Must(id => id != Guid.Empty)
|
||||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||||
|
|
||||||
RuleFor(command => command.OwnerId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Users.UserIdCannotBeEmpty)
|
|
||||||
.Must(id => id != Guid.Empty)
|
|
||||||
.WithError(Errors.Users.UserIdCannotBeEmpty);
|
|
||||||
|
|
||||||
RuleFor(command => command.LibraryType)
|
RuleFor(command => command.LibraryType)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||||
.Must(libraryType => Enum.TryParse<LibraryType>(libraryType, out _))
|
.IsInEnum<UpdateLibraryCommand, LibraryType>()
|
||||||
.WithError(Errors.Library.UnknownLibraryType);
|
.WithError(Errors.Library.UnknownLibraryType);
|
||||||
|
|
||||||
RuleFor(command => command.ContentLocations)
|
RuleFor(command => command.ContentLocations)
|
||||||
@@ -73,5 +68,32 @@ public class UpdateLibraryCommandValidator : AbstractValidator<UpdateLibraryComm
|
|||||||
.When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase))
|
.When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase))
|
||||||
.WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty);
|
.WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RuleForEach(command => command.MetadataProviders)
|
||||||
|
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||||
|
|
||||||
|
RuleFor(command => command.MetadataProviders)
|
||||||
|
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||||
|
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||||
|
|
||||||
|
RuleForEach(command => command.ArtworkProviders)
|
||||||
|
.ChildRules(provider => provider.RuleFor(selection => selection.PluginId)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||||
|
|
||||||
|
RuleFor(command => command.ArtworkProviders)
|
||||||
|
.Must(providers => providers is null || providers.Select(selection => selection.PluginId).Distinct().Count() == providers.Length)
|
||||||
|
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||||
|
|
||||||
|
RuleForEach(command => command.BookReaders)
|
||||||
|
.ChildRules(reader => reader.RuleFor(selection => selection.PluginId)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithError(Errors.Plugins.PluginIdCannotBeEmpty));
|
||||||
|
|
||||||
|
RuleFor(command => command.BookReaders)
|
||||||
|
.Must(readers => readers is null || readers.Select(selection => selection.PluginId).Distinct().Count() == readers.Length)
|
||||||
|
.WithError(Errors.Plugins.PluginIdsMustBeUnique);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-6
@@ -41,19 +41,19 @@ public class GetLibraryPathTemplatePartsQueryHandler : IQueryHandler<GetLibraryP
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public Task<Result<LibraryPathTemplateCatalogResponse>> HandleAsync(GetLibraryPathTemplatePartsQuery query, CancellationToken cancellationToken)
|
public Task<Result<LibraryPathTemplateCatalogResponse>> HandleAsync(GetLibraryPathTemplatePartsQuery query, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// the library type travels as a string taken from the route, and is matched against the enum the same way the create and update
|
// The library type travels as a string taken from the route, and is matched against the enum the same way the create and update
|
||||||
// library commands do, so that a malformed type is reported as an unknown library type instead of silently returning an empty catalog.
|
// library commands do, so that a malformed type is reported as an unknown library type instead of silently returning an empty catalog.
|
||||||
if (!Enum.TryParse(query.LibraryType, ignoreCase: true, out LibraryType libraryType))
|
if (!Enum.TryParse(query.LibraryType, ignoreCase: true, out LibraryType libraryType) || !Enum.IsDefined(libraryType))
|
||||||
return Task.FromResult<Result<LibraryPathTemplateCatalogResponse>>(DomainErrors.Library.UnknownLibraryType);
|
return Task.FromResult<Result<LibraryPathTemplateCatalogResponse>>(DomainErrors.Library.UnknownLibraryType);
|
||||||
|
|
||||||
// only the catalog registered for the requested library type applies, so the parts and the default structure offered to the user are
|
// Only the catalog registered for the requested library type applies, so the parts and the default structure offered to the user are
|
||||||
// type aware (music libraries get artist and release parts, book libraries get author and title parts, and so on).
|
// type aware (music libraries get artist and release parts, book libraries get author and title parts, and so on).
|
||||||
ILibraryPathPartCatalog? catalog = _catalogs.FirstOrDefault(candidate => candidate.SupportedLibraryType == libraryType);
|
ILibraryPathPartCatalog? catalog = _catalogs.FirstOrDefault(candidate => candidate.SupportedLibraryType == libraryType);
|
||||||
if (catalog is null)
|
if (catalog is null)
|
||||||
// a library type without a catalog has no structure to describe, so an empty catalog is returned, which the client uses to hide the editor.
|
// A library type without a catalog has no structure to describe, so an empty catalog is returned, which the client uses to hide the editor.
|
||||||
return Task.FromResult(Result<LibraryPathTemplateCatalogResponse>.Success(new LibraryPathTemplateCatalogResponse([], [])));
|
return Task.FromResult(Result<LibraryPathTemplateCatalogResponse>.Success(new LibraryPathTemplateCatalogResponse([], [])));
|
||||||
|
|
||||||
// the selectable parts describe what the user can drop into the template, together with the value type and the default on-disk representation of each part.
|
// The selectable parts describe what the user can drop into the template, together with the value type and the default on-disk representation of each part.
|
||||||
List<LibraryPathPartDefinitionResponse> parts =
|
List<LibraryPathPartDefinitionResponse> parts =
|
||||||
[
|
[
|
||||||
.. catalog.GetPartDefinitions().Select(definition => new LibraryPathPartDefinitionResponse(
|
.. catalog.GetPartDefinitions().Select(definition => new LibraryPathPartDefinitionResponse(
|
||||||
@@ -62,7 +62,7 @@ public class GetLibraryPathTemplatePartsQueryHandler : IQueryHandler<GetLibraryP
|
|||||||
definition.DefaultRepresentation,
|
definition.DefaultRepresentation,
|
||||||
definition.IsOptionalByDefault))
|
definition.IsOptionalByDefault))
|
||||||
];
|
];
|
||||||
// the default template parts describe the ideal structure the application expects, pre-filled in the editor so the user only edits what deviates.
|
// The default template parts describe the ideal structure the application expects, pre-filled in the editor so the user only edits what deviates.
|
||||||
List<LibraryPathTemplatePartResponse> defaultTemplateParts =
|
List<LibraryPathTemplatePartResponse> defaultTemplateParts =
|
||||||
[
|
[
|
||||||
.. catalog.GetDefaultTemplate().Parts.Select(part => new LibraryPathTemplatePartResponse(part.Kind.ToString(), part.Representation, part.IsOptional))
|
.. catalog.GetDefaultTemplate().Parts.Select(part => new LibraryPathTemplatePartResponse(part.Kind.ToString(), part.Representation, part.IsOptional))
|
||||||
|
|||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command for reordering the artwork providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose artwork providers are reordered.</param>
|
|
||||||
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank.</param>
|
|
||||||
public record ReorderLibraryArtworkProvidersCommand(
|
|
||||||
Guid LibraryId,
|
|
||||||
IReadOnlyList<Guid> PluginIds
|
|
||||||
) : ICommand;
|
|
||||||
-98
@@ -1,98 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
|
||||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
|
||||||
using Lumina.Application.Common.DataAccess.UoW;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handler for the command to reorder the artwork providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
public class ReorderLibraryArtworkProvidersCommandHandler : ICommandHandler<ReorderLibraryArtworkProvidersCommand, Result<Success>>
|
|
||||||
{
|
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
|
||||||
private readonly IAuthorizationService _authorizationService;
|
|
||||||
private readonly ICurrentUserService _currentUserService;
|
|
||||||
private readonly IValidator<ReorderLibraryArtworkProvidersCommand> _validator;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersCommandHandler"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
|
||||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
|
||||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
|
||||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
|
||||||
public ReorderLibraryArtworkProvidersCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<ReorderLibraryArtworkProvidersCommand> validator)
|
|
||||||
{
|
|
||||||
_authorizationService = authorizationService;
|
|
||||||
_currentUserService = currentUserService;
|
|
||||||
_unitOfWork = unitOfWork;
|
|
||||||
_validator = validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the command to reorder the artwork providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command">The request to be handled.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
|
||||||
/// </returns>
|
|
||||||
public async Task<Result<Success>> HandleAsync(ReorderLibraryArtworkProvidersCommand command, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
List<Error> validationResult = _validator.Validate(command);
|
|
||||||
if (validationResult.Count > 0)
|
|
||||||
return validationResult;
|
|
||||||
|
|
||||||
// An authenticated request must always carry a user identity.
|
|
||||||
Guid? currentUserId = _currentUserService.UserId;
|
|
||||||
if (currentUserId is null)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
Guid userId = currentUserId.Value;
|
|
||||||
|
|
||||||
// Admins can reorder the artwork providers of any library; for everyone else, only their own libraries.
|
|
||||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
|
||||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
|
||||||
if (!canAccessLibrary)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
|
|
||||||
// Load the artwork provider configurations that are currently registered for the library, so that only providers it actually has are reordered.
|
|
||||||
Result<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.ArtworkProviderConfigurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (getConfigurationsResult.IsFailure)
|
|
||||||
return getConfigurationsResult.Errors;
|
|
||||||
|
|
||||||
// Index the configurations by plugin id, so that each requested plugin can be matched without repeatedly searching the list.
|
|
||||||
Dictionary<Guid, LibraryArtworkProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value.ToDictionary(configuration => configuration.PluginId);
|
|
||||||
// Walk the requested order and assign each provider the 1-based rank that matches its position in the command, so the persisted order follows the user's choice.
|
|
||||||
for (int rank = 0; rank < command.PluginIds.Count; rank++)
|
|
||||||
{
|
|
||||||
Guid pluginId = command.PluginIds[rank];
|
|
||||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryArtworkProviderConfigurationEntity? configuration))
|
|
||||||
{
|
|
||||||
configuration.Rank = rank + 1;
|
|
||||||
Result<Updated> upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (upsertResult.IsFailure)
|
|
||||||
return upsertResult.Errors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Persist all the rank changes in a single save, so that the reorder is applied atomically.
|
|
||||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
if (saveChangesResult.IsFailure)
|
|
||||||
return saveChangesResult.Errors;
|
|
||||||
return Result.Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Application.Common.Utilities;
|
|
||||||
using Lumina.Domain.Common.Errors;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates the needed validation rules for <see cref="ReorderLibraryArtworkProvidersCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
public class ReorderLibraryArtworkProvidersCommandValidator : AbstractValidator<ReorderLibraryArtworkProvidersCommand>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersCommandValidator"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public ReorderLibraryArtworkProvidersCommandValidator()
|
|
||||||
{
|
|
||||||
RuleFor(command => command.LibraryId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
|
||||||
.Must(id => id != Guid.Empty)
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
|
||||||
|
|
||||||
RuleFor(command => command.PluginIds)
|
|
||||||
.NotNull()
|
|
||||||
.WithError(Errors.Plugins.PluginIdsListCannotBeNull)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.PluginIdsListCannotBeEmpty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command for reordering the metadata providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose metadata providers are reordered.</param>
|
|
||||||
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank.</param>
|
|
||||||
public record ReorderLibraryMetadataProvidersCommand(
|
|
||||||
Guid LibraryId,
|
|
||||||
IReadOnlyList<Guid> PluginIds
|
|
||||||
) : ICommand;
|
|
||||||
-97
@@ -1,97 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
|
||||||
using Lumina.Application.Common.DataAccess.UoW;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handler for the command to reorder the metadata providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<ReorderLibraryMetadataProvidersCommand, Result<Success>>
|
|
||||||
{
|
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
|
||||||
private readonly IAuthorizationService _authorizationService;
|
|
||||||
private readonly ICurrentUserService _currentUserService;
|
|
||||||
private readonly IValidator<ReorderLibraryMetadataProvidersCommand> _validator;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersCommandHandler"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
|
||||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
|
||||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
|
||||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
|
||||||
public ReorderLibraryMetadataProvidersCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<ReorderLibraryMetadataProvidersCommand> validator)
|
|
||||||
{
|
|
||||||
_authorizationService = authorizationService;
|
|
||||||
_currentUserService = currentUserService;
|
|
||||||
_unitOfWork = unitOfWork;
|
|
||||||
_validator = validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the command to reorder the metadata providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command">The request to be handled.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
|
||||||
/// </returns>
|
|
||||||
public async Task<Result<Success>> HandleAsync(ReorderLibraryMetadataProvidersCommand command, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
List<Error> validationResult = _validator.Validate(command);
|
|
||||||
if (validationResult.Count > 0)
|
|
||||||
return validationResult;
|
|
||||||
|
|
||||||
// An authenticated request must always carry a user identity.
|
|
||||||
Guid? currentUserId = _currentUserService.UserId;
|
|
||||||
if (currentUserId is null)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
Guid userId = currentUserId.Value;
|
|
||||||
|
|
||||||
// Admins can reorder the metadata providers of any library; for everyone else, only their own libraries.
|
|
||||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
|
||||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
|
||||||
if (!canAccessLibrary)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
|
|
||||||
// Load the metadata provider configurations that are currently registered for the library, so that only providers it actually has are reordered.
|
|
||||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (getConfigurationsResult.IsFailure)
|
|
||||||
return getConfigurationsResult.Errors;
|
|
||||||
|
|
||||||
// Index the configurations by plugin id, so that each requested plugin can be matched without repeatedly searching the list.
|
|
||||||
Dictionary<Guid, LibraryMetadataProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value.ToDictionary(configuration => configuration.PluginId);
|
|
||||||
// Walk the requested order and assign each provider the 1-based rank that matches its position in the command, so the persisted order follows the user's choice.
|
|
||||||
for (int rank = 0; rank < command.PluginIds.Count; rank++)
|
|
||||||
{
|
|
||||||
Guid pluginId = command.PluginIds[rank];
|
|
||||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryMetadataProviderConfigurationEntity? configuration))
|
|
||||||
{
|
|
||||||
configuration.Rank = rank + 1;
|
|
||||||
Result<Updated> upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (upsertResult.IsFailure)
|
|
||||||
return upsertResult.Errors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Persist all the rank changes in a single save, so that the reorder is applied atomically.
|
|
||||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
if (saveChangesResult.IsFailure)
|
|
||||||
return saveChangesResult.Errors;
|
|
||||||
return Result.Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Application.Common.Utilities;
|
|
||||||
using Lumina.Domain.Common.Errors;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates the needed validation rules for <see cref="ReorderLibraryMetadataProvidersCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
public class ReorderLibraryMetadataProvidersCommandValidator : AbstractValidator<ReorderLibraryMetadataProvidersCommand>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersCommandValidator"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public ReorderLibraryMetadataProvidersCommandValidator()
|
|
||||||
{
|
|
||||||
RuleFor(command => command.LibraryId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
|
||||||
.Must(id => id != Guid.Empty)
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
|
||||||
|
|
||||||
RuleFor(command => command.PluginIds)
|
|
||||||
.NotNull()
|
|
||||||
.WithError(Errors.Plugins.PluginIdsListCannotBeNull)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.PluginIdsListCannotBeEmpty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command for enabling or disabling an artwork provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose artwork provider is enabled or disabled.</param>
|
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the artwork.</param>
|
|
||||||
/// <param name="IsEnabled">Whether the artwork provider should be enabled for the media library.</param>
|
|
||||||
public record SetLibraryArtworkProviderEnabledCommand(
|
|
||||||
Guid LibraryId,
|
|
||||||
Guid PluginId,
|
|
||||||
bool IsEnabled
|
|
||||||
) : ICommand;
|
|
||||||
-113
@@ -1,113 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
|
||||||
using Lumina.Application.Common.DataAccess.UoW;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handler for the command to enable or disable an artwork provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
public class SetLibraryArtworkProviderEnabledCommandHandler : ICommandHandler<SetLibraryArtworkProviderEnabledCommand, Result<Success>>
|
|
||||||
{
|
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
|
||||||
private readonly IAuthorizationService _authorizationService;
|
|
||||||
private readonly ICurrentUserService _currentUserService;
|
|
||||||
private readonly IValidator<SetLibraryArtworkProviderEnabledCommand> _validator;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetLibraryArtworkProviderEnabledCommandHandler"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
|
||||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
|
||||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
|
||||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
|
||||||
public SetLibraryArtworkProviderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<SetLibraryArtworkProviderEnabledCommand> validator)
|
|
||||||
{
|
|
||||||
_authorizationService = authorizationService;
|
|
||||||
_currentUserService = currentUserService;
|
|
||||||
_unitOfWork = unitOfWork;
|
|
||||||
_validator = validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the command to enable or disable an artwork provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command">The request to be handled.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
|
||||||
/// </returns>
|
|
||||||
public async Task<Result<Success>> HandleAsync(SetLibraryArtworkProviderEnabledCommand command, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
List<Error> validationResult = _validator.Validate(command);
|
|
||||||
if (validationResult.Count > 0)
|
|
||||||
return validationResult;
|
|
||||||
|
|
||||||
// An authenticated request must always carry a user identity.
|
|
||||||
Guid? currentUserId = _currentUserService.UserId;
|
|
||||||
if (currentUserId is null)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
Guid userId = currentUserId.Value;
|
|
||||||
|
|
||||||
// Admins can configure the artwork providers of any library; for everyone else, only their own libraries.
|
|
||||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
|
||||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
|
||||||
if (!canAccessLibrary)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
|
|
||||||
// Look up the configuration of this provider for the library, so that an existing one is toggled instead of duplicated.
|
|
||||||
Result<LibraryArtworkProviderConfigurationEntity?> getConfigurationResult = await _unitOfWork.ArtworkProviderConfigurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (getConfigurationResult.IsFailure)
|
|
||||||
return getConfigurationResult.Errors;
|
|
||||||
|
|
||||||
LibraryArtworkProviderConfigurationEntity configuration;
|
|
||||||
if (getConfigurationResult.Value is not null)
|
|
||||||
{
|
|
||||||
// The provider is already configured for the library, so only its enabled state changes, keeping its existing rank in the display order.
|
|
||||||
configuration = getConfigurationResult.Value;
|
|
||||||
configuration.IsEnabled = command.IsEnabled;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Compute the rank to assign to the new configuration, appending it after the existing ones.
|
|
||||||
Result<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.ArtworkProviderConfigurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (getConfigurationsResult.IsFailure)
|
|
||||||
return getConfigurationsResult.Errors;
|
|
||||||
int nextRank = getConfigurationsResult.Value.Count == 0 ? 1 : getConfigurationsResult.Value.Max(configuration => configuration.Rank) + 1;
|
|
||||||
configuration = new LibraryArtworkProviderConfigurationEntity
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
LibraryId = command.LibraryId,
|
|
||||||
PluginId = command.PluginId,
|
|
||||||
IsEnabled = command.IsEnabled,
|
|
||||||
Rank = nextRank,
|
|
||||||
CreatedOnUtc = default,
|
|
||||||
CreatedBy = default,
|
|
||||||
UpdatedBy = default
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert the new configuration, or update the existing one, and persist the change.
|
|
||||||
Result<Updated> upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (upsertResult.IsFailure)
|
|
||||||
return upsertResult.Errors;
|
|
||||||
|
|
||||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
if (saveChangesResult.IsFailure)
|
|
||||||
return saveChangesResult.Errors;
|
|
||||||
return Result.Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Application.Common.Utilities;
|
|
||||||
using Lumina.Domain.Common.Errors;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates the needed validation rules for <see cref="SetLibraryArtworkProviderEnabledCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
public class SetLibraryArtworkProviderEnabledCommandValidator : AbstractValidator<SetLibraryArtworkProviderEnabledCommand>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetLibraryArtworkProviderEnabledCommandValidator"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public SetLibraryArtworkProviderEnabledCommandValidator()
|
|
||||||
{
|
|
||||||
RuleFor(command => command.LibraryId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
|
||||||
.Must(id => id != Guid.Empty)
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
|
||||||
|
|
||||||
RuleFor(command => command.PluginId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty)
|
|
||||||
.Must(id => id != Guid.Empty)
|
|
||||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command for enabling or disabling a book reader for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose book reader is enabled or disabled.</param>
|
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the book reader.</param>
|
|
||||||
/// <param name="IsEnabled">Whether the book reader should be enabled for the media library.</param>
|
|
||||||
public record SetLibraryBookReaderEnabledCommand(
|
|
||||||
Guid LibraryId,
|
|
||||||
Guid PluginId,
|
|
||||||
bool IsEnabled
|
|
||||||
) : ICommand;
|
|
||||||
-108
@@ -1,108 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
|
||||||
using Lumina.Application.Common.DataAccess.UoW;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Reading;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handler for the command to enable or disable a book reader for a media library.
|
|
||||||
/// </summary>
|
|
||||||
public class SetLibraryBookReaderEnabledCommandHandler : ICommandHandler<SetLibraryBookReaderEnabledCommand, Result<Success>>
|
|
||||||
{
|
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
|
||||||
private readonly IAuthorizationService _authorizationService;
|
|
||||||
private readonly ICurrentUserService _currentUserService;
|
|
||||||
private readonly IBookReaderEnablementCache _enablementCache;
|
|
||||||
private readonly IValidator<SetLibraryBookReaderEnabledCommand> _validator;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetLibraryBookReaderEnabledCommandHandler"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
|
||||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
|
||||||
/// <param name="enablementCache">Injected cache of whether the book reader of a plugin is enabled for a media library.</param>
|
|
||||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
|
||||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
|
||||||
public SetLibraryBookReaderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReaderEnablementCache enablementCache, IUnitOfWork unitOfWork, IValidator<SetLibraryBookReaderEnabledCommand> validator)
|
|
||||||
{
|
|
||||||
_authorizationService = authorizationService;
|
|
||||||
_currentUserService = currentUserService;
|
|
||||||
_enablementCache = enablementCache;
|
|
||||||
_unitOfWork = unitOfWork;
|
|
||||||
_validator = validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the command to enable or disable a book reader for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command">The request to be handled.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
|
||||||
/// </returns>
|
|
||||||
public async Task<Result<Success>> HandleAsync(SetLibraryBookReaderEnabledCommand command, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
List<Error> validationResult = _validator.Validate(command);
|
|
||||||
if (validationResult.Count > 0)
|
|
||||||
return validationResult;
|
|
||||||
|
|
||||||
// An authenticated request must always carry a user identity.
|
|
||||||
Guid? currentUserId = _currentUserService.UserId;
|
|
||||||
if (currentUserId is null)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
Guid userId = currentUserId.Value;
|
|
||||||
|
|
||||||
// Admins can configure the book readers of any library; for everyone else, only their own libraries.
|
|
||||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
|
||||||
if (!canAccessLibrary)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
|
|
||||||
Result<LibraryBookReaderConfigurationEntity?> getConfigurationResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (getConfigurationResult.IsFailure)
|
|
||||||
return getConfigurationResult.Errors;
|
|
||||||
|
|
||||||
LibraryBookReaderConfigurationEntity configuration;
|
|
||||||
if (getConfigurationResult.Value is not null)
|
|
||||||
{
|
|
||||||
configuration = getConfigurationResult.Value;
|
|
||||||
configuration.IsEnabled = command.IsEnabled;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
configuration = new LibraryBookReaderConfigurationEntity
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
LibraryId = command.LibraryId,
|
|
||||||
PluginId = command.PluginId,
|
|
||||||
IsEnabled = command.IsEnabled,
|
|
||||||
CreatedOnUtc = default,
|
|
||||||
CreatedBy = default,
|
|
||||||
UpdatedBy = default
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<Updated> upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (upsertResult.IsFailure)
|
|
||||||
return upsertResult.Errors;
|
|
||||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
if (saveChangesResult.IsFailure)
|
|
||||||
return saveChangesResult.Errors;
|
|
||||||
// The reading service caches the enablement of a reader, because it consults it on every request; the cache is invalidated here,
|
|
||||||
// so that disabling a reader cuts access to its books immediately, without waiting for the cache to expire.
|
|
||||||
_enablementCache.Invalidate(command.LibraryId, command.PluginId);
|
|
||||||
return Result.Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Application.Common.Utilities;
|
|
||||||
using Lumina.Domain.Common.Errors;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates the needed validation rules for <see cref="SetLibraryBookReaderEnabledCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
public class SetLibraryBookReaderEnabledCommandValidator : AbstractValidator<SetLibraryBookReaderEnabledCommand>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetLibraryBookReaderEnabledCommandValidator"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public SetLibraryBookReaderEnabledCommandValidator()
|
|
||||||
{
|
|
||||||
RuleFor(command => command.LibraryId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
|
||||||
|
|
||||||
RuleFor(command => command.PluginId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command for enabling or disabling a metadata provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose metadata provider is enabled or disabled.</param>
|
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the metadata.</param>
|
|
||||||
/// <param name="IsEnabled">Whether the metadata provider should be enabled for the media library.</param>
|
|
||||||
public record SetLibraryMetadataProviderEnabledCommand(
|
|
||||||
Guid LibraryId,
|
|
||||||
Guid PluginId,
|
|
||||||
bool IsEnabled
|
|
||||||
) : ICommand;
|
|
||||||
-113
@@ -1,113 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
|
||||||
using Lumina.Application.Common.DataAccess.UoW;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handler for the command to enable or disable a metadata provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<SetLibraryMetadataProviderEnabledCommand, Result<Success>>
|
|
||||||
{
|
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
|
||||||
private readonly IAuthorizationService _authorizationService;
|
|
||||||
private readonly ICurrentUserService _currentUserService;
|
|
||||||
private readonly IValidator<SetLibraryMetadataProviderEnabledCommand> _validator;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledCommandHandler"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
|
||||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
|
||||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
|
||||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
|
||||||
public SetLibraryMetadataProviderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<SetLibraryMetadataProviderEnabledCommand> validator)
|
|
||||||
{
|
|
||||||
_authorizationService = authorizationService;
|
|
||||||
_currentUserService = currentUserService;
|
|
||||||
_unitOfWork = unitOfWork;
|
|
||||||
_validator = validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the command to enable or disable a metadata provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command">The request to be handled.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
|
||||||
/// </returns>
|
|
||||||
public async Task<Result<Success>> HandleAsync(SetLibraryMetadataProviderEnabledCommand command, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
List<Error> validationResult = _validator.Validate(command);
|
|
||||||
if (validationResult.Count > 0)
|
|
||||||
return validationResult;
|
|
||||||
|
|
||||||
// An authenticated request must always carry a user identity.
|
|
||||||
Guid? currentUserId = _currentUserService.UserId;
|
|
||||||
if (currentUserId is null)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
Guid userId = currentUserId.Value;
|
|
||||||
|
|
||||||
// Admins can configure the metadata providers of any library; for everyone else, only their own libraries.
|
|
||||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
|
||||||
userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
|
|
||||||
if (!canAccessLibrary)
|
|
||||||
return ApplicationErrors.Authorization.NotAuthorized;
|
|
||||||
|
|
||||||
// Look up the configuration of this provider for the library, so that an existing one is toggled instead of duplicated.
|
|
||||||
Result<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (getConfigurationResult.IsFailure)
|
|
||||||
return getConfigurationResult.Errors;
|
|
||||||
|
|
||||||
LibraryMetadataProviderConfigurationEntity configuration;
|
|
||||||
if (getConfigurationResult.Value is not null)
|
|
||||||
{
|
|
||||||
// The provider is already configured for the library, so only its enabled state changes, keeping its existing rank in the display order.
|
|
||||||
configuration = getConfigurationResult.Value;
|
|
||||||
configuration.IsEnabled = command.IsEnabled;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Compute the rank to assign to the new configuration, appending it after the existing ones.
|
|
||||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (getConfigurationsResult.IsFailure)
|
|
||||||
return getConfigurationsResult.Errors;
|
|
||||||
int nextRank = getConfigurationsResult.Value.Count == 0 ? 1 : getConfigurationsResult.Value.Max(configuration => configuration.Rank) + 1;
|
|
||||||
configuration = new LibraryMetadataProviderConfigurationEntity
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
LibraryId = command.LibraryId,
|
|
||||||
PluginId = command.PluginId,
|
|
||||||
IsEnabled = command.IsEnabled,
|
|
||||||
Rank = nextRank,
|
|
||||||
CreatedOnUtc = default,
|
|
||||||
CreatedBy = default,
|
|
||||||
UpdatedBy = default
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert the new configuration, or update the existing one, and persist the change.
|
|
||||||
Result<Updated> upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (upsertResult.IsFailure)
|
|
||||||
return upsertResult.Errors;
|
|
||||||
|
|
||||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
if (saveChangesResult.IsFailure)
|
|
||||||
return saveChangesResult.Errors;
|
|
||||||
return Result.Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.Infrastructure.Validation;
|
|
||||||
using Lumina.Application.Common.Utilities;
|
|
||||||
using Lumina.Domain.Common.Errors;
|
|
||||||
using System;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates the needed validation rules for <see cref="SetLibraryMetadataProviderEnabledCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
public class SetLibraryMetadataProviderEnabledCommandValidator : AbstractValidator<SetLibraryMetadataProviderEnabledCommand>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetLibraryMetadataProviderEnabledCommandValidator"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public SetLibraryMetadataProviderEnabledCommandValidator()
|
|
||||||
{
|
|
||||||
RuleFor(command => command.LibraryId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty)
|
|
||||||
.Must(id => id != Guid.Empty)
|
|
||||||
.WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
|
|
||||||
|
|
||||||
RuleFor(command => command.PluginId)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty)
|
|
||||||
.Must(id => id != Guid.Empty)
|
|
||||||
.WithError(Errors.Plugins.PluginIdCannotBeEmpty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query for getting the artwork providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="LibraryType">The media library type whose available artwork providers are retrieved.</param>
|
||||||
|
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||||
|
public record GetLibraryTypeArtworkProvidersQuery(
|
||||||
|
string? LibraryType
|
||||||
|
) : IQuery;
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||||
|
using Lumina.Application.Common.DataAccess.UoW;
|
||||||
|
using Lumina.Application.Common.DTO.Filtering;
|
||||||
|
using Lumina.Application.Common.DTO.Pagination;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Validation;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using Lumina.Domain.Common.Primitives;
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handler for the query to get the artwork providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeArtworkProvidersQueryHandler : IQueryHandler<GetLibraryTypeArtworkProvidersQuery, Result<IReadOnlyList<LibraryArtworkProviderResponse>>>
|
||||||
|
{
|
||||||
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
private readonly ICurrentUserService _currentUserService;
|
||||||
|
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
|
||||||
|
private readonly IValidator<GetLibraryTypeArtworkProvidersQuery> _validator;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeArtworkProvidersQueryHandler"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||||
|
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
|
||||||
|
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||||
|
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||||
|
public GetLibraryTypeArtworkProvidersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IUnitOfWork unitOfWork, IValidator<GetLibraryTypeArtworkProvidersQuery> validator)
|
||||||
|
{
|
||||||
|
_currentUserService = currentUserService;
|
||||||
|
_providerConfigurationStore = providerConfigurationStore;
|
||||||
|
_unitOfWork = unitOfWork;
|
||||||
|
_validator = validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the query to get the artwork providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query to be handled.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryArtworkProviderResponse"/>, or an error.
|
||||||
|
/// </returns>
|
||||||
|
public async Task<Result<IReadOnlyList<LibraryArtworkProviderResponse>>> HandleAsync(GetLibraryTypeArtworkProvidersQuery query, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
List<Error> validationResult = _validator.Validate(query);
|
||||||
|
if (validationResult.Count > 0)
|
||||||
|
return validationResult;
|
||||||
|
|
||||||
|
// An authenticated request must always carry a user identity.
|
||||||
|
if (_currentUserService.UserId is null)
|
||||||
|
return ApplicationErrors.Authorization.NotAuthorized;
|
||||||
|
|
||||||
|
LibraryType libraryType = Enum.Parse<LibraryType>(query.LibraryType!, ignoreCase: true);
|
||||||
|
|
||||||
|
// Build a plugin name lookup from the detected plugins, so that each provider is returned with its display name.
|
||||||
|
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
|
if (getPluginsResult.IsFailure)
|
||||||
|
return getPluginsResult.Errors;
|
||||||
|
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.Data.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||||
|
|
||||||
|
// The providers are returned the way a new media library of this type is configured with them: disabled, and ranked in alphabetical order.
|
||||||
|
IReadOnlyList<Guid> pluginIds = _providerConfigurationStore.GetSupportedArtworkProviderPluginIds(libraryType);
|
||||||
|
return pluginIds
|
||||||
|
.Select((pluginId, index) => new LibraryArtworkProviderResponse(pluginId, pluginNames.GetValueOrDefault(pluginId) ?? string.Empty, IsEnabled: false, Rank: index + 1))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.Infrastructure.Validation;
|
||||||
|
using Lumina.Application.Common.Utilities;
|
||||||
|
using Lumina.Domain.Common.Errors;
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the needed validation rules for <see cref="GetLibraryTypeArtworkProvidersQuery"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeArtworkProvidersQueryValidator : AbstractValidator<GetLibraryTypeArtworkProvidersQuery>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeArtworkProvidersQueryValidator"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public GetLibraryTypeArtworkProvidersQueryValidator()
|
||||||
|
{
|
||||||
|
RuleFor(query => query.LibraryType)
|
||||||
|
.NotNull()
|
||||||
|
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||||
|
.IsInEnum<GetLibraryTypeArtworkProvidersQuery, LibraryType>()
|
||||||
|
.WithError(Errors.Library.UnknownLibraryType);
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query for getting the book readers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="LibraryType">The media library type whose available book readers are retrieved.</param>
|
||||||
|
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||||
|
public record GetLibraryTypeBookReadersQuery(
|
||||||
|
string? LibraryType
|
||||||
|
) : IQuery;
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||||
|
using Lumina.Application.Common.DataAccess.UoW;
|
||||||
|
using Lumina.Application.Common.DTO.Filtering;
|
||||||
|
using Lumina.Application.Common.DTO.Pagination;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Reading;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Validation;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using Lumina.Domain.Common.Primitives;
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handler for the query to get the book readers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeBookReadersQueryHandler : IQueryHandler<GetLibraryTypeBookReadersQuery, Result<IReadOnlyList<LibraryBookReaderResponse>>>
|
||||||
|
{
|
||||||
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
private readonly ICurrentUserService _currentUserService;
|
||||||
|
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
|
||||||
|
private readonly IBookReaderRegistry _bookReaderRegistry;
|
||||||
|
private readonly IValidator<GetLibraryTypeBookReadersQuery> _validator;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeBookReadersQueryHandler"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||||
|
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
|
||||||
|
/// <param name="bookReaderRegistry">Injected registry of the book readers provided by the loaded plugins.</param>
|
||||||
|
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||||
|
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||||
|
public GetLibraryTypeBookReadersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IBookReaderRegistry bookReaderRegistry, IUnitOfWork unitOfWork, IValidator<GetLibraryTypeBookReadersQuery> validator)
|
||||||
|
{
|
||||||
|
_currentUserService = currentUserService;
|
||||||
|
_providerConfigurationStore = providerConfigurationStore;
|
||||||
|
_bookReaderRegistry = bookReaderRegistry;
|
||||||
|
_unitOfWork = unitOfWork;
|
||||||
|
_validator = validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the query to get the book readers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query to be handled.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryBookReaderResponse"/>, or an error.
|
||||||
|
/// </returns>
|
||||||
|
public async Task<Result<IReadOnlyList<LibraryBookReaderResponse>>> HandleAsync(GetLibraryTypeBookReadersQuery query, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
List<Error> validationResult = _validator.Validate(query);
|
||||||
|
if (validationResult.Count > 0)
|
||||||
|
return validationResult;
|
||||||
|
|
||||||
|
// An authenticated request must always carry a user identity.
|
||||||
|
if (_currentUserService.UserId is null)
|
||||||
|
return ApplicationErrors.Authorization.NotAuthorized;
|
||||||
|
|
||||||
|
LibraryType libraryType = Enum.Parse<LibraryType>(query.LibraryType!, ignoreCase: true);
|
||||||
|
|
||||||
|
// Build a plugin name lookup from the detected plugins, so that each reader is returned with its display name.
|
||||||
|
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
|
if (getPluginsResult.IsFailure)
|
||||||
|
return getPluginsResult.Errors;
|
||||||
|
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.Data.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||||
|
|
||||||
|
IReadOnlyDictionary<Guid, IReadOnlyList<string>> supportedExtensionsByPluginId = _bookReaderRegistry.GetSupportedExtensionsByPluginId();
|
||||||
|
|
||||||
|
// The readers are returned the way a new media library of this type is configured with them: disabled, in alphabetical order.
|
||||||
|
IReadOnlyList<Guid> pluginIds = _providerConfigurationStore.GetSupportedBookReaderPluginIds(libraryType);
|
||||||
|
return pluginIds
|
||||||
|
.Select(pluginId => new LibraryBookReaderResponse(
|
||||||
|
pluginId,
|
||||||
|
pluginNames.GetValueOrDefault(pluginId) ?? string.Empty,
|
||||||
|
supportedExtensionsByPluginId.GetValueOrDefault(pluginId) ?? [],
|
||||||
|
IsEnabled: false))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.Infrastructure.Validation;
|
||||||
|
using Lumina.Application.Common.Utilities;
|
||||||
|
using Lumina.Domain.Common.Errors;
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the needed validation rules for <see cref="GetLibraryTypeBookReadersQuery"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeBookReadersQueryValidator : AbstractValidator<GetLibraryTypeBookReadersQuery>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeBookReadersQueryValidator"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public GetLibraryTypeBookReadersQueryValidator()
|
||||||
|
{
|
||||||
|
RuleFor(query => query.LibraryType)
|
||||||
|
.NotNull()
|
||||||
|
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||||
|
.IsInEnum<GetLibraryTypeBookReadersQuery, LibraryType>()
|
||||||
|
.WithError(Errors.Library.UnknownLibraryType);
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query for getting the metadata providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="LibraryType">The media library type whose available metadata providers are retrieved.</param>
|
||||||
|
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||||
|
public record GetLibraryTypeMetadataProvidersQuery(
|
||||||
|
string? LibraryType
|
||||||
|
) : IQuery;
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||||
|
using Lumina.Application.Common.DataAccess.UoW;
|
||||||
|
using Lumina.Application.Common.DTO.Filtering;
|
||||||
|
using Lumina.Application.Common.DTO.Pagination;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||||
|
using Lumina.Application.Common.Infrastructure.Validation;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using Lumina.Domain.Common.Primitives;
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handler for the query to get the metadata providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeMetadataProvidersQueryHandler : IQueryHandler<GetLibraryTypeMetadataProvidersQuery, Result<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||||
|
{
|
||||||
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
private readonly ICurrentUserService _currentUserService;
|
||||||
|
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
|
||||||
|
private readonly IValidator<GetLibraryTypeMetadataProvidersQuery> _validator;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeMetadataProvidersQueryHandler"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||||
|
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
|
||||||
|
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||||
|
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||||
|
public GetLibraryTypeMetadataProvidersQueryHandler(ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IUnitOfWork unitOfWork, IValidator<GetLibraryTypeMetadataProvidersQuery> validator)
|
||||||
|
{
|
||||||
|
_currentUserService = currentUserService;
|
||||||
|
_providerConfigurationStore = providerConfigurationStore;
|
||||||
|
_unitOfWork = unitOfWork;
|
||||||
|
_validator = validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the query to get the metadata providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query to be handled.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryMetadataProviderResponse"/>, or an error.
|
||||||
|
/// </returns>
|
||||||
|
public async Task<Result<IReadOnlyList<LibraryMetadataProviderResponse>>> HandleAsync(GetLibraryTypeMetadataProvidersQuery query, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
List<Error> validationResult = _validator.Validate(query);
|
||||||
|
if (validationResult.Count > 0)
|
||||||
|
return validationResult;
|
||||||
|
|
||||||
|
// An authenticated request must always carry a user identity.
|
||||||
|
if (_currentUserService.UserId is null)
|
||||||
|
return ApplicationErrors.Authorization.NotAuthorized;
|
||||||
|
|
||||||
|
LibraryType libraryType = Enum.Parse<LibraryType>(query.LibraryType!, ignoreCase: true);
|
||||||
|
|
||||||
|
// Build a plugin name lookup from the detected plugins, so that each provider is returned with its display name.
|
||||||
|
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
|
if (getPluginsResult.IsFailure)
|
||||||
|
return getPluginsResult.Errors;
|
||||||
|
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.Data.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||||
|
|
||||||
|
// The providers are returned the way a new media library of this type is configured with them: disabled, and ranked in alphabetical order.
|
||||||
|
IReadOnlyList<Guid> pluginIds = _providerConfigurationStore.GetSupportedMetadataProviderPluginIds(libraryType);
|
||||||
|
return pluginIds
|
||||||
|
.Select((pluginId, index) => new LibraryMetadataProviderResponse(pluginId, pluginNames.GetValueOrDefault(pluginId) ?? string.Empty, IsEnabled: false, Rank: index + 1))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Application.Common.Infrastructure.Validation;
|
||||||
|
using Lumina.Application.Common.Utilities;
|
||||||
|
using Lumina.Domain.Common.Errors;
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the needed validation rules for <see cref="GetLibraryTypeMetadataProvidersQuery"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeMetadataProvidersQueryValidator : AbstractValidator<GetLibraryTypeMetadataProvidersQuery>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeMetadataProvidersQueryValidator"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public GetLibraryTypeMetadataProvidersQueryValidator()
|
||||||
|
{
|
||||||
|
RuleFor(query => query.LibraryType)
|
||||||
|
.NotNull()
|
||||||
|
.WithError(Errors.Library.LibraryTypeCannotBeNull)
|
||||||
|
.IsInEnum<GetLibraryTypeMetadataProvidersQuery, LibraryType>()
|
||||||
|
.WithError(Errors.Library.UnknownLibraryType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,15 +11,18 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
|||||||
/// <param name="LibraryType">The type of the media library. Required.</param>
|
/// <param name="LibraryType">The type of the media library. Required.</param>
|
||||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located. Required.</param>
|
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located. Required.</param>
|
||||||
/// <param name="CoverImage">The path of the image file used as the cover for the library. Optional.</param>
|
/// <param name="CoverImage">The path of the image file used as the cover for the library. Optional.</param>
|
||||||
/// <param name="IsEnabled">Whether this media library is enabled or not. A disabled media library is never shown or changed. Optional.</param>
|
/// <param name="IsEnabled">Whether this media library is enabled or not. A disabled media library is never shown or changed. Required.</param>
|
||||||
/// <param name="IsLocked">Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Optional.</param>
|
/// <param name="IsLocked">Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Required.</param>
|
||||||
/// <param name="CanDownloadMetadataFromWeb">Whether this media library should update the metadata of its elements from the web, or not. Optional.</param>
|
/// <param name="CanDownloadMetadataFromWeb">Whether this media library should update the metadata of its elements from the web, or not. Required.</param>
|
||||||
/// <param name="ShouldSaveMetadataInMediaDirectories">Whether this media library should copy the downloaded metadata into the media library content locations, or not. Optional.</param>
|
/// <param name="ShouldSaveMetadataInMediaDirectories">Whether this media library should copy the downloaded metadata into the media library content locations, or not. Required.</param>
|
||||||
/// <param name="ShouldSkipUnchangedDirectoriesDuringScan">Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional.</param>
|
/// <param name="ShouldSkipUnchangedDirectoriesDuringScan">Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Required.</param>
|
||||||
/// <param name="IsContentOnSsd">Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Optional.</param>
|
/// <param name="IsContentOnSsd">Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Required.</param>
|
||||||
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. Optional, the default of the library type is used when absent.</param>
|
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. Optional, the default of the library type is used when absent.</param>
|
||||||
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the default of the library type is used when absent.</param>
|
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the default of the library type is used when absent.</param>
|
||||||
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.</param>
|
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.</param>
|
||||||
|
/// <param name="MetadataProviders">The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, every provider supported by the library type is added disabled.</param>
|
||||||
|
/// <param name="ArtworkProviders">The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, every provider supported by the library type is added disabled.</param>
|
||||||
|
/// <param name="BookReaders">The book readers of the media library, and whether each one is enabled. Optional, every reader supported by the library type is added disabled.</param>
|
||||||
[DebuggerDisplay("Title: {Title}")]
|
[DebuggerDisplay("Title: {Title}")]
|
||||||
public record AddLibraryRequest(
|
public record AddLibraryRequest(
|
||||||
string? Title,
|
string? Title,
|
||||||
@@ -34,5 +37,8 @@ public record AddLibraryRequest(
|
|||||||
bool IsContentOnSsd,
|
bool IsContentOnSsd,
|
||||||
bool? ShouldTrackConsumptionProgress,
|
bool? ShouldTrackConsumptionProgress,
|
||||||
int? CompletionThresholdPercentage,
|
int? CompletionThresholdPercentage,
|
||||||
LibraryPathTemplatePartRequest[]? PathTemplateParts
|
LibraryPathTemplatePartRequest?[]? PathTemplateParts,
|
||||||
|
LibraryProviderSelectionRequest?[]? MetadataProviders,
|
||||||
|
LibraryProviderSelectionRequest?[]? ArtworkProviders,
|
||||||
|
LibraryProviderSelectionRequest?[]? BookReaders
|
||||||
);
|
);
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the choice made for one metadata provider, artwork provider or book reader of a media library.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="PluginId">The Id of the plugin providing the metadata provider, artwork provider or book reader. Required.</param>
|
||||||
|
/// <param name="IsEnabled">Whether the provider or reader is enabled for the media library. Optional, the stored state is kept when absent, and a provider or reader without a stored state starts disabled.</param>
|
||||||
|
[DebuggerDisplay("PluginId: {PluginId}; IsEnabled: {IsEnabled}")]
|
||||||
|
public record LibraryProviderSelectionRequest(
|
||||||
|
Guid PluginId,
|
||||||
|
bool? IsEnabled
|
||||||
|
);
|
||||||
@@ -9,24 +9,25 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
|||||||
/// Represents a request to update a media library.
|
/// Represents a request to update a media library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Id">The unique identifier of the media library. Required.</param>
|
/// <param name="Id">The unique identifier of the media library. Required.</param>
|
||||||
/// <param name="UserId">The unique identifier of the user owning the media library. Required.</param>
|
|
||||||
/// <param name="Title">The title of the media library. Required.</param>
|
/// <param name="Title">The title of the media library. Required.</param>
|
||||||
/// <param name="LibraryType">The type of the media library. Required.</param>
|
/// <param name="LibraryType">The type of the media library. Required.</param>
|
||||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located. Required.</param>
|
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located. Required.</param>
|
||||||
/// <param name="CoverImage">The path of the image file used as the cover for the library. Optional.</param>
|
/// <param name="CoverImage">The path of the image file used as the cover for the library. Optional.</param>
|
||||||
/// <param name="IsEnabled">Whether this media library is enabled or not. A disabled media library is never shown or changed. Optional.</param>
|
/// <param name="IsEnabled">Whether this media library is enabled or not. A disabled media library is never shown or changed. Required.</param>
|
||||||
/// <param name="IsLocked">Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Optional.</param>
|
/// <param name="IsLocked">Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. Required.</param>
|
||||||
/// <param name="CanDownloadMetadataFromWeb">Whether this media library should update the metadata of its elements from the web, or not. Optional.</param>
|
/// <param name="CanDownloadMetadataFromWeb">Whether this media library should update the metadata of its elements from the web, or not. Required.</param>
|
||||||
/// <param name="ShouldSaveMetadataInMediaDirectories">Whether this media library should copy the downloaded metadata into the media library content locations, or not.
|
/// <param name="ShouldSaveMetadataInMediaDirectories">Whether this media library should copy the downloaded metadata into the media library content locations, or not. Required.</param>
|
||||||
/// <param name="ShouldSkipUnchangedDirectoriesDuringScan">Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional.</param>
|
/// <param name="ShouldSkipUnchangedDirectoriesDuringScan">Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Required.</param>
|
||||||
/// <param name="IsContentOnSsd">Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Optional.</param>
|
/// <param name="IsContentOnSsd">Whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel. Required.</param>
|
||||||
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. Optional, the stored value is kept when absent.</param>
|
/// <param name="ShouldTrackConsumptionProgress">Whether the consumption progress of the media library items should be tracked, or not. Optional, the stored value is kept when absent.</param>
|
||||||
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the stored value is kept when absent.</param>
|
/// <param name="CompletionThresholdPercentage">The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the stored value is kept when absent.</param>
|
||||||
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.</param>
|
/// <param name="PathTemplateParts">The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.</param>
|
||||||
|
/// <param name="MetadataProviders">The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||||
|
/// <param name="ArtworkProviders">The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||||
|
/// <param name="BookReaders">The book readers of the media library, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes.</param>
|
||||||
[DebuggerDisplay("Title: {Title}")]
|
[DebuggerDisplay("Title: {Title}")]
|
||||||
public record class UpdateLibraryRequest(
|
public record class UpdateLibraryRequest(
|
||||||
Guid Id,
|
Guid Id,
|
||||||
Guid UserId,
|
|
||||||
string? Title,
|
string? Title,
|
||||||
string? LibraryType,
|
string? LibraryType,
|
||||||
string[]? ContentLocations,
|
string[]? ContentLocations,
|
||||||
@@ -39,5 +40,8 @@ public record class UpdateLibraryRequest(
|
|||||||
bool IsContentOnSsd,
|
bool IsContentOnSsd,
|
||||||
bool? ShouldTrackConsumptionProgress,
|
bool? ShouldTrackConsumptionProgress,
|
||||||
int? CompletionThresholdPercentage,
|
int? CompletionThresholdPercentage,
|
||||||
LibraryPathTemplatePartRequest[]? PathTemplateParts
|
LibraryPathTemplatePartRequest?[]? PathTemplateParts,
|
||||||
|
LibraryProviderSelectionRequest?[]? MetadataProviders,
|
||||||
|
LibraryProviderSelectionRequest?[]? ArtworkProviders,
|
||||||
|
LibraryProviderSelectionRequest?[]? BookReaders
|
||||||
);
|
);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Contracts.Requests.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a request to get the artwork providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="LibraryType">The media library type whose available artwork providers are retrieved. Required.</param>
|
||||||
|
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||||
|
public sealed record GetLibraryTypeArtworkProvidersRequest(
|
||||||
|
string? LibraryType
|
||||||
|
);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Contracts.Requests.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a request to get the book readers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="LibraryType">The media library type whose available book readers are retrieved. Required.</param>
|
||||||
|
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||||
|
public sealed record GetLibraryTypeBookReadersRequest(
|
||||||
|
string? LibraryType
|
||||||
|
);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Contracts.Requests.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a request to get the metadata providers available for a media library type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="LibraryType">The media library type whose available metadata providers are retrieved. Required.</param>
|
||||||
|
[DebuggerDisplay("LibraryType: {LibraryType}")]
|
||||||
|
public sealed record GetLibraryTypeMetadataProvidersRequest(
|
||||||
|
string? LibraryType
|
||||||
|
);
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Contracts.Requests.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a request to reorder the artwork providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The unique identifier of the media library whose artwork providers are reordered. Required.</param>
|
|
||||||
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank. Required.</param>
|
|
||||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
|
||||||
public sealed record ReorderLibraryArtworkProvidersRequest(
|
|
||||||
Guid LibraryId,
|
|
||||||
IReadOnlyList<Guid> PluginIds
|
|
||||||
);
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Contracts.Requests.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a request to reorder the metadata providers of a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose metadata providers are reordered. Required.</param>
|
|
||||||
/// <param name="PluginIds">The plugin Ids in the new order, from highest to lowest rank. Required.</param>
|
|
||||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
|
||||||
public sealed record ReorderLibraryMetadataProvidersRequest(
|
|
||||||
Guid LibraryId,
|
|
||||||
IReadOnlyList<Guid> PluginIds
|
|
||||||
);
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Contracts.Requests.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a request to enable or disable an artwork provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The unique identifier of the media library whose artwork provider is enabled or disabled. Required.</param>
|
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the artwork. Required.</param>
|
|
||||||
/// <param name="IsEnabled">Whether the artwork provider should be enabled for the media library. Required.</param>
|
|
||||||
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
|
|
||||||
public sealed record SetLibraryArtworkProviderEnabledRequest(
|
|
||||||
Guid LibraryId,
|
|
||||||
Guid PluginId,
|
|
||||||
bool IsEnabled
|
|
||||||
);
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Contracts.Requests.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a request to enable or disable a book reader for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose book reader is enabled or disabled. Required.</param>
|
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the book reader. Required.</param>
|
|
||||||
/// <param name="IsEnabled">Whether the book reader should be enabled for the media library. Required.</param>
|
|
||||||
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
|
|
||||||
public sealed record SetLibraryBookReaderEnabledRequest(
|
|
||||||
Guid LibraryId,
|
|
||||||
Guid PluginId,
|
|
||||||
bool IsEnabled
|
|
||||||
);
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Contracts.Requests.Plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a request to enable or disable a metadata provider for a media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LibraryId">The Id of the media library whose metadata provider is enabled or disabled. Required.</param>
|
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the metadata. Required.</param>
|
|
||||||
/// <param name="IsEnabled">Whether the metadata provider should be enabled for the media library. Required.</param>
|
|
||||||
[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
|
|
||||||
public sealed record SetLibraryMetadataProviderEnabledRequest(
|
|
||||||
Guid LibraryId,
|
|
||||||
Guid PluginId,
|
|
||||||
bool IsEnabled
|
|
||||||
);
|
|
||||||
@@ -5,12 +5,12 @@ using System;
|
|||||||
namespace Lumina.Contracts.Responses.Plugins;
|
namespace Lumina.Contracts.Responses.Plugins;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an artwork provider configured for a media library.
|
/// Represents an artwork provider, either as configured for a media library, or as available for a library type, the way a new library of that type starts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the artwork.</param>
|
/// <param name="PluginId">The unique identifier of the plugin providing the artwork.</param>
|
||||||
/// <param name="Name">The display name of the artwork provider.</param>
|
/// <param name="Name">The display name of the artwork provider.</param>
|
||||||
/// <param name="IsEnabled">Whether the artwork provider is enabled for the media library.</param>
|
/// <param name="IsEnabled">Whether the artwork provider is enabled for the media library. Always <see langword="false"/> for a provider available for a library type, since a new provider starts disabled.</param>
|
||||||
/// <param name="Rank">The rank of the artwork provider, determining the order in which providers are tried.</param>
|
/// <param name="Rank">The rank of the artwork provider, determining the order in which providers are tried. For a provider available for a library type, it is the rank a new library starts with, in alphabetical order of the plugin names.</param>
|
||||||
public sealed record LibraryArtworkProviderResponse(
|
public sealed record LibraryArtworkProviderResponse(
|
||||||
Guid PluginId,
|
Guid PluginId,
|
||||||
string Name,
|
string Name,
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ using System.Diagnostics;
|
|||||||
namespace Lumina.Contracts.Responses.Plugins;
|
namespace Lumina.Contracts.Responses.Plugins;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a book reader configured for a media library.
|
/// Represents a book reader, either as configured for a media library, or as available for a library type, the way a new library of that type starts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the book reader.</param>
|
/// <param name="PluginId">The unique identifier of the plugin providing the book reader.</param>
|
||||||
/// <param name="Name">The display name of the book reader.</param>
|
/// <param name="Name">The display name of the book reader.</param>
|
||||||
/// <param name="SupportedExtensions">The file extensions supported by the book reader.</param>
|
/// <param name="SupportedExtensions">The file extensions supported by the book reader.</param>
|
||||||
/// <param name="IsEnabled">Whether the book reader is enabled for the media library.</param>
|
/// <param name="IsEnabled">Whether the book reader is enabled for the media library. Always <see langword="false"/> for a reader available for a library type, since a new reader starts disabled.</param>
|
||||||
[DebuggerDisplay("Name: {Name}")]
|
[DebuggerDisplay("Name: {Name}")]
|
||||||
public sealed record LibraryBookReaderResponse(
|
public sealed record LibraryBookReaderResponse(
|
||||||
Guid PluginId,
|
Guid PluginId,
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ using System;
|
|||||||
namespace Lumina.Contracts.Responses.Plugins;
|
namespace Lumina.Contracts.Responses.Plugins;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a metadata provider configured for a media library.
|
/// Represents a metadata provider, either as configured for a media library, or as available for a library type, the way a new library of that type starts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="PluginId">The unique identifier of the plugin providing the metadata.</param>
|
/// <param name="PluginId">The unique identifier of the plugin providing the metadata.</param>
|
||||||
/// <param name="Name">The display name of the metadata provider.</param>
|
/// <param name="Name">The display name of the metadata provider.</param>
|
||||||
/// <param name="IsEnabled">Whether the metadata provider is enabled for the media library.</param>
|
/// <param name="IsEnabled">Whether the metadata provider is enabled for the media library. Always <see langword="false"/> for a provider available for a library type, since a new provider starts disabled.</param>
|
||||||
/// <param name="Rank">The rank of the metadata provider, determining the order in which providers are tried.</param>
|
/// <param name="Rank">The rank of the metadata provider, determining the order in which providers are tried. For a provider available for a library type, it is the rank a new library starts with, in alphabetical order of the plugin names.</param>
|
||||||
public sealed record LibraryMetadataProviderResponse(
|
public sealed record LibraryMetadataProviderResponse(
|
||||||
Guid PluginId,
|
Guid PluginId,
|
||||||
string Name,
|
string Name,
|
||||||
|
|||||||
+6
-3
@@ -20,7 +20,7 @@ public class LibraryArtworkProviderConfigurationConfiguration : IEntityTypeConfi
|
|||||||
builder.ToTable("LibraryArtworkProviderConfigurations");
|
builder.ToTable("LibraryArtworkProviderConfigurations");
|
||||||
builder.HasKey(configuration => configuration.Id);
|
builder.HasKey(configuration => configuration.Id);
|
||||||
builder.Property(configuration => configuration.Id)
|
builder.Property(configuration => configuration.Id)
|
||||||
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
|
.ValueGeneratedNever() // Because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it.
|
||||||
.HasColumnOrder(0);
|
.HasColumnOrder(0);
|
||||||
builder.Property(configuration => configuration.LibraryId)
|
builder.Property(configuration => configuration.LibraryId)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
@@ -35,7 +35,7 @@ public class LibraryArtworkProviderConfigurationConfiguration : IEntityTypeConfi
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnOrder(4);
|
.HasColumnOrder(4);
|
||||||
|
|
||||||
// audit
|
// Audit.
|
||||||
builder.Property(configuration => configuration.CreatedOnUtc)
|
builder.Property(configuration => configuration.CreatedOnUtc)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnOrder(5);
|
.HasColumnOrder(5);
|
||||||
@@ -52,6 +52,9 @@ public class LibraryArtworkProviderConfigurationConfiguration : IEntityTypeConfi
|
|||||||
.HasDefaultValue(null)
|
.HasDefaultValue(null)
|
||||||
.HasColumnOrder(8);
|
.HasColumnOrder(8);
|
||||||
|
|
||||||
builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId });
|
// A media library has at most one artwork provider configuration per plugin, so the pair is unique; the repository upserts on it, and
|
||||||
|
// the constraint guarantees that two concurrent upserts cannot insert duplicate rows.
|
||||||
|
builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId })
|
||||||
|
.IsUnique();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-3
@@ -20,7 +20,7 @@ public class LibraryMetadataProviderConfigurationConfiguration : IEntityTypeConf
|
|||||||
builder.ToTable("LibraryMetadataProviderConfigurations");
|
builder.ToTable("LibraryMetadataProviderConfigurations");
|
||||||
builder.HasKey(configuration => configuration.Id);
|
builder.HasKey(configuration => configuration.Id);
|
||||||
builder.Property(configuration => configuration.Id)
|
builder.Property(configuration => configuration.Id)
|
||||||
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
|
.ValueGeneratedNever() // Because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it.
|
||||||
.HasColumnOrder(0);
|
.HasColumnOrder(0);
|
||||||
builder.Property(configuration => configuration.LibraryId)
|
builder.Property(configuration => configuration.LibraryId)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
@@ -35,7 +35,7 @@ public class LibraryMetadataProviderConfigurationConfiguration : IEntityTypeConf
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnOrder(4);
|
.HasColumnOrder(4);
|
||||||
|
|
||||||
// audit
|
// Audit.
|
||||||
builder.Property(configuration => configuration.CreatedOnUtc)
|
builder.Property(configuration => configuration.CreatedOnUtc)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnOrder(5);
|
.HasColumnOrder(5);
|
||||||
@@ -52,6 +52,9 @@ public class LibraryMetadataProviderConfigurationConfiguration : IEntityTypeConf
|
|||||||
.HasDefaultValue(null)
|
.HasDefaultValue(null)
|
||||||
.HasColumnOrder(8);
|
.HasColumnOrder(8);
|
||||||
|
|
||||||
builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId });
|
// A media library has at most one metadata provider configuration per plugin, so the pair is unique; the repository upserts on it, and
|
||||||
|
// the constraint guarantees that two concurrent upserts cannot insert duplicate rows.
|
||||||
|
builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId })
|
||||||
|
.IsUnique();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3904
File diff suppressed because it is too large.
Load diff
+72
@@ -0,0 +1,72 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Lumina.DataAccess.Common.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class MakesProviderConfigurationsUniquePerLibraryAndPlugin : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
// The upserts read before they add, so two concurrent ones could store the same plugin twice for a library; the duplicates are removed before the
|
||||||
|
// indexes become unique, keeping the configuration that is tried first, so the unique indexes can be created on an existing database.
|
||||||
|
migrationBuilder.Sql("""
|
||||||
|
DELETE FROM LibraryMetadataProviderConfigurations WHERE rowid NOT IN (
|
||||||
|
SELECT rowid FROM (
|
||||||
|
SELECT rowid, ROW_NUMBER() OVER (PARTITION BY LibraryId, PluginId ORDER BY Rank, rowid) AS RowNumber
|
||||||
|
FROM LibraryMetadataProviderConfigurations)
|
||||||
|
WHERE RowNumber = 1);
|
||||||
|
|
||||||
|
DELETE FROM LibraryArtworkProviderConfigurations WHERE rowid NOT IN (
|
||||||
|
SELECT rowid FROM (
|
||||||
|
SELECT rowid, ROW_NUMBER() OVER (PARTITION BY LibraryId, PluginId ORDER BY Rank, rowid) AS RowNumber
|
||||||
|
FROM LibraryArtworkProviderConfigurations)
|
||||||
|
WHERE RowNumber = 1);
|
||||||
|
""");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_LibraryMetadataProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryMetadataProviderConfigurations");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_LibraryArtworkProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryArtworkProviderConfigurations");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_LibraryMetadataProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryMetadataProviderConfigurations",
|
||||||
|
columns: new[] { "LibraryId", "PluginId" },
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_LibraryArtworkProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryArtworkProviderConfigurations",
|
||||||
|
columns: new[] { "LibraryId", "PluginId" },
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_LibraryMetadataProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryMetadataProviderConfigurations");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_LibraryArtworkProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryArtworkProviderConfigurations");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_LibraryMetadataProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryMetadataProviderConfigurations",
|
||||||
|
columns: new[] { "LibraryId", "PluginId" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_LibraryArtworkProviderConfigurations_LibraryId_PluginId",
|
||||||
|
table: "LibraryArtworkProviderConfigurations",
|
||||||
|
columns: new[] { "LibraryId", "PluginId" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2223,7 +2223,8 @@ namespace Lumina.DataAccess.Common.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("LibraryId", "PluginId");
|
b.HasIndex("LibraryId", "PluginId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("LibraryArtworkProviderConfigurations", (string)null);
|
b.ToTable("LibraryArtworkProviderConfigurations", (string)null);
|
||||||
});
|
});
|
||||||
@@ -2310,7 +2311,8 @@ namespace Lumina.DataAccess.Common.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("LibraryId", "PluginId");
|
b.HasIndex("LibraryId", "PluginId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("LibraryMetadataProviderConfigurations", (string)null);
|
b.ToTable("LibraryMetadataProviderConfigurations", (string)null);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ public static partial class Errors
|
|||||||
public static Error PluginIdCannotBeEmpty => Error.Validation(description: nameof(PluginIdCannotBeEmpty));
|
public static Error PluginIdCannotBeEmpty => Error.Validation(description: nameof(PluginIdCannotBeEmpty));
|
||||||
public static Error PluginSettingsCannotBeNull => Error.Validation(description: nameof(PluginSettingsCannotBeNull));
|
public static Error PluginSettingsCannotBeNull => Error.Validation(description: nameof(PluginSettingsCannotBeNull));
|
||||||
public static Error LibraryIdCannotBeEmpty => Error.Validation(description: nameof(LibraryIdCannotBeEmpty));
|
public static Error LibraryIdCannotBeEmpty => Error.Validation(description: nameof(LibraryIdCannotBeEmpty));
|
||||||
public static Error PluginIdsListCannotBeNull => Error.Validation(description: nameof(PluginIdsListCannotBeNull));
|
public static Error PluginIdsMustBeUnique => Error.Validation(description: nameof(PluginIdsMustBeUnique));
|
||||||
public static Error PluginIdsListCannotBeEmpty => Error.Validation(description: nameof(PluginIdsListCannotBeEmpty));
|
public static Error PluginNotSupportedForLibraryType => Error.Validation(description: nameof(PluginNotSupportedForLibraryType));
|
||||||
public static Error LibraryMetadataProviderConfigurationNotFound => Error.NotFound(description: nameof(LibraryMetadataProviderConfigurationNotFound));
|
public static Error LibraryMetadataProviderConfigurationNotFound => Error.NotFound(description: nameof(LibraryMetadataProviderConfigurationNotFound));
|
||||||
public static Error PluginArchiveCannotBeNull => Error.Validation(description: nameof(PluginArchiveCannotBeNull));
|
public static Error PluginArchiveCannotBeNull => Error.Validation(description: nameof(PluginArchiveCannotBeNull));
|
||||||
public static Error PluginFileNameCannotBeEmpty => Error.Validation(description: nameof(PluginFileNameCannotBeEmpty));
|
public static Error PluginFileNameCannotBeEmpty => Error.Validation(description: nameof(PluginFileNameCannotBeEmpty));
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||||
using Lumina.Application.Common.DataAccess.UoW;
|
using Lumina.Application.Common.DataAccess.UoW;
|
||||||
|
using Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||||
using Lumina.Application.Common.Infrastructure.Reading;
|
using Lumina.Application.Common.Infrastructure.Reading;
|
||||||
|
using Lumina.Domain.Common.Errors;
|
||||||
using Lumina.Domain.Common.Primitives;
|
using Lumina.Domain.Common.Primitives;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
using Lumina.Plugins.Contracts.Core.Metadata;
|
using Lumina.Plugins.Contracts.Core.Metadata;
|
||||||
@@ -25,9 +27,10 @@ namespace Lumina.Infrastructure.Core.Plugins;
|
|||||||
/// The configurations decide, per media library, which loaded plugins may serve metadata or artwork, which book reader opens the
|
/// The configurations decide, per media library, which loaded plugins may serve metadata or artwork, which book reader opens the
|
||||||
/// books of the library, and whether each of them is currently enabled. They are persisted as rows instead of being derived from
|
/// books of the library, and whether each of them is currently enabled. They are persisted as rows instead of being derived from
|
||||||
/// the loaded plugins on the fly, because the user can enable or disable a provider per library, and because the set of loaded
|
/// the loaded plugins on the fly, because the user can enable or disable a provider per library, and because the set of loaded
|
||||||
/// plugins can change between restarts. This class is the single place that maintains them, and the only one that knows the
|
/// plugins can change between restarts. This class is the only one that writes them, while the queries, the scan enrichers and the
|
||||||
/// difference between "ensure" (only add what is missing) and "reconcile" (make the persisted configurations match the loaded
|
/// reading service read them through their repositories. It maintains them in three ways: "ensure" only adds what is missing,
|
||||||
/// plugins exactly).
|
/// "reconcile" makes the persisted configurations match the plugins supporting the library type, and "apply" reconciles them
|
||||||
|
/// and sets the enabled state and the order chosen when the library is added or updated.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProviderConfigurationStore
|
internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProviderConfigurationStore
|
||||||
{
|
{
|
||||||
@@ -63,8 +66,12 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a disabled provider configuration for every loaded plugin that supports the provided library type and has no configuration yet for the media library identified by <paramref name="libraryId"/>.
|
/// Adds a disabled metadata provider, artwork provider and book reader configuration for every loaded plugin that supports the provided library type and has no configuration yet
|
||||||
|
/// for the media library identified by <paramref name="libraryId"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The added configurations are only staged until the unit of work is saved, and are not visible to a later ensure, so it must be called at most once per media library before the changes are saved.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="libraryId">The Id of the media library whose provider configurations are ensured.</param>
|
/// <param name="libraryId">The Id of the media library whose provider configurations are ensured.</param>
|
||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
@@ -83,28 +90,6 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
return await EnsureBookReaderConfigurationsAsync(libraryId, libraryType, cancellationToken).ConfigureAwait(false);
|
return await EnsureBookReaderConfigurationsAsync(libraryId, libraryType, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Replaces the provider configurations of the media library identified by <paramref name="libraryId"/> so that they match the plugins supporting the provided library type.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="libraryId">The Id of the media library whose provider configurations are reconciled.</param>
|
|
||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
||||||
public async Task<Result<Success>> ReconcileProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
// "Reconcile" makes the persisted configurations match the loaded plugins exactly: configurations of plugins that no longer support
|
|
||||||
// the library type are removed, configurations for newly supported plugins are added, and the rest are kept. It is called when a
|
|
||||||
// plugin is uninstalled or when the type of a library changes.
|
|
||||||
(IReadOnlyList<Guid> metadataProviderPluginIds, IReadOnlyList<Guid> artworkProviderPluginIds) = GetSupportedProviderPluginIds(libraryType);
|
|
||||||
Result<Success> reconcileMetadataResult = await ReconcileMetadataConfigurationsAsync(libraryId, metadataProviderPluginIds, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (reconcileMetadataResult.IsFailure)
|
|
||||||
return reconcileMetadataResult;
|
|
||||||
Result<Success> reconcileArtworkResult = await ReconcileArtworkConfigurationsAsync(libraryId, artworkProviderPluginIds, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (reconcileArtworkResult.IsFailure)
|
|
||||||
return reconcileArtworkResult;
|
|
||||||
return await ReconcileBookReaderConfigurationsAsync(libraryId, libraryType, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes all the provider configurations of the media library identified by <paramref name="libraryId"/>.
|
/// Deletes all the provider configurations of the media library identified by <paramref name="libraryId"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -152,35 +137,63 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes all the book reader configurations of the media library identified by <paramref name="libraryId"/>.
|
/// Makes the provider and book reader configurations of the media library identified by <paramref name="libraryId"/> match the plugins supporting the provided library type,
|
||||||
|
/// and applies the choices made for them.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are deleted.</param>
|
/// <remarks>
|
||||||
|
/// A list that is provided reconciles that kind of configuration with the library type and applies the choices: the configurations of the plugins that do not support the library type
|
||||||
|
/// are removed, even when the list does not name them, every supported plugin gets a configuration, and the list sets the enabled state of every provider or reader it names and, for the
|
||||||
|
/// metadata and artwork providers, their order. A choice without an enabled state keeps the stored state, the supported plugins the list does not name keep their stored state and are
|
||||||
|
/// ordered after the named ones, and a plugin without a stored configuration starts disabled. A list that is <see langword="null"/> leaves that kind of configuration untouched, unless
|
||||||
|
/// <paramref name="shouldReconcileOmittedKinds"/> is <see langword="true"/>, in which case it is reconciled the same way, without choices. Whenever the book reader configurations are
|
||||||
|
/// reconciled or chosen, the cached reader enablements of the library are dropped.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="libraryId">The Id of the media library whose provider and book reader configurations are configured.</param>
|
||||||
|
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers and book readers apply.</param>
|
||||||
|
/// <param name="metadataProviders">The choices made for the metadata providers, in the order in which they are tried.</param>
|
||||||
|
/// <param name="artworkProviders">The choices made for the artwork providers, in the order in which they are tried.</param>
|
||||||
|
/// <param name="bookReaders">The choices made for the book readers.</param>
|
||||||
|
/// <param name="shouldReconcileOmittedKinds">Whether the kinds of configuration whose list of choices is <see langword="null"/> are reconciled with the library type, which is needed when the
|
||||||
|
/// library is new or its type changed.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error when a choice names a plugin that does not support the library type.</returns>
|
||||||
public async Task<Result<Deleted>> RemoveBookReaderConfigurationsForLibraryAsync(Guid libraryId, CancellationToken cancellationToken)
|
public async Task<Result<Success>> ConfigureProvidersAsync(
|
||||||
|
Guid libraryId,
|
||||||
|
LibraryType libraryType,
|
||||||
|
IReadOnlyList<LibraryProviderSelectionDto>? metadataProviders,
|
||||||
|
IReadOnlyList<LibraryProviderSelectionDto>? artworkProviders,
|
||||||
|
IReadOnlyList<LibraryProviderSelectionDto>? bookReaders,
|
||||||
|
bool shouldReconcileOmittedKinds,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Result<Deleted> removeResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.DeleteByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
// The configurations are computed in a single pass from the stored state, instead of reconciling first and applying the choices afterwards,
|
||||||
if (removeResult.IsFailure)
|
// because the configurations added by a reconcile are only staged until the unit of work is saved, and a second upsert of the same plugin would not find them and would add a duplicate.
|
||||||
return removeResult;
|
(IReadOnlyList<Guid> metadataProviderPluginIds, IReadOnlyList<Guid> artworkProviderPluginIds) = GetSupportedProviderPluginIds(libraryType);
|
||||||
// The reader enablements of the deleted library are no longer valid, so the reading service must not serve its books from the cache.
|
if (metadataProviders is not null || shouldReconcileOmittedKinds)
|
||||||
|
{
|
||||||
|
Result<Success> configureMetadataResult = metadataProviders is null
|
||||||
|
? await ReconcileMetadataConfigurationsAsync(libraryId, metadataProviderPluginIds, cancellationToken).ConfigureAwait(false)
|
||||||
|
: await ApplyMetadataProviderSelectionsAsync(libraryId, metadataProviderPluginIds, metadataProviders, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (configureMetadataResult.IsFailure)
|
||||||
|
return configureMetadataResult;
|
||||||
|
}
|
||||||
|
if (artworkProviders is not null || shouldReconcileOmittedKinds)
|
||||||
|
{
|
||||||
|
Result<Success> configureArtworkResult = artworkProviders is null
|
||||||
|
? await ReconcileArtworkConfigurationsAsync(libraryId, artworkProviderPluginIds, cancellationToken).ConfigureAwait(false)
|
||||||
|
: await ApplyArtworkProviderSelectionsAsync(libraryId, artworkProviderPluginIds, artworkProviders, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (configureArtworkResult.IsFailure)
|
||||||
|
return configureArtworkResult;
|
||||||
|
}
|
||||||
|
// Reconciling the book readers drops the cached enablements of the library by itself.
|
||||||
|
if (bookReaders is null)
|
||||||
|
return shouldReconcileOmittedKinds ? await ReconcileBookReaderConfigurationsAsync(libraryId, libraryType, cancellationToken).ConfigureAwait(false) : Result.Success;
|
||||||
|
Result<Success> configureBookReadersResult = await ApplyBookReaderSelectionsAsync(libraryId, GetSupportedBookReaderPluginIds(libraryType), bookReaders, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (configureBookReadersResult.IsFailure)
|
||||||
|
return configureBookReadersResult;
|
||||||
|
// The reading service caches the enablement of the readers, so the cached state of the library is dropped, and a reader that was disabled stops serving its books immediately.
|
||||||
_enablementCache.InvalidateLibrary(libraryId);
|
_enablementCache.InvalidateLibrary(libraryId);
|
||||||
return removeResult;
|
return Result.Success;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes all the book reader configurations referencing the plugin identified by <paramref name="pluginId"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pluginId">The Id of the plugin whose book reader configurations are deleted.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
||||||
public async Task<Result<Deleted>> RemoveBookReaderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
Result<Deleted> removeResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.DeleteByPluginIdAsync(pluginId, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (removeResult.IsFailure)
|
|
||||||
return removeResult;
|
|
||||||
// The reader enablements of the removed plugin are no longer valid, so the reading service must not serve its books from the cache.
|
|
||||||
_enablementCache.InvalidatePlugin(pluginId);
|
|
||||||
return removeResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -205,12 +218,32 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
return (metadataProviderPluginIds, artworkProviderPluginIds);
|
return (metadataProviderPluginIds, artworkProviderPluginIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Ids of the loaded plugins that provide metadata for the provided library type, ordered alphabetically by plugin name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryType">The type of the media library the metadata providers must support.</param>
|
||||||
|
/// <returns>The Ids of the plugins providing metadata for the library type.</returns>
|
||||||
|
public IReadOnlyList<Guid> GetSupportedMetadataProviderPluginIds(LibraryType libraryType)
|
||||||
|
{
|
||||||
|
return GetSupportedProviderPluginIds(libraryType).metadataProviderPluginIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Ids of the loaded plugins that provide artwork for the provided library type, ordered alphabetically by plugin name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryType">The type of the media library the artwork providers must support.</param>
|
||||||
|
/// <returns>The Ids of the plugins providing artwork for the library type.</returns>
|
||||||
|
public IReadOnlyList<Guid> GetSupportedArtworkProviderPluginIds(LibraryType libraryType)
|
||||||
|
{
|
||||||
|
return GetSupportedProviderPluginIds(libraryType).artworkProviderPluginIds;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Ids of the loaded plugins that provide a book reader for the provided library type, ordered alphabetically by plugin name so that the assigned order is stable.
|
/// Gets the Ids of the loaded plugins that provide a book reader for the provided library type, ordered alphabetically by plugin name so that the assigned order is stable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="libraryType">The type of the media library the book readers must support.</param>
|
/// <param name="libraryType">The type of the media library the book readers must support.</param>
|
||||||
/// <returns>The Ids of the plugins providing a book reader for the library type.</returns>
|
/// <returns>The Ids of the plugins providing a book reader for the library type.</returns>
|
||||||
private IReadOnlyList<Guid> GetSupportedBookReaderPluginIds(LibraryType libraryType)
|
public IReadOnlyList<Guid> GetSupportedBookReaderPluginIds(LibraryType libraryType)
|
||||||
{
|
{
|
||||||
// Book readers have no rank: a book is opened by exactly one reader matched by its file extension, not by priority, so the alphabetical order is only used to keep the display order stable.
|
// Book readers have no rank: a book is opened by exactly one reader matched by its file extension, not by priority, so the alphabetical order is only used to keep the display order stable.
|
||||||
List<Guid> bookReaderPluginIds = [];
|
List<Guid> bookReaderPluginIds = [];
|
||||||
@@ -224,11 +257,14 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces the book reader configurations of the media library identified by <paramref name="libraryId"/> so that they match the plugins supporting the provided library type.
|
/// Replaces the book reader configurations of the media library identified by <paramref name="libraryId"/> so that they match the plugins supporting the provided library type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The cached reader enablements of the library are dropped, so a reader whose configuration was removed stops serving its books immediately.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="libraryId">The Id of the media library whose book reader configurations are reconciled.</param>
|
/// <param name="libraryId">The Id of the media library whose book reader configurations are reconciled.</param>
|
||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
public async Task<Result<Success>> ReconcileBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken)
|
private async Task<Result<Success>> ReconcileBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// First, the configurations of readers that no longer apply are deleted, then a disabled configuration is added for every reader
|
// First, the configurations of readers that no longer apply are deleted, then a disabled configuration is added for every reader
|
||||||
// that applies, but is not configured yet; the configurations of readers that still apply are kept untouched.
|
// that applies, but is not configured yet; the configurations of readers that still apply are kept untouched.
|
||||||
@@ -267,6 +303,8 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
if (upsertResult.IsFailure)
|
if (upsertResult.IsFailure)
|
||||||
return Result<Success>.Failure(upsertResult.Errors);
|
return Result<Success>.Failure(upsertResult.Errors);
|
||||||
}
|
}
|
||||||
|
// The reading service caches the enablement of the readers, so the cached state of the library is dropped, and a reader whose configuration was removed stops serving its books immediately.
|
||||||
|
_enablementCache.InvalidateLibrary(libraryId);
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +315,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
public async Task<Result<Success>> EnsureBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken)
|
private async Task<Result<Success>> EnsureBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// Unlike reconcile, ensure never deletes: it only adds a disabled configuration for the readers that are not configured yet.
|
// Unlike reconcile, ensure never deletes: it only adds a disabled configuration for the readers that are not configured yet.
|
||||||
IReadOnlyList<Guid> bookReaderPluginIds = GetSupportedBookReaderPluginIds(libraryType);
|
IReadOnlyList<Guid> bookReaderPluginIds = GetSupportedBookReaderPluginIds(libraryType);
|
||||||
@@ -499,4 +537,193 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
}
|
}
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the metadata provider configurations of the media library match the plugins supporting its type, and applies the provided choices.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryId">The Id of the media library whose metadata provider configurations are configured.</param>
|
||||||
|
/// <param name="metadataProviderPluginIds">The Ids of the plugins providing metadata for the library type, in alphabetical order.</param>
|
||||||
|
/// <param name="selections">The choices made for the metadata providers, in the order in which they are tried.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
|
private async Task<Result<Success>> ApplyMetadataProviderSelectionsAsync(Guid libraryId, IReadOnlyList<Guid> metadataProviderPluginIds, IReadOnlyList<LibraryProviderSelectionDto> selections, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
// The command validation rejects duplicated choices already, and they are reported here too, so that a direct caller gets an error instead of an exception.
|
||||||
|
if (selections.Select(selection => selection.PluginId).Distinct().Count() != selections.Count)
|
||||||
|
return Errors.Plugins.PluginIdsMustBeUnique;
|
||||||
|
if (selections.Any(selection => !metadataProviderPluginIds.Contains(selection.PluginId)))
|
||||||
|
return Errors.Plugins.PluginNotSupportedForLibraryType;
|
||||||
|
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (getConfigurationsResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(getConfigurationsResult.Errors);
|
||||||
|
List<Guid> stalePluginIds = [.. getConfigurationsResult.Value
|
||||||
|
.Select(configuration => configuration.PluginId)
|
||||||
|
.Where(pluginId => !metadataProviderPluginIds.Contains(pluginId))];
|
||||||
|
if (stalePluginIds.Count > 0)
|
||||||
|
{
|
||||||
|
Result<Deleted> removeResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, stalePluginIds, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (removeResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(removeResult.Errors);
|
||||||
|
}
|
||||||
|
Dictionary<Guid, LibraryMetadataProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value
|
||||||
|
.Where(configuration => metadataProviderPluginIds.Contains(configuration.PluginId))
|
||||||
|
.ToDictionary(configuration => configuration.PluginId);
|
||||||
|
IReadOnlyList<Guid> orderedPluginIds = GetProviderOrder(selections, configurationsByPluginId.Values.OrderBy(configuration => configuration.Rank).Select(configuration => configuration.PluginId), metadataProviderPluginIds);
|
||||||
|
Dictionary<Guid, bool?> enabledStatesByPluginId = selections.ToDictionary(selection => selection.PluginId, selection => selection.IsEnabled);
|
||||||
|
for (int index = 0; index < orderedPluginIds.Count; index++)
|
||||||
|
{
|
||||||
|
Guid pluginId = orderedPluginIds[index];
|
||||||
|
configurationsByPluginId.TryGetValue(pluginId, out LibraryMetadataProviderConfigurationEntity? storedConfiguration);
|
||||||
|
// A provider that is not named, or is named without an enabled state, keeps its stored state, and a provider that has no configuration yet starts disabled, so it never silently starts enriching the library.
|
||||||
|
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
||||||
|
LibraryMetadataProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryMetadataProviderConfigurationEntity
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
LibraryId = libraryId,
|
||||||
|
PluginId = pluginId,
|
||||||
|
IsEnabled = isEnabled,
|
||||||
|
Rank = index + 1,
|
||||||
|
CreatedOnUtc = default,
|
||||||
|
CreatedBy = default,
|
||||||
|
UpdatedBy = default
|
||||||
|
};
|
||||||
|
configuration.IsEnabled = isEnabled;
|
||||||
|
configuration.Rank = index + 1;
|
||||||
|
Result<Updated> upsertResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (upsertResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(upsertResult.Errors);
|
||||||
|
}
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the artwork provider configurations of the media library match the plugins supporting its type, and applies the provided choices.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryId">The Id of the media library whose artwork provider configurations are configured.</param>
|
||||||
|
/// <param name="artworkProviderPluginIds">The Ids of the plugins providing artwork for the library type, in alphabetical order.</param>
|
||||||
|
/// <param name="selections">The choices made for the artwork providers, in the order in which they are tried.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
|
private async Task<Result<Success>> ApplyArtworkProviderSelectionsAsync(Guid libraryId, IReadOnlyList<Guid> artworkProviderPluginIds, IReadOnlyList<LibraryProviderSelectionDto> selections, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
// The command validation rejects duplicated choices already, and they are reported here too, so that a direct caller gets an error instead of an exception.
|
||||||
|
if (selections.Select(selection => selection.PluginId).Distinct().Count() != selections.Count)
|
||||||
|
return Errors.Plugins.PluginIdsMustBeUnique;
|
||||||
|
if (selections.Any(selection => !artworkProviderPluginIds.Contains(selection.PluginId)))
|
||||||
|
return Errors.Plugins.PluginNotSupportedForLibraryType;
|
||||||
|
Result<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.ArtworkProviderConfigurationRepository.GetByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (getConfigurationsResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(getConfigurationsResult.Errors);
|
||||||
|
List<Guid> stalePluginIds = [.. getConfigurationsResult.Value
|
||||||
|
.Select(configuration => configuration.PluginId)
|
||||||
|
.Where(pluginId => !artworkProviderPluginIds.Contains(pluginId))];
|
||||||
|
if (stalePluginIds.Count > 0)
|
||||||
|
{
|
||||||
|
Result<Deleted> removeResult = await _unitOfWork.ArtworkProviderConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, stalePluginIds, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (removeResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(removeResult.Errors);
|
||||||
|
}
|
||||||
|
Dictionary<Guid, LibraryArtworkProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value
|
||||||
|
.Where(configuration => artworkProviderPluginIds.Contains(configuration.PluginId))
|
||||||
|
.ToDictionary(configuration => configuration.PluginId);
|
||||||
|
IReadOnlyList<Guid> orderedPluginIds = GetProviderOrder(selections, configurationsByPluginId.Values.OrderBy(configuration => configuration.Rank).Select(configuration => configuration.PluginId), artworkProviderPluginIds);
|
||||||
|
Dictionary<Guid, bool?> enabledStatesByPluginId = selections.ToDictionary(selection => selection.PluginId, selection => selection.IsEnabled);
|
||||||
|
for (int index = 0; index < orderedPluginIds.Count; index++)
|
||||||
|
{
|
||||||
|
Guid pluginId = orderedPluginIds[index];
|
||||||
|
configurationsByPluginId.TryGetValue(pluginId, out LibraryArtworkProviderConfigurationEntity? storedConfiguration);
|
||||||
|
// A provider that is not named, or is named without an enabled state, keeps its stored state, and a provider that has no configuration yet starts disabled, so it never silently starts enriching the library.
|
||||||
|
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
||||||
|
LibraryArtworkProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryArtworkProviderConfigurationEntity
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
LibraryId = libraryId,
|
||||||
|
PluginId = pluginId,
|
||||||
|
IsEnabled = isEnabled,
|
||||||
|
Rank = index + 1,
|
||||||
|
CreatedOnUtc = default,
|
||||||
|
CreatedBy = default,
|
||||||
|
UpdatedBy = default
|
||||||
|
};
|
||||||
|
configuration.IsEnabled = isEnabled;
|
||||||
|
configuration.Rank = index + 1;
|
||||||
|
Result<Updated> upsertResult = await _unitOfWork.ArtworkProviderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (upsertResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(upsertResult.Errors);
|
||||||
|
}
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the book reader configurations of the media library match the plugins supporting its type, and applies the provided choices.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryId">The Id of the media library whose book reader configurations are configured.</param>
|
||||||
|
/// <param name="bookReaderPluginIds">The Ids of the plugins providing a book reader for the library type.</param>
|
||||||
|
/// <param name="selections">The choices made for the book readers.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
|
private async Task<Result<Success>> ApplyBookReaderSelectionsAsync(Guid libraryId, IReadOnlyList<Guid> bookReaderPluginIds, IReadOnlyList<LibraryProviderSelectionDto> selections, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
// The command validation rejects duplicated choices already, and they are reported here too, so that a direct caller gets an error instead of an exception.
|
||||||
|
if (selections.Select(selection => selection.PluginId).Distinct().Count() != selections.Count)
|
||||||
|
return Errors.Plugins.PluginIdsMustBeUnique;
|
||||||
|
if (selections.Any(selection => !bookReaderPluginIds.Contains(selection.PluginId)))
|
||||||
|
return Errors.Plugins.PluginNotSupportedForLibraryType;
|
||||||
|
Result<IReadOnlyList<LibraryBookReaderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.GetByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (getConfigurationsResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(getConfigurationsResult.Errors);
|
||||||
|
List<Guid> stalePluginIds = [.. getConfigurationsResult.Value
|
||||||
|
.Select(configuration => configuration.PluginId)
|
||||||
|
.Where(pluginId => !bookReaderPluginIds.Contains(pluginId))];
|
||||||
|
if (stalePluginIds.Count > 0)
|
||||||
|
{
|
||||||
|
Result<Deleted> removeResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.DeleteByLibraryIdAndPluginIdsAsync(libraryId, stalePluginIds, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (removeResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(removeResult.Errors);
|
||||||
|
}
|
||||||
|
Dictionary<Guid, LibraryBookReaderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value
|
||||||
|
.Where(configuration => bookReaderPluginIds.Contains(configuration.PluginId))
|
||||||
|
.ToDictionary(configuration => configuration.PluginId);
|
||||||
|
Dictionary<Guid, bool?> enabledStatesByPluginId = selections.ToDictionary(selection => selection.PluginId, selection => selection.IsEnabled);
|
||||||
|
// Book readers have no rank, since a book is opened by the reader matched by its file extension, so only their enabled state is applied.
|
||||||
|
foreach (Guid pluginId in bookReaderPluginIds)
|
||||||
|
{
|
||||||
|
configurationsByPluginId.TryGetValue(pluginId, out LibraryBookReaderConfigurationEntity? storedConfiguration);
|
||||||
|
// A reader that is not named, or is named without an enabled state, keeps its stored state, and a reader that has no configuration yet starts disabled, so it never silently takes over reading the books of the library.
|
||||||
|
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
||||||
|
LibraryBookReaderConfigurationEntity configuration = storedConfiguration ?? new LibraryBookReaderConfigurationEntity
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
LibraryId = libraryId,
|
||||||
|
PluginId = pluginId,
|
||||||
|
IsEnabled = isEnabled,
|
||||||
|
CreatedOnUtc = default,
|
||||||
|
CreatedBy = default,
|
||||||
|
UpdatedBy = default
|
||||||
|
};
|
||||||
|
configuration.IsEnabled = isEnabled;
|
||||||
|
Result<Updated> upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (upsertResult.IsFailure)
|
||||||
|
return Result<Success>.Failure(upsertResult.Errors);
|
||||||
|
}
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the order in which the supported providers of a media library are tried: the named providers in the order of the choices, then the providers that are already configured,
|
||||||
|
/// in their stored order, then the providers that are not configured yet, in alphabetical order.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="selections">The choices made for the providers, in the order in which they are tried.</param>
|
||||||
|
/// <param name="configuredPluginIds">The Ids of the plugins whose providers are already configured and still supported, in their stored order.</param>
|
||||||
|
/// <param name="supportedPluginIds">The Ids of the plugins providing for the library type, in alphabetical order.</param>
|
||||||
|
/// <returns>The Ids of the plugins, in the order in which their providers are tried.</returns>
|
||||||
|
private static IReadOnlyList<Guid> GetProviderOrder(IReadOnlyList<LibraryProviderSelectionDto> selections, IEnumerable<Guid> configuredPluginIds, IReadOnlyList<Guid> supportedPluginIds)
|
||||||
|
{
|
||||||
|
List<Guid> orderedPluginIds = [.. selections.Select(selection => selection.PluginId)];
|
||||||
|
HashSet<Guid> orderedPluginIdSet = [.. orderedPluginIds];
|
||||||
|
foreach (Guid pluginId in configuredPluginIds.Concat(supportedPluginIds))
|
||||||
|
if (orderedPluginIdSet.Add(pluginId))
|
||||||
|
orderedPluginIds.Add(pluginId);
|
||||||
|
return orderedPluginIds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,9 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seed the provider configurations of the media libraries, so that every library lists the plugins providing metadata or artwork for its type.
|
// Seed the provider configurations of the media libraries, so that every library lists the plugins providing metadata, artwork or a book reader for its type.
|
||||||
|
// A single ensure covers all three kinds, because the configurations it adds are only staged until the unit of work is saved, and a second ensure in the
|
||||||
|
// same scope would not find them and would add duplicates that break the unique index on save.
|
||||||
Result<PaginatedResultDto<LibraryEntity>> getLibrariesResult = await unitOfWork.LibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: stoppingToken).ConfigureAwait(false);
|
Result<PaginatedResultDto<LibraryEntity>> getLibrariesResult = await unitOfWork.LibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: stoppingToken).ConfigureAwait(false);
|
||||||
if (getLibrariesResult.IsFailure)
|
if (getLibrariesResult.IsFailure)
|
||||||
_logger.LogError("Failed to get the media libraries while seeding the provider configurations.");
|
_logger.LogError("Failed to get the media libraries while seeding the provider configurations.");
|
||||||
@@ -140,9 +142,6 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
|||||||
Result<Success> ensureResult = await providerConfigurationStore.EnsureProviderConfigurationsAsync(library.Id, library.LibraryType, stoppingToken).ConfigureAwait(false);
|
Result<Success> ensureResult = await providerConfigurationStore.EnsureProviderConfigurationsAsync(library.Id, library.LibraryType, stoppingToken).ConfigureAwait(false);
|
||||||
if (ensureResult.IsFailure)
|
if (ensureResult.IsFailure)
|
||||||
_logger.LogError("Failed to seed the provider configurations of the media library '{LibraryTitle}': {Error}", library.Title, ensureResult.FirstError.Description);
|
_logger.LogError("Failed to seed the provider configurations of the media library '{LibraryTitle}': {Error}", library.Title, ensureResult.FirstError.Description);
|
||||||
Result<Success> ensureBookReadersResult = await providerConfigurationStore.EnsureBookReaderConfigurationsAsync(library.Id, library.LibraryType, stoppingToken).ConfigureAwait(false);
|
|
||||||
if (ensureBookReadersResult.IsFailure)
|
|
||||||
_logger.LogError("Failed to seed the book reader configurations of the media library '{LibraryTitle}': {Error}", library.Title, ensureBookReadersResult.FirstError.Description);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,11 @@ public static partial class ApiRoutes
|
|||||||
public const string CANCEL_LIBRARIES_SCAN = "/libraries/scans/cancel";
|
public const string CANCEL_LIBRARIES_SCAN = "/libraries/scans/cancel";
|
||||||
public const string CANCEL_LIBRARY_SCAN = "/libraries/{libraryId}/scans/{scanId}/cancel";
|
public const string CANCEL_LIBRARY_SCAN = "/libraries/{libraryId}/scans/{scanId}/cancel";
|
||||||
public const string GET_LIBRARY_METADATA_PROVIDERS = "/libraries/{libraryId}/metadata-providers";
|
public const string GET_LIBRARY_METADATA_PROVIDERS = "/libraries/{libraryId}/metadata-providers";
|
||||||
public const string SET_LIBRARY_METADATA_PROVIDER_ENABLED = "/libraries/{libraryId}/metadata-providers/{pluginId}/enabled";
|
|
||||||
public const string REORDER_LIBRARY_METADATA_PROVIDERS = "/libraries/{libraryId}/metadata-providers/reorder";
|
|
||||||
public const string GET_LIBRARY_ARTWORK_PROVIDERS = "/libraries/{libraryId}/artwork-providers";
|
public const string GET_LIBRARY_ARTWORK_PROVIDERS = "/libraries/{libraryId}/artwork-providers";
|
||||||
public const string SET_LIBRARY_ARTWORK_PROVIDER_ENABLED = "/libraries/{libraryId}/artwork-providers/{pluginId}/enabled";
|
|
||||||
public const string REORDER_LIBRARY_ARTWORK_PROVIDERS = "/libraries/{libraryId}/artwork-providers/reorder";
|
|
||||||
public const string GET_LIBRARY_PATH_TEMPLATE_PARTS = "/libraries/path-template-parts/{libraryType}";
|
public const string GET_LIBRARY_PATH_TEMPLATE_PARTS = "/libraries/path-template-parts/{libraryType}";
|
||||||
public const string GET_LIBRARY_BOOK_READERS = "/libraries/{libraryId}/book-readers";
|
public const string GET_LIBRARY_BOOK_READERS = "/libraries/{libraryId}/book-readers";
|
||||||
public const string SET_LIBRARY_BOOK_READER_ENABLED = "/libraries/{libraryId}/book-readers/{pluginId}/enabled";
|
public const string GET_LIBRARY_TYPE_METADATA_PROVIDERS = "/libraries/metadata-providers/{libraryType}";
|
||||||
|
public const string GET_LIBRARY_TYPE_ARTWORK_PROVIDERS = "/libraries/artwork-providers/{libraryType}";
|
||||||
|
public const string GET_LIBRARY_TYPE_BOOK_READERS = "/libraries/book-readers/{libraryType}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+11
-2
@@ -40,7 +40,10 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
|||||||
IsContentOnSsd: false,
|
IsContentOnSsd: false,
|
||||||
ShouldTrackConsumptionProgress: true,
|
ShouldTrackConsumptionProgress: true,
|
||||||
CompletionThresholdPercentage: 90,
|
CompletionThresholdPercentage: 90,
|
||||||
PathTemplateParts: null
|
PathTemplateParts: null,
|
||||||
|
MetadataProviders: [new LibraryProviderSelectionRequest(PluginId: Guid.NewGuid(), IsEnabled: true)],
|
||||||
|
ArtworkProviders: [new LibraryProviderSelectionRequest(PluginId: Guid.NewGuid(), IsEnabled: true)],
|
||||||
|
BookReaders: null
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestParam(r => r.Title, "The title of the media library. Required.");
|
RequestParam(r => r.Title, "The title of the media library. Required.");
|
||||||
@@ -56,6 +59,9 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
|||||||
RequestParam(r => r.ShouldTrackConsumptionProgress, "Whether the consumption progress of the media library items should be tracked, or not. Optional, the default of the library type is used when absent.");
|
RequestParam(r => r.ShouldTrackConsumptionProgress, "Whether the consumption progress of the media library items should be tracked, or not. Optional, the default of the library type is used when absent.");
|
||||||
RequestParam(r => r.CompletionThresholdPercentage, "The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the default of the library type is used when absent.");
|
RequestParam(r => r.CompletionThresholdPercentage, "The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the default of the library type is used when absent.");
|
||||||
RequestParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.");
|
RequestParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.");
|
||||||
|
RequestParam(r => r.MetadataProviders, "The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, every provider supported by the library type is added disabled when absent.");
|
||||||
|
RequestParam(r => r.ArtworkProviders, "The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, every provider supported by the library type is added disabled when absent.");
|
||||||
|
RequestParam(r => r.BookReaders, "The book readers of the media library, and whether each one is enabled. Optional, every reader supported by the library type is added disabled when absent.");
|
||||||
|
|
||||||
ResponseParam<LibraryResponse>(r => r.Id, "The unique identifier of the entity.");
|
ResponseParam<LibraryResponse>(r => r.Id, "The unique identifier of the entity.");
|
||||||
ResponseParam<LibraryResponse>(r => r.UserId, "The unique identifier of the user owning the media library.");
|
ResponseParam<LibraryResponse>(r => r.UserId, "The unique identifier of the user owning the media library.");
|
||||||
@@ -172,7 +178,10 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
|||||||
"TitleMustBeMaximum255CharactersLong",
|
"TitleMustBeMaximum255CharactersLong",
|
||||||
"CompletionThresholdPercentageMustBeNullWhenProgressTrackingIsOff",
|
"CompletionThresholdPercentageMustBeNullWhenProgressTrackingIsOff",
|
||||||
"CompletionThresholdPercentageMustBeBetweenZeroAndOneHundred",
|
"CompletionThresholdPercentageMustBeBetweenZeroAndOneHundred",
|
||||||
"CoverFileMustBeAnImage"
|
"CoverFileMustBeAnImage",
|
||||||
|
"PluginIdCannotBeEmpty",
|
||||||
|
"PluginIdsMustBeUnique",
|
||||||
|
"PluginNotSupportedForLibraryType"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ public class DeleteLibraryEndpointSummary : Summary<DeleteLibraryEndpoint, Delet
|
|||||||
public DeleteLibraryEndpointSummary()
|
public DeleteLibraryEndpointSummary()
|
||||||
{
|
{
|
||||||
Summary = "Deletes an existing media library.";
|
Summary = "Deletes an existing media library.";
|
||||||
Description = "Deletes a media library, if the user making the request is an Admin, or the owner of the library.";
|
Description = "Deletes a media library, if the user making the request is an Admin, or the owner of the library holding the permission to create libraries.";
|
||||||
|
|
||||||
ExampleRequest = new DeleteLibraryRequest(
|
ExampleRequest = new DeleteLibraryRequest(
|
||||||
Id: Guid.NewGuid()
|
Id: Guid.NewGuid()
|
||||||
@@ -62,7 +62,7 @@ public class DeleteLibraryEndpointSummary : Summary<DeleteLibraryEndpoint, Delet
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
Response(403, "The request failed because the user making the request is neither an Admin, nor the owner of the media library holding the permission to create libraries.", "application/problem+json",
|
||||||
example: new
|
example: new
|
||||||
{
|
{
|
||||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||||
|
|||||||
+13
-7
@@ -22,11 +22,10 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
|
|||||||
public UpdateLibraryEndpointSummary()
|
public UpdateLibraryEndpointSummary()
|
||||||
{
|
{
|
||||||
Summary = "Updates an existing media library.";
|
Summary = "Updates an existing media library.";
|
||||||
Description = "Updates a media library and returns its details, if the user making the request is an Admin, or the owner of the library.";
|
Description = "Updates a media library and returns its details, if the user making the request is an Admin, or the owner of the library holding the permission to create libraries. The owner of the library is never changed by an update.";
|
||||||
|
|
||||||
ExampleRequest = new UpdateLibraryRequest(
|
ExampleRequest = new UpdateLibraryRequest(
|
||||||
Id: Guid.NewGuid(),
|
Id: Guid.NewGuid(),
|
||||||
UserId: Guid.NewGuid(),
|
|
||||||
Title: "TV Shows",
|
Title: "TV Shows",
|
||||||
LibraryType: "TvShow",
|
LibraryType: "TvShow",
|
||||||
ContentLocations: [
|
ContentLocations: [
|
||||||
@@ -42,11 +41,13 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
|
|||||||
IsContentOnSsd: false,
|
IsContentOnSsd: false,
|
||||||
ShouldTrackConsumptionProgress: true,
|
ShouldTrackConsumptionProgress: true,
|
||||||
CompletionThresholdPercentage: 90,
|
CompletionThresholdPercentage: 90,
|
||||||
PathTemplateParts: null
|
PathTemplateParts: null,
|
||||||
|
MetadataProviders: [new LibraryProviderSelectionRequest(PluginId: Guid.NewGuid(), IsEnabled: true)],
|
||||||
|
ArtworkProviders: [new LibraryProviderSelectionRequest(PluginId: Guid.NewGuid(), IsEnabled: true)],
|
||||||
|
BookReaders: null
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestParam(r => r.Id, "The unique identifier of the media library. Required.");
|
RequestParam(r => r.Id, "The unique identifier of the media library. Required.");
|
||||||
RequestParam(r => r.UserId, "The unique identifier of the user owning the media library. Required.");
|
|
||||||
RequestParam(r => r.Title, "The title of the media library. Required.");
|
RequestParam(r => r.Title, "The title of the media library. Required.");
|
||||||
RequestParam(r => r.LibraryType, "The type of the media library. Required.");
|
RequestParam(r => r.LibraryType, "The type of the media library. Required.");
|
||||||
RequestParam(r => r.ContentLocations, ">The file system paths of the directories where the media library elements are located. Required.");
|
RequestParam(r => r.ContentLocations, ">The file system paths of the directories where the media library elements are located. Required.");
|
||||||
@@ -60,6 +61,9 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
|
|||||||
RequestParam(r => r.ShouldTrackConsumptionProgress, "Whether the consumption progress of the media library items should be tracked, or not. Optional, the stored value is kept when absent.");
|
RequestParam(r => r.ShouldTrackConsumptionProgress, "Whether the consumption progress of the media library items should be tracked, or not. Optional, the stored value is kept when absent.");
|
||||||
RequestParam(r => r.CompletionThresholdPercentage, "The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the stored value is kept when absent.");
|
RequestParam(r => r.CompletionThresholdPercentage, "The percentage of a media library item that must be consumed for its session to be considered completed. Optional, the stored value is kept when absent.");
|
||||||
RequestParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.");
|
RequestParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent.");
|
||||||
|
RequestParam(r => r.MetadataProviders, "The metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes when absent.");
|
||||||
|
RequestParam(r => r.ArtworkProviders, "The artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes when absent.");
|
||||||
|
RequestParam(r => r.BookReaders, "The book readers of the media library, and whether each one is enabled. Optional, the stored configurations are kept, or reconciled with the library type when it changes when absent.");
|
||||||
|
|
||||||
ResponseParam<LibraryResponse>(r => r.Id, "The unique identifier of the entity.");
|
ResponseParam<LibraryResponse>(r => r.Id, "The unique identifier of the entity.");
|
||||||
ResponseParam<LibraryResponse>(r => r.UserId, "The unique identifier of the user owning the media library.");
|
ResponseParam<LibraryResponse>(r => r.UserId, "The unique identifier of the user owning the media library.");
|
||||||
@@ -130,7 +134,7 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Response(403, "The request failed because the authenticated user is not allowed to manage the media library, or because the request carried an unsupported library type.", "application/problem+json",
|
Response(403, "The request failed because the authenticated user is neither an Admin, nor the owner of the media library holding the permission to create libraries, or because the request carried an unsupported library type.", "application/problem+json",
|
||||||
example: new[]
|
example: new[]
|
||||||
{
|
{
|
||||||
new
|
new
|
||||||
@@ -180,7 +184,6 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
|
|||||||
"General.Validation", new[]
|
"General.Validation", new[]
|
||||||
{
|
{
|
||||||
"LibraryIdCannotBeEmpty",
|
"LibraryIdCannotBeEmpty",
|
||||||
"UserIdCannotBeEmpty",
|
|
||||||
"LibraryTypeCannotBeNull",
|
"LibraryTypeCannotBeNull",
|
||||||
"PathsListCannotBeNull",
|
"PathsListCannotBeNull",
|
||||||
"PathsListCannotBeEmpty",
|
"PathsListCannotBeEmpty",
|
||||||
@@ -189,7 +192,10 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
|
|||||||
"TitleCannotBeEmpty",
|
"TitleCannotBeEmpty",
|
||||||
"TitleMustBeMaximum255CharactersLong",
|
"TitleMustBeMaximum255CharactersLong",
|
||||||
"CompletionThresholdPercentageMustBeNullWhenProgressTrackingIsOff",
|
"CompletionThresholdPercentageMustBeNullWhenProgressTrackingIsOff",
|
||||||
"CompletionThresholdPercentageMustBeBetweenZeroAndOneHundred"
|
"CompletionThresholdPercentageMustBeBetweenZeroAndOneHundred",
|
||||||
|
"PluginIdCannotBeEmpty",
|
||||||
|
"PluginIdsMustBeUnique",
|
||||||
|
"PluginNotSupportedForLibraryType"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using FastEndpoints;
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
|
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using Lumina.Domain.Common.Primitives;
|
||||||
|
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
||||||
|
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryTypeArtworkProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API endpoint for the <c>/libraries/artwork-providers/{libraryType}</c> route.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeArtworkProvidersEndpoint : BaseEndpoint<GetLibraryTypeArtworkProvidersRequest, IResult>
|
||||||
|
{
|
||||||
|
private readonly IQueryHandler<GetLibraryTypeArtworkProvidersQuery, Result<IReadOnlyList<LibraryArtworkProviderResponse>>> _getLibraryTypeArtworkProvidersQueryHandler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeArtworkProvidersEndpoint"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="getLibraryTypeArtworkProvidersQueryHandler">Injected service for handling get library type artwork providers queries.</param>
|
||||||
|
public GetLibraryTypeArtworkProvidersEndpoint(IQueryHandler<GetLibraryTypeArtworkProvidersQuery, Result<IReadOnlyList<LibraryArtworkProviderResponse>>> getLibraryTypeArtworkProvidersQueryHandler)
|
||||||
|
{
|
||||||
|
_getLibraryTypeArtworkProvidersQueryHandler = getLibraryTypeArtworkProvidersQueryHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the API endpoint.
|
||||||
|
/// </summary>
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Verbs(Http.GET);
|
||||||
|
Routes(ApiRoutes.Libraries.GET_LIBRARY_TYPE_ARTWORK_PROVIDERS);
|
||||||
|
Version(1);
|
||||||
|
DontCatchExceptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the artwork providers available for the media library type provided in <paramref name="request"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The request containing the media library type whose available artwork providers are retrieved.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
public override async Task<IResult> ExecuteAsync(GetLibraryTypeArtworkProvidersRequest request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Result<IReadOnlyList<LibraryArtworkProviderResponse>> result = await _getLibraryTypeArtworkProvidersQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||||
|
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||||
|
}
|
||||||
|
}
|
||||||
+118
@@ -0,0 +1,118 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using FastEndpoints;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryTypeArtworkProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class used for providing a textual description for the <see cref="GetLibraryTypeArtworkProvidersEndpoint"/> API endpoint, for OpenAPI.
|
||||||
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public class GetLibraryTypeArtworkProvidersEndpointSummary : Summary<GetLibraryTypeArtworkProvidersEndpoint, GetLibraryTypeArtworkProvidersRequest>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeArtworkProvidersEndpointSummary"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public GetLibraryTypeArtworkProvidersEndpointSummary()
|
||||||
|
{
|
||||||
|
Summary = "Retrieves the artwork providers available for a media library type.";
|
||||||
|
Description = "Retrieves the artwork providers of the loaded plugins that support a media library type, in the state a new media library of that type starts with: disabled, and ranked in alphabetical order.";
|
||||||
|
|
||||||
|
ExampleRequest = new GetLibraryTypeArtworkProvidersRequest(
|
||||||
|
LibraryType: "Book"
|
||||||
|
);
|
||||||
|
|
||||||
|
RequestParam(r => r.LibraryType, "The media library type whose available artwork providers are retrieved. Required.");
|
||||||
|
|
||||||
|
ResponseParam<LibraryArtworkProviderResponse>(r => r.PluginId, "The unique identifier of the plugin providing the artwork.");
|
||||||
|
ResponseParam<LibraryArtworkProviderResponse>(r => r.Name, "The display name of the artwork provider.");
|
||||||
|
ResponseParam<LibraryArtworkProviderResponse>(r => r.IsEnabled, "Whether the artwork provider is enabled. Always false, since no media library is involved.");
|
||||||
|
ResponseParam<LibraryArtworkProviderResponse>(r => r.Rank, "The rank of the artwork provider, determining the order in which providers are tried.");
|
||||||
|
|
||||||
|
Response(200, "The artwork providers available for the media library type are returned.",
|
||||||
|
example: new LibraryArtworkProviderResponse[] {
|
||||||
|
new(
|
||||||
|
PluginId: Guid.NewGuid(),
|
||||||
|
Name: "Goodreads",
|
||||||
|
IsEnabled: false,
|
||||||
|
Rank: 1
|
||||||
|
),
|
||||||
|
new(
|
||||||
|
PluginId: Guid.NewGuid(),
|
||||||
|
Name: "OpenLibrary",
|
||||||
|
IsEnabled: false,
|
||||||
|
Rank: 2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(401, "Authentication required.", "application/problem+json",
|
||||||
|
example: new[]
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "Authentication failed",
|
||||||
|
instance = "/api/v1/libraries/artwork-providers/{libraryType}"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "The token has expired",
|
||||||
|
instance = "/api/v1/libraries/artwork-providers/{libraryType}"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "The token is invalid",
|
||||||
|
instance = "/api/v1/libraries/artwork-providers/{libraryType}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(403, "The request failed because the request carries no user identity.", "application/problem+json",
|
||||||
|
example: new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||||
|
title = "General.Failure",
|
||||||
|
status = 403,
|
||||||
|
detail = "NotAuthorized",
|
||||||
|
instance = "/api/v1/libraries/artwork-providers/{libraryType}",
|
||||||
|
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||||
|
example: new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||||
|
title = "General.Validation",
|
||||||
|
status = 422,
|
||||||
|
detail = "OneOrMoreValidationErrorsOccurred",
|
||||||
|
instance = "/api/v1/libraries/artwork-providers/{libraryType}",
|
||||||
|
errors = new Dictionary<string, string[]>
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"General.Validation", new[]
|
||||||
|
{
|
||||||
|
"LibraryTypeCannotBeNull",
|
||||||
|
"UnknownLibraryType"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using FastEndpoints;
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
|
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using Lumina.Domain.Common.Primitives;
|
||||||
|
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
||||||
|
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryTypeBookReaders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API endpoint for the <c>/libraries/book-readers/{libraryType}</c> route.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeBookReadersEndpoint : BaseEndpoint<GetLibraryTypeBookReadersRequest, IResult>
|
||||||
|
{
|
||||||
|
private readonly IQueryHandler<GetLibraryTypeBookReadersQuery, Result<IReadOnlyList<LibraryBookReaderResponse>>> _getLibraryTypeBookReadersQueryHandler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeBookReadersEndpoint"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="getLibraryTypeBookReadersQueryHandler">Injected service for handling get library type book readers queries.</param>
|
||||||
|
public GetLibraryTypeBookReadersEndpoint(IQueryHandler<GetLibraryTypeBookReadersQuery, Result<IReadOnlyList<LibraryBookReaderResponse>>> getLibraryTypeBookReadersQueryHandler)
|
||||||
|
{
|
||||||
|
_getLibraryTypeBookReadersQueryHandler = getLibraryTypeBookReadersQueryHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the API endpoint.
|
||||||
|
/// </summary>
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Verbs(Http.GET);
|
||||||
|
Routes(ApiRoutes.Libraries.GET_LIBRARY_TYPE_BOOK_READERS);
|
||||||
|
Version(1);
|
||||||
|
DontCatchExceptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the book readers available for the media library type provided in <paramref name="request"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The request containing the media library type whose available book readers are retrieved.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
public override async Task<IResult> ExecuteAsync(GetLibraryTypeBookReadersRequest request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Result<IReadOnlyList<LibraryBookReaderResponse>> result = await _getLibraryTypeBookReadersQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||||
|
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||||
|
}
|
||||||
|
}
|
||||||
+118
@@ -0,0 +1,118 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using FastEndpoints;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryTypeBookReaders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class used for providing a textual description for the <see cref="GetLibraryTypeBookReadersEndpoint"/> API endpoint, for OpenAPI.
|
||||||
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public class GetLibraryTypeBookReadersEndpointSummary : Summary<GetLibraryTypeBookReadersEndpoint, GetLibraryTypeBookReadersRequest>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeBookReadersEndpointSummary"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public GetLibraryTypeBookReadersEndpointSummary()
|
||||||
|
{
|
||||||
|
Summary = "Retrieves the book readers available for a media library type.";
|
||||||
|
Description = "Retrieves the book readers of the loaded plugins that support a media library type, with their supported file extensions, in the state a new media library of that type starts with: disabled, in alphabetical order.";
|
||||||
|
|
||||||
|
ExampleRequest = new GetLibraryTypeBookReadersRequest(
|
||||||
|
LibraryType: "Book"
|
||||||
|
);
|
||||||
|
|
||||||
|
RequestParam(r => r.LibraryType, "The media library type whose available book readers are retrieved. Required.");
|
||||||
|
|
||||||
|
ResponseParam<LibraryBookReaderResponse>(r => r.PluginId, "The unique identifier of the plugin providing the book reader.");
|
||||||
|
ResponseParam<LibraryBookReaderResponse>(r => r.Name, "The display name of the book reader.");
|
||||||
|
ResponseParam<LibraryBookReaderResponse>(r => r.SupportedExtensions, "The file extensions supported by the book reader.");
|
||||||
|
ResponseParam<LibraryBookReaderResponse>(r => r.IsEnabled, "Whether the book reader is enabled. Always false, since no media library is involved.");
|
||||||
|
|
||||||
|
Response(200, "The book readers available for the media library type are returned.",
|
||||||
|
example: new LibraryBookReaderResponse[] {
|
||||||
|
new(
|
||||||
|
PluginId: Guid.NewGuid(),
|
||||||
|
Name: "EPUB Reader",
|
||||||
|
SupportedExtensions: [".epub"],
|
||||||
|
IsEnabled: false
|
||||||
|
),
|
||||||
|
new(
|
||||||
|
PluginId: Guid.NewGuid(),
|
||||||
|
Name: "PDF Reader",
|
||||||
|
SupportedExtensions: [".pdf"],
|
||||||
|
IsEnabled: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(401, "Authentication required.", "application/problem+json",
|
||||||
|
example: new[]
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "Authentication failed",
|
||||||
|
instance = "/api/v1/libraries/book-readers/{libraryType}"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "The token has expired",
|
||||||
|
instance = "/api/v1/libraries/book-readers/{libraryType}"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "The token is invalid",
|
||||||
|
instance = "/api/v1/libraries/book-readers/{libraryType}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(403, "The request failed because the request carries no user identity.", "application/problem+json",
|
||||||
|
example: new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||||
|
title = "General.Failure",
|
||||||
|
status = 403,
|
||||||
|
detail = "NotAuthorized",
|
||||||
|
instance = "/api/v1/libraries/book-readers/{libraryType}",
|
||||||
|
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||||
|
example: new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||||
|
title = "General.Validation",
|
||||||
|
status = 422,
|
||||||
|
detail = "OneOrMoreValidationErrorsOccurred",
|
||||||
|
instance = "/api/v1/libraries/book-readers/{libraryType}",
|
||||||
|
errors = new Dictionary<string, string[]>
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"General.Validation", new[]
|
||||||
|
{
|
||||||
|
"LibraryTypeCannotBeNull",
|
||||||
|
"UnknownLibraryType"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using FastEndpoints;
|
||||||
|
using Lumina.Application.Common.CQRS;
|
||||||
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
|
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using Lumina.Domain.Common.Primitives;
|
||||||
|
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
||||||
|
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryTypeMetadataProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API endpoint for the <c>/libraries/metadata-providers/{libraryType}</c> route.
|
||||||
|
/// </summary>
|
||||||
|
public class GetLibraryTypeMetadataProvidersEndpoint : BaseEndpoint<GetLibraryTypeMetadataProvidersRequest, IResult>
|
||||||
|
{
|
||||||
|
private readonly IQueryHandler<GetLibraryTypeMetadataProvidersQuery, Result<IReadOnlyList<LibraryMetadataProviderResponse>>> _getLibraryTypeMetadataProvidersQueryHandler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeMetadataProvidersEndpoint"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="getLibraryTypeMetadataProvidersQueryHandler">Injected service for handling get library type metadata providers queries.</param>
|
||||||
|
public GetLibraryTypeMetadataProvidersEndpoint(IQueryHandler<GetLibraryTypeMetadataProvidersQuery, Result<IReadOnlyList<LibraryMetadataProviderResponse>>> getLibraryTypeMetadataProvidersQueryHandler)
|
||||||
|
{
|
||||||
|
_getLibraryTypeMetadataProvidersQueryHandler = getLibraryTypeMetadataProvidersQueryHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the API endpoint.
|
||||||
|
/// </summary>
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Verbs(Http.GET);
|
||||||
|
Routes(ApiRoutes.Libraries.GET_LIBRARY_TYPE_METADATA_PROVIDERS);
|
||||||
|
Version(1);
|
||||||
|
DontCatchExceptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the metadata providers available for the media library type provided in <paramref name="request"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The request containing the media library type whose available metadata providers are retrieved.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
|
public override async Task<IResult> ExecuteAsync(GetLibraryTypeMetadataProvidersRequest request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Result<IReadOnlyList<LibraryMetadataProviderResponse>> result = await _getLibraryTypeMetadataProvidersQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||||
|
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||||
|
}
|
||||||
|
}
|
||||||
+118
@@ -0,0 +1,118 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using FastEndpoints;
|
||||||
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryTypeMetadataProviders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class used for providing a textual description for the <see cref="GetLibraryTypeMetadataProvidersEndpoint"/> API endpoint, for OpenAPI.
|
||||||
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public class GetLibraryTypeMetadataProvidersEndpointSummary : Summary<GetLibraryTypeMetadataProvidersEndpoint, GetLibraryTypeMetadataProvidersRequest>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GetLibraryTypeMetadataProvidersEndpointSummary"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public GetLibraryTypeMetadataProvidersEndpointSummary()
|
||||||
|
{
|
||||||
|
Summary = "Retrieves the metadata providers available for a media library type.";
|
||||||
|
Description = "Retrieves the metadata providers of the loaded plugins that support a media library type, in the state a new media library of that type starts with: disabled, and ranked in alphabetical order.";
|
||||||
|
|
||||||
|
ExampleRequest = new GetLibraryTypeMetadataProvidersRequest(
|
||||||
|
LibraryType: "Book"
|
||||||
|
);
|
||||||
|
|
||||||
|
RequestParam(r => r.LibraryType, "The media library type whose available metadata providers are retrieved. Required.");
|
||||||
|
|
||||||
|
ResponseParam<LibraryMetadataProviderResponse>(r => r.PluginId, "The unique identifier of the plugin providing the metadata.");
|
||||||
|
ResponseParam<LibraryMetadataProviderResponse>(r => r.Name, "The display name of the metadata provider.");
|
||||||
|
ResponseParam<LibraryMetadataProviderResponse>(r => r.IsEnabled, "Whether the metadata provider is enabled. Always false, since no media library is involved.");
|
||||||
|
ResponseParam<LibraryMetadataProviderResponse>(r => r.Rank, "The rank of the metadata provider, determining the order in which providers are tried.");
|
||||||
|
|
||||||
|
Response(200, "The metadata providers available for the media library type are returned.",
|
||||||
|
example: new LibraryMetadataProviderResponse[] {
|
||||||
|
new(
|
||||||
|
PluginId: Guid.NewGuid(),
|
||||||
|
Name: "Goodreads",
|
||||||
|
IsEnabled: false,
|
||||||
|
Rank: 1
|
||||||
|
),
|
||||||
|
new(
|
||||||
|
PluginId: Guid.NewGuid(),
|
||||||
|
Name: "OpenLibrary",
|
||||||
|
IsEnabled: false,
|
||||||
|
Rank: 2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(401, "Authentication required.", "application/problem+json",
|
||||||
|
example: new[]
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "Authentication failed",
|
||||||
|
instance = "/api/v1/libraries/metadata-providers/{libraryType}"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "The token has expired",
|
||||||
|
instance = "/api/v1/libraries/metadata-providers/{libraryType}"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||||
|
status = 401,
|
||||||
|
title = "Unauthorized",
|
||||||
|
detail = "The token is invalid",
|
||||||
|
instance = "/api/v1/libraries/metadata-providers/{libraryType}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(403, "The request failed because the request carries no user identity.", "application/problem+json",
|
||||||
|
example: new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||||
|
title = "General.Failure",
|
||||||
|
status = 403,
|
||||||
|
detail = "NotAuthorized",
|
||||||
|
instance = "/api/v1/libraries/metadata-providers/{libraryType}",
|
||||||
|
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||||
|
example: new
|
||||||
|
{
|
||||||
|
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||||
|
title = "General.Validation",
|
||||||
|
status = 422,
|
||||||
|
detail = "OneOrMoreValidationErrorsOccurred",
|
||||||
|
instance = "/api/v1/libraries/metadata-providers/{libraryType}",
|
||||||
|
errors = new Dictionary<string, string[]>
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"General.Validation", new[]
|
||||||
|
{
|
||||||
|
"LibraryTypeCannotBeNull",
|
||||||
|
"UnknownLibraryType"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
|
||||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryArtworkProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// API endpoint for the <c>/libraries/{libraryId}/artwork-providers/reorder</c> route.
|
|
||||||
/// </summary>
|
|
||||||
public class ReorderLibraryArtworkProvidersEndpoint : BaseEndpoint<ReorderLibraryArtworkProvidersRequest, IResult>
|
|
||||||
{
|
|
||||||
private readonly ICommandHandler<ReorderLibraryArtworkProvidersCommand, Result<Success>> _reorderLibraryArtworkProvidersCommandHandler;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersEndpoint"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="reorderLibraryArtworkProvidersCommandHandler">Injected service for handling reorder library artwork providers commands.</param>
|
|
||||||
public ReorderLibraryArtworkProvidersEndpoint(ICommandHandler<ReorderLibraryArtworkProvidersCommand, Result<Success>> reorderLibraryArtworkProvidersCommandHandler)
|
|
||||||
{
|
|
||||||
_reorderLibraryArtworkProvidersCommandHandler = reorderLibraryArtworkProvidersCommandHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Configures the API endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Verbs(FastEndpoints.Http.PUT);
|
|
||||||
Routes(ApiRoutes.Libraries.REORDER_LIBRARY_ARTWORK_PROVIDERS);
|
|
||||||
Version(1);
|
|
||||||
DontCatchExceptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reorders the artwork providers of the media library identified by <paramref name="request"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request containing the Id of the media library and the plugin Ids in the new order.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
public override async Task<IResult> ExecuteAsync(ReorderLibraryArtworkProvidersRequest request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
Result<Success> result = await _reorderLibraryArtworkProvidersCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
|
||||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-116
@@ -1,116 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using FastEndpoints;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryArtworkProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class used for providing a textual description for the <see cref="ReorderLibraryArtworkProvidersEndpoint"/> API endpoint, for OpenAPI.
|
|
||||||
/// </summary>
|
|
||||||
[ExcludeFromCodeCoverage]
|
|
||||||
public class ReorderLibraryArtworkProvidersEndpointSummary : Summary<ReorderLibraryArtworkProvidersEndpoint, ReorderLibraryArtworkProvidersRequest>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersEndpointSummary"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public ReorderLibraryArtworkProvidersEndpointSummary()
|
|
||||||
{
|
|
||||||
Summary = "Reorders the artwork providers of a media library.";
|
|
||||||
Description = "Reorders the artwork providers of a media library, determining the order in which the providers are tried during the artwork enrichment of the library scans.";
|
|
||||||
|
|
||||||
ExampleRequest = new ReorderLibraryArtworkProvidersRequest(
|
|
||||||
LibraryId: Guid.NewGuid(),
|
|
||||||
PluginIds:
|
|
||||||
[
|
|
||||||
Guid.NewGuid(),
|
|
||||||
Guid.NewGuid()
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
RequestParam(r => r.LibraryId, "The Id of the media library whose artwork providers are reordered. Required.");
|
|
||||||
RequestParam(r => r.PluginIds, "The plugin Ids in the new order, from highest to lowest rank. Required.");
|
|
||||||
|
|
||||||
Response(200, "The artwork providers of the media library were successfully reordered.");
|
|
||||||
|
|
||||||
Response(401, "Authentication required.", "application/problem+json",
|
|
||||||
example: new[]
|
|
||||||
{
|
|
||||||
new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
|
||||||
status = 401,
|
|
||||||
title = "Unauthorized",
|
|
||||||
detail = "Authentication failed",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder"
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
|
||||||
status = 401,
|
|
||||||
title = "Unauthorized",
|
|
||||||
detail = "The token has expired",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder"
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
|
||||||
status = 401,
|
|
||||||
title = "Unauthorized",
|
|
||||||
detail = "The token is invalid",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
|
||||||
example: new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
|
||||||
title = "General.Failure",
|
|
||||||
status = 403,
|
|
||||||
detail = "NotAuthorized",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder",
|
|
||||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Response(404, "The request failed because the requested media library does not exist.", "application/problem+json",
|
|
||||||
example: new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
|
||||||
title = "General.NotFound",
|
|
||||||
status = 404,
|
|
||||||
detail = "LibraryNotFound",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder",
|
|
||||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
|
||||||
example: new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
|
||||||
title = "General.Validation",
|
|
||||||
status = 422,
|
|
||||||
detail = "OneOrMoreValidationErrorsOccurred",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder",
|
|
||||||
errors = new Dictionary<string, string[]>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"General.Validation", new[]
|
|
||||||
{
|
|
||||||
"LibraryIdCannotBeEmpty",
|
|
||||||
"PluginIdsListCannotBeNull",
|
|
||||||
"PluginIdsListCannotBeEmpty"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
|
||||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryMetadataProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// API endpoint for the <c>/libraries/{libraryId}/metadata-providers/reorder</c> route.
|
|
||||||
/// </summary>
|
|
||||||
public class ReorderLibraryMetadataProvidersEndpoint : BaseEndpoint<ReorderLibraryMetadataProvidersRequest, IResult>
|
|
||||||
{
|
|
||||||
private readonly ICommandHandler<ReorderLibraryMetadataProvidersCommand, Result<Success>> _reorderLibraryMetadataProvidersCommandHandler;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersEndpoint"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="reorderLibraryMetadataProvidersCommandHandler">Injected service for handling reorder library metadata providers commands.</param>
|
|
||||||
public ReorderLibraryMetadataProvidersEndpoint(ICommandHandler<ReorderLibraryMetadataProvidersCommand, Result<Success>> reorderLibraryMetadataProvidersCommandHandler)
|
|
||||||
{
|
|
||||||
_reorderLibraryMetadataProvidersCommandHandler = reorderLibraryMetadataProvidersCommandHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Configures the API endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Verbs(FastEndpoints.Http.PUT);
|
|
||||||
Routes(ApiRoutes.Libraries.REORDER_LIBRARY_METADATA_PROVIDERS);
|
|
||||||
Version(1);
|
|
||||||
DontCatchExceptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reorders the metadata providers of the media library identified by <paramref name="request"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request containing the Id of the media library and the plugin Ids in the new order.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
public override async Task<IResult> ExecuteAsync(ReorderLibraryMetadataProvidersRequest request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
Result<Success> result = await _reorderLibraryMetadataProvidersCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
|
||||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-116
@@ -1,116 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using FastEndpoints;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryMetadataProviders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class used for providing a textual description for the <see cref="ReorderLibraryMetadataProvidersEndpoint"/> API endpoint, for OpenAPI.
|
|
||||||
/// </summary>
|
|
||||||
[ExcludeFromCodeCoverage]
|
|
||||||
public class ReorderLibraryMetadataProvidersEndpointSummary : Summary<ReorderLibraryMetadataProvidersEndpoint, ReorderLibraryMetadataProvidersRequest>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ReorderLibraryMetadataProvidersEndpointSummary"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public ReorderLibraryMetadataProvidersEndpointSummary()
|
|
||||||
{
|
|
||||||
Summary = "Reorders the metadata providers of a media library.";
|
|
||||||
Description = "Reorders the metadata providers of a media library, determining the order in which the providers are tried during the metadata enrichment of the library scans.";
|
|
||||||
|
|
||||||
ExampleRequest = new ReorderLibraryMetadataProvidersRequest(
|
|
||||||
LibraryId: Guid.NewGuid(),
|
|
||||||
PluginIds:
|
|
||||||
[
|
|
||||||
Guid.NewGuid(),
|
|
||||||
Guid.NewGuid()
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
RequestParam(r => r.LibraryId, "The Id of the media library whose metadata providers are reordered. Required.");
|
|
||||||
RequestParam(r => r.PluginIds, "The plugin Ids in the new order, from highest to lowest rank. Required.");
|
|
||||||
|
|
||||||
Response(200, "The metadata providers of the media library were successfully reordered.");
|
|
||||||
|
|
||||||
Response(401, "Authentication required.", "application/problem+json",
|
|
||||||
example: new[]
|
|
||||||
{
|
|
||||||
new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
|
||||||
status = 401,
|
|
||||||
title = "Unauthorized",
|
|
||||||
detail = "Authentication failed",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers/reorder"
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
|
||||||
status = 401,
|
|
||||||
title = "Unauthorized",
|
|
||||||
detail = "The token has expired",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers/reorder"
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
|
||||||
status = 401,
|
|
||||||
title = "Unauthorized",
|
|
||||||
detail = "The token is invalid",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers/reorder"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
|
||||||
example: new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
|
||||||
title = "General.Failure",
|
|
||||||
status = 403,
|
|
||||||
detail = "NotAuthorized",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers/reorder",
|
|
||||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Response(404, "The request failed because the requested media library does not exist.", "application/problem+json",
|
|
||||||
example: new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
|
||||||
title = "General.NotFound",
|
|
||||||
status = 404,
|
|
||||||
detail = "LibraryNotFound",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers/reorder",
|
|
||||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
|
||||||
example: new
|
|
||||||
{
|
|
||||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
|
||||||
title = "General.Validation",
|
|
||||||
status = 422,
|
|
||||||
detail = "OneOrMoreValidationErrorsOccurred",
|
|
||||||
instance = "/api/v1/libraries/{libraryId}/metadata-providers/reorder",
|
|
||||||
errors = new Dictionary<string, string[]>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"General.Validation", new[]
|
|
||||||
{
|
|
||||||
"LibraryIdCannotBeEmpty",
|
|
||||||
"PluginIdsListCannotBeNull",
|
|
||||||
"PluginIdsListCannotBeEmpty"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Common.CQRS;
|
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
|
||||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
|
||||||
using Lumina.Domain.Common.Primitives;
|
|
||||||
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
|
||||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.SetLibraryArtworkProviderEnabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// API endpoint for the <c>/libraries/{libraryId}/artwork-providers/{pluginId}/enabled</c> route.
|
|
||||||
/// </summary>
|
|
||||||
public class SetLibraryArtworkProviderEnabledEndpoint : BaseEndpoint<SetLibraryArtworkProviderEnabledRequest, IResult>
|
|
||||||
{
|
|
||||||
private readonly ICommandHandler<SetLibraryArtworkProviderEnabledCommand, Result<Success>> _setLibraryArtworkProviderEnabledCommandHandler;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetLibraryArtworkProviderEnabledEndpoint"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="setLibraryArtworkProviderEnabledCommandHandler">Injected service for handling set library artwork provider enabled commands.</param>
|
|
||||||
public SetLibraryArtworkProviderEnabledEndpoint(ICommandHandler<SetLibraryArtworkProviderEnabledCommand, Result<Success>> setLibraryArtworkProviderEnabledCommandHandler)
|
|
||||||
{
|
|
||||||
_setLibraryArtworkProviderEnabledCommandHandler = setLibraryArtworkProviderEnabledCommandHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Configures the API endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Verbs(FastEndpoints.Http.PUT);
|
|
||||||
Routes(ApiRoutes.Libraries.SET_LIBRARY_ARTWORK_PROVIDER_ENABLED);
|
|
||||||
Version(1);
|
|
||||||
DontCatchExceptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Enables or disables the artwork provider identified by <paramref name="request"/> for the media library.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request containing the Ids of the media library and of the artwork provider.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
||||||
public override async Task<IResult> ExecuteAsync(SetLibraryArtworkProviderEnabledRequest request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
Result<Success> result = await _setLibraryArtworkProviderEnabledCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
|
||||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loaded 100 of 292 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user