implemented suggestions, extended CMPs with series

This commit is contained in:
FlyinPancake 2024-01-12 21:45:03 +01:00
parent 12c6a1baa0
commit 3b531144cf
No known key found for this signature in database
6 changed files with 33 additions and 28 deletions

View file

@ -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()

View file

@ -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'

View file

@ -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,
}