mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-16 01:16:24 +02: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>}
|
* @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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user