From 3b531144cfdbce2379b90bb4f2ee36ca949db79c Mon Sep 17 00:00:00 2001 From: FlyinPancake Date: Fri, 12 Jan 2024 21:45:03 +0100 Subject: [PATCH] implemented suggestions, extended CMPs with series --- .../pages/config/custom-metadata-providers.vue | 6 ++---- client/strings/en-us.json | 6 +++--- custom-metadata-provider-specification.yaml | 13 ++++++++++++- server/controllers/MiscController.js | 10 +++++----- server/models/CustomMetadataProvider.js | 10 ++-------- server/providers/CustomProviderAdapter.js | 16 +++++++++------- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/client/pages/config/custom-metadata-providers.vue b/client/pages/config/custom-metadata-providers.vue index 10fdb21b..9f394eae 100644 --- a/client/pages/config/custom-metadata-providers.vue +++ b/client/pages/config/custom-metadata-providers.vue @@ -9,7 +9,7 @@
- {{ $strings.ButtonAdd }} + {{ $strings.ButtonAdd }} @@ -40,6 +40,4 @@ export default { } - + diff --git a/client/strings/en-us.json b/client/strings/en-us.json index 9dfde095..e937ed72 100644 --- a/client/strings/en-us.json +++ b/client/strings/en-us.json @@ -96,7 +96,6 @@ "HeaderAudiobookTools": "Audiobook File Management Tools", "HeaderAudioTracks": "Audio Tracks", "HeaderAuthentication": "Authentication", - "HeaderCustomMetadataProviders": "Custom metadata providers", "HeaderBackups": "Backups", "HeaderChangePassword": "Change Password", "HeaderChapters": "Chapters", @@ -105,6 +104,7 @@ "HeaderCollectionItems": "Collection Items", "HeaderCover": "Cover", "HeaderCurrentDownloads": "Current Downloads", + "HeaderCustomMetadataProviders": "Custom metadata providers", "HeaderDetails": "Details", "HeaderDownloadQueue": "Download Queue", "HeaderEbookFiles": "Ebook Files", @@ -194,6 +194,7 @@ "LabelAllUsersExcludingGuests": "All users excluding guests", "LabelAllUsersIncludingGuests": "All users including guests", "LabelAlreadyInYourLibrary": "Already in your library", + "LabelApiKey": "API Key", "LabelAppend": "Append", "LabelAuthor": "Author", "LabelAuthorFirstLast": "Author (First Last)", @@ -526,6 +527,7 @@ "LabelUploaderDragAndDrop": "Drag & drop files or folders", "LabelUploaderDropFiles": "Drop files", "LabelUploaderItemFetchMetadataHelp": "Automatically fetch title, author, and series", + "LabelUrl": "URL", "LabelUseChapterTrack": "Use chapter track", "LabelUseFullTrack": "Use full track", "LabelUser": "User", @@ -541,8 +543,6 @@ "LabelYourBookmarks": "Your Bookmarks", "LabelYourPlaylists": "Your Playlists", "LabelYourProgress": "Your Progress", - "LabelUrl": "URL", - "LabelApiKey": "API Key", "MessageAddToPlayerQueue": "Add to player queue", "MessageAppriseDescription": "To use this feature you will need to have an instance of Apprise API running or an api that will handle those same requests.
The Apprise API Url should be the full URL path to send the notification, e.g., if your API instance is served at http://192.168.1.1:8337 then you would put http://192.168.1.1:8337/notify.", "MessageBackupsDescription": "Backups include users, user progress, library item details, server settings, and images stored in /metadata/items & /metadata/authors. Backups do not include any files stored in your library folders.", diff --git a/custom-metadata-provider-specification.yaml b/custom-metadata-provider-specification.yaml index 3201fbb8..90df875b 100644 --- a/custom-metadata-provider-specification.yaml +++ b/custom-metadata-provider-specification.yaml @@ -86,7 +86,7 @@ components: type: string publisher: type: string - published_year: + publishedYear: type: string description: type: string @@ -107,6 +107,17 @@ components: type: array items: type: string + series: + type: array + items: + type: object + properties: + series: + type: string + required: true + sequence: + type: number + format: int64 language: type: string duration: diff --git a/server/controllers/MiscController.js b/server/controllers/MiscController.js index 76140dcc..1d2fff04 100644 --- a/server/controllers/MiscController.js +++ b/server/controllers/MiscController.js @@ -763,7 +763,7 @@ class MiscController { return res.sendStatus(403) } - const { name, url, apiKey } = req.body; + const { name, url, apiKey } = req.body if (!name || !url || !apiKey) { return res.status(500).send(`Invalid patch data`) @@ -794,18 +794,18 @@ class MiscController { return res.sendStatus(403) } - const { id } = req.params; + const { id } = req.params if (!id) { return res.status(500).send(`Invalid delete data`) } - const provider = await Database.customMetadataProviderModel.findByPk(id); - await Database.removeCustomMetadataProviderById(id); + const provider = await Database.customMetadataProviderModel.findByPk(id) + await Database.removeCustomMetadataProviderById(id) SocketAuthority.adminEmitter('custom_metadata_provider_removed', provider) - res.json({}) + res.sendStatus(200) } } module.exports = new MiscController() diff --git a/server/models/CustomMetadataProvider.js b/server/models/CustomMetadataProvider.js index 9bc175c4..d6047bb8 100644 --- a/server/models/CustomMetadataProvider.js +++ b/server/models/CustomMetadataProvider.js @@ -26,13 +26,7 @@ class CustomMetadataProvider extends Model { } } - static findByPk(id) { - return this.findOne({ - where: { - id, - } - }) - } + /** * Initialize model @@ -47,7 +41,7 @@ class CustomMetadataProvider extends Model { }, name: DataTypes.STRING, url: DataTypes.STRING, - apiKey: DataTypes.STRING + apiKey: DataTypes.STRING, }, { sequelize, modelName: 'customMetadataProvider' diff --git a/server/providers/CustomProviderAdapter.js b/server/providers/CustomProviderAdapter.js index d5f64291..1919ecc9 100644 --- a/server/providers/CustomProviderAdapter.js +++ b/server/providers/CustomProviderAdapter.js @@ -1,6 +1,6 @@ const Database = require('../Database') -const axios = require("axios"); -const Logger = require("../Logger"); +const axios = require("axios") +const Logger = require("../Logger") class CustomProviderAdapter { constructor() { @@ -8,10 +8,10 @@ class CustomProviderAdapter { async search(title, author, providerSlug) { const providerId = providerSlug.split("custom-")[1] - const provider = await Database.customMetadataProviderModel.findByPk(providerId); + const provider = await Database.customMetadataProviderModel.findByPk(providerId) if (!provider) { - throw new Error("Custom provider not found for the given id"); + throw new Error("Custom provider not found for the given id") } const matches = await axios.get(`${provider.url}/search?query=${encodeURIComponent(title)}${!!author ? `&author=${encodeURIComponent(author)}` : ""}`, { @@ -27,7 +27,7 @@ class CustomProviderAdapter { }) if (matches === null) { - throw new Error("Custom provider returned malformed response"); + throw new Error("Custom provider returned malformed response") } // re-map keys to throw out @@ -37,13 +37,14 @@ class CustomProviderAdapter { author, narrator, publisher, - published_year, + publishedYear, description, cover, isbn, asin, genres, tags, + series, language, duration, }) => { @@ -53,13 +54,14 @@ class CustomProviderAdapter { author, narrator, publisher, - publishedYear: published_year, + publishedYear, description, cover, isbn, asin, genres, tags: tags.join(","), + series: series.length ? series : null, language, duration, }