mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-11-07 08:34:10 +01:00
when checking if series/author is alread in DB, use case insensitive match only for ASCII names
This commit is contained in:
parent
01fbea02f1
commit
def34a860b
@ -53,14 +53,26 @@ class Author extends Model {
|
||||
* @returns {Promise<Author>}
|
||||
*/
|
||||
static async getByNameAndLibrary(authorName, libraryId) {
|
||||
return this.findOne({
|
||||
where: [
|
||||
where(fn('lower', col('name')), authorName.toLowerCase()),
|
||||
{
|
||||
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({
|
||||
where: [
|
||||
where(fn('lower', col('name')), authorName.toLowerCase()),
|
||||
{
|
||||
libraryId
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,14 +39,26 @@ class Series extends Model {
|
||||
* @returns {Promise<Series>}
|
||||
*/
|
||||
static async getByNameAndLibrary(seriesName, libraryId) {
|
||||
return this.findOne({
|
||||
where: [
|
||||
where(fn('lower', col('name')), seriesName.toLowerCase()),
|
||||
{
|
||||
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({
|
||||
where: [
|
||||
where(fn('lower', col('name')), seriesName.toLowerCase()),
|
||||
{
|
||||
libraryId
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user