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

View File

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