when checking if series/author is alread in DB, use case insensitive match only for ASCII names

This commit is contained in:
Oleg Ivasenko 2024-09-13 16:23:25 +00:00
parent 01fbea02f1
commit def34a860b
2 changed files with 38 additions and 14 deletions

View File

@ -53,6 +53,17 @@ class Author extends Model {
* @returns {Promise<Author>} * @returns {Promise<Author>}
*/ */
static async getByNameAndLibrary(authorName, libraryId) { static async getByNameAndLibrary(authorName, libraryId) {
const containsOnlyASCII = /^[\u0000-\u007f]*$/.test(authorName)
// SQLite does not support lower with non-Unicode chars
if (!containsOnlyASCII) {
return this.findOne({
where: {
name: authorName,
libraryId: libraryId
}
})
} else {
return this.findOne({ return this.findOne({
where: [ where: [
where(fn('lower', col('name')), authorName.toLowerCase()), where(fn('lower', col('name')), authorName.toLowerCase()),
@ -62,6 +73,7 @@ class Author extends Model {
] ]
}) })
} }
}
/** /**
* *

View File

@ -39,6 +39,17 @@ class Series extends Model {
* @returns {Promise<Series>} * @returns {Promise<Series>}
*/ */
static async getByNameAndLibrary(seriesName, libraryId) { static async getByNameAndLibrary(seriesName, libraryId) {
const containsOnlyASCII = /^[\u0000-\u007f]*$/.test(authorName)
// SQLite does not support lower with non-Unicode chars
if (!containsOnlyASCII) {
return this.findOne({
where: {
name: seriesName,
libraryId: libraryId
}
})
} else {
return this.findOne({ return this.findOne({
where: [ where: [
where(fn('lower', col('name')), seriesName.toLowerCase()), where(fn('lower', col('name')), seriesName.toLowerCase()),
@ -48,6 +59,7 @@ class Series extends Model {
] ]
}) })
} }
}
/** /**
* Initialize model * Initialize model