mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-08 00:08:14 +01:00
Fix:Duplicate series and authors being added on matches and scans #2106
This commit is contained in:
parent
0aae672e19
commit
d18592eaeb
@ -1,4 +1,4 @@
|
|||||||
const { DataTypes, Model, literal } = require('sequelize')
|
const { DataTypes, Model, where, fn, col } = require('sequelize')
|
||||||
|
|
||||||
const oldAuthor = require('../objects/entities/Author')
|
const oldAuthor = require('../objects/entities/Author')
|
||||||
|
|
||||||
@ -114,14 +114,11 @@ class Author extends Model {
|
|||||||
static async getOldByNameAndLibrary(authorName, libraryId) {
|
static async getOldByNameAndLibrary(authorName, libraryId) {
|
||||||
const author = (await this.findOne({
|
const author = (await this.findOne({
|
||||||
where: [
|
where: [
|
||||||
literal(`name = ':authorName' COLLATE NOCASE`),
|
where(fn('lower', col('name')), authorName.toLowerCase()),
|
||||||
{
|
{
|
||||||
libraryId
|
libraryId
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
replacements: {
|
|
||||||
authorName
|
|
||||||
}
|
|
||||||
}))?.getOldAuthor()
|
}))?.getOldAuthor()
|
||||||
return author
|
return author
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { DataTypes, Model, literal } = require('sequelize')
|
const { DataTypes, Model, where, fn, col } = require('sequelize')
|
||||||
|
|
||||||
const oldSeries = require('../objects/entities/Series')
|
const oldSeries = require('../objects/entities/Series')
|
||||||
|
|
||||||
@ -105,14 +105,11 @@ class Series extends Model {
|
|||||||
static async getOldByNameAndLibrary(seriesName, libraryId) {
|
static async getOldByNameAndLibrary(seriesName, libraryId) {
|
||||||
const series = (await this.findOne({
|
const series = (await this.findOne({
|
||||||
where: [
|
where: [
|
||||||
literal(`name = ':seriesName' COLLATE NOCASE`),
|
where(fn('lower', col('name')), seriesName.toLowerCase()),
|
||||||
{
|
{
|
||||||
libraryId
|
libraryId
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
replacements: {
|
|
||||||
seriesName
|
|
||||||
}
|
|
||||||
}))?.getOldSeries()
|
}))?.getOldSeries()
|
||||||
return series
|
return series
|
||||||
}
|
}
|
||||||
|
@ -553,13 +553,17 @@ class ApiRouter {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mediaMetadata.authors[i].id?.startsWith('new')) {
|
||||||
|
mediaMetadata.authors[i].id = null
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the ID for the author exists
|
// Ensure the ID for the author exists
|
||||||
if (mediaMetadata.authors[i].id && !(await Database.checkAuthorExists(libraryId, mediaMetadata.authors[i].id))) {
|
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`)
|
Logger.warn(`[ApiRouter] Author id "${mediaMetadata.authors[i].id}" does not exist`)
|
||||||
mediaMetadata.authors[i].id = null
|
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)
|
let author = await Database.authorModel.getOldByNameAndLibrary(authorName, libraryId)
|
||||||
if (!author) {
|
if (!author) {
|
||||||
author = new Author()
|
author = new Author()
|
||||||
@ -590,13 +594,17 @@ class ApiRouter {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mediaMetadata.series[i].id?.startsWith('new')) {
|
||||||
|
mediaMetadata.series[i].id = null
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the ID for the series exists
|
// Ensure the ID for the series exists
|
||||||
if (mediaMetadata.series[i].id && !(await Database.checkSeriesExists(libraryId, mediaMetadata.series[i].id))) {
|
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`)
|
Logger.warn(`[ApiRouter] Series id "${mediaMetadata.series[i].id}" does not exist`)
|
||||||
mediaMetadata.series[i].id = null
|
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)
|
let seriesItem = await Database.seriesModel.getOldByNameAndLibrary(seriesName, libraryId)
|
||||||
if (!seriesItem) {
|
if (!seriesItem) {
|
||||||
seriesItem = new Series()
|
seriesItem = new Series()
|
||||||
|
Loading…
Reference in New Issue
Block a user