diff --git a/server/models/Author.js b/server/models/Author.js index 220abeb8..c6537ec1 100644 --- a/server/models/Author.js +++ b/server/models/Author.js @@ -1,4 +1,4 @@ -const { DataTypes, Model, literal } = require('sequelize') +const { DataTypes, Model, where, fn, col } = require('sequelize') const oldAuthor = require('../objects/entities/Author') @@ -114,14 +114,11 @@ class Author extends Model { static async getOldByNameAndLibrary(authorName, libraryId) { const author = (await this.findOne({ where: [ - literal(`name = ':authorName' COLLATE NOCASE`), + where(fn('lower', col('name')), authorName.toLowerCase()), { libraryId } - ], - replacements: { - authorName - } + ] }))?.getOldAuthor() return author } diff --git a/server/models/Series.js b/server/models/Series.js index 2b37002d..81c27a8b 100644 --- a/server/models/Series.js +++ b/server/models/Series.js @@ -1,4 +1,4 @@ -const { DataTypes, Model, literal } = require('sequelize') +const { DataTypes, Model, where, fn, col } = require('sequelize') const oldSeries = require('../objects/entities/Series') @@ -105,14 +105,11 @@ class Series extends Model { static async getOldByNameAndLibrary(seriesName, libraryId) { const series = (await this.findOne({ where: [ - literal(`name = ':seriesName' COLLATE NOCASE`), + where(fn('lower', col('name')), seriesName.toLowerCase()), { libraryId } - ], - replacements: { - seriesName - } + ] }))?.getOldSeries() return series } diff --git a/server/routers/ApiRouter.js b/server/routers/ApiRouter.js index a0bb2544..71d9429e 100644 --- a/server/routers/ApiRouter.js +++ b/server/routers/ApiRouter.js @@ -553,13 +553,17 @@ class ApiRouter { continue } + if (mediaMetadata.authors[i].id?.startsWith('new')) { + mediaMetadata.authors[i].id = null + } + // Ensure the ID for the author exists if (mediaMetadata.authors[i].id && !(await Database.checkAuthorExists(libraryId, mediaMetadata.authors[i].id))) { Logger.warn(`[ApiRouter] Author id "${mediaMetadata.authors[i].id}" does not exist`) mediaMetadata.authors[i].id = null } - if (!mediaMetadata.authors[i].id || mediaMetadata.authors[i].id.startsWith('new')) { + if (!mediaMetadata.authors[i].id) { let author = await Database.authorModel.getOldByNameAndLibrary(authorName, libraryId) if (!author) { author = new Author() @@ -590,13 +594,17 @@ class ApiRouter { continue } + if (mediaMetadata.series[i].id?.startsWith('new')) { + mediaMetadata.series[i].id = null + } + // Ensure the ID for the series exists if (mediaMetadata.series[i].id && !(await Database.checkSeriesExists(libraryId, mediaMetadata.series[i].id))) { Logger.warn(`[ApiRouter] Series id "${mediaMetadata.series[i].id}" does not exist`) mediaMetadata.series[i].id = null } - if (!mediaMetadata.series[i].id || mediaMetadata.series[i].id.startsWith('new')) { + if (!mediaMetadata.series[i].id) { let seriesItem = await Database.seriesModel.getOldByNameAndLibrary(seriesName, libraryId) if (!seriesItem) { seriesItem = new Series()