mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 09:51:37 +00:00
Update author model function comments
This commit is contained in:
parent
d67c1816dd
commit
22d107fb4e
1 changed files with 22 additions and 3 deletions
|
|
@ -37,6 +37,11 @@ class Author extends Model {
|
||||||
return parseNameString.nameToLastFirst(name)
|
return parseNameString.nameToLastFirst(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all punctionation, diacritics, and whitespace and convert to lowercase for searching and matching
|
||||||
|
* @param {string} name
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
static normalizeSearchName(name) {
|
static normalizeSearchName(name) {
|
||||||
if (!name?.trim()) return null
|
if (!name?.trim()) return null
|
||||||
return name
|
return name
|
||||||
|
|
@ -47,6 +52,11 @@ class Author extends Model {
|
||||||
.trim()
|
.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate derived fields. Returns null if name is empty after normalization
|
||||||
|
* @param {string} name
|
||||||
|
* @returns { lastFirst: string?, searchName: string? }
|
||||||
|
*/
|
||||||
static buildAuthorDerivedFields(name) {
|
static buildAuthorDerivedFields(name) {
|
||||||
const searchName = this.normalizeSearchName(name)
|
const searchName = this.normalizeSearchName(name)
|
||||||
if (!searchName) {
|
if (!searchName) {
|
||||||
|
|
@ -62,10 +72,21 @@ class Author extends Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if two author names match after normalization
|
||||||
|
* @param {string} leftName
|
||||||
|
* @param {string} rightName
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
static isAuthorNameMatch(leftName, rightName) {
|
static isAuthorNameMatch(leftName, rightName) {
|
||||||
return this.normalizeSearchName(leftName) === this.normalizeSearchName(rightName)
|
return this.normalizeSearchName(leftName) === this.normalizeSearchName(rightName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if any derived fields would change to reduce unnecessary database writes
|
||||||
|
* @param {Author} author
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
static hasDerivedFieldChange(author) {
|
static hasDerivedFieldChange(author) {
|
||||||
const derivedFields = this.buildAuthorDerivedFields(author.name)
|
const derivedFields = this.buildAuthorDerivedFields(author.name)
|
||||||
let changed = false
|
let changed = false
|
||||||
|
|
@ -96,8 +117,6 @@ class Author extends Model {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get author by name and libraryId. name case insensitive
|
* Get author by name and libraryId. name case insensitive
|
||||||
* TODO: Look for authors ignoring punctuation
|
|
||||||
*
|
|
||||||
* @param {string} authorName
|
* @param {string} authorName
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @returns {Promise<Author>}
|
* @returns {Promise<Author>}
|
||||||
|
|
@ -158,7 +177,7 @@ class Author extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Ensure duplicate authors are not created for the same library using the normalized name
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @returns {Promise<{ author: Author, created: boolean }>}
|
* @returns {Promise<{ author: Author, created: boolean }>}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue