mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-01 00:18:14 +01:00
Update functions for #2724 and add jsdocs
This commit is contained in:
parent
ae0a9bcf86
commit
c14f9accaf
@ -689,19 +689,33 @@ class Database {
|
|||||||
return this.libraryFilterData[libraryId].series.some(se => se.id === seriesId)
|
return this.libraryFilterData[libraryId].series.some(se => se.id === seriesId)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAuthorByName(libraryId, authorName) {
|
/**
|
||||||
|
* Get author id for library by name. Uses library filter data if available
|
||||||
|
*
|
||||||
|
* @param {string} libraryId
|
||||||
|
* @param {string} authorName
|
||||||
|
* @returns {Promise<string>} author id or null if not found
|
||||||
|
*/
|
||||||
|
async getAuthorIdByName(libraryId, authorName) {
|
||||||
if (!this.libraryFilterData[libraryId]) {
|
if (!this.libraryFilterData[libraryId]) {
|
||||||
return await this.authorModel.getOldByNameAndLibrary(authorName, libraryId)
|
return (await this.authorModel.getOldByNameAndLibrary(authorName, libraryId))?.id || null
|
||||||
}
|
}
|
||||||
return this.libraryFilterData[libraryId].authors.find(au => au.name === authorName)
|
return this.libraryFilterData[libraryId].authors.find(au => au.name === authorName)?.id || null
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSeriesByName(libraryId, seriesName) {
|
/**
|
||||||
|
* Get series id for library by name. Uses library filter data if available
|
||||||
|
*
|
||||||
|
* @param {string} libraryId
|
||||||
|
* @param {string} seriesName
|
||||||
|
* @returns {Promise<string>} series id or null if not found
|
||||||
|
*/
|
||||||
|
async getSeriesIdByName(libraryId, seriesName) {
|
||||||
if (!this.libraryFilterData[libraryId]) {
|
if (!this.libraryFilterData[libraryId]) {
|
||||||
return await this.seriesModel.getOldByNameAndLibrary(seriesName, libraryId)
|
return (await this.seriesModel.getOldByNameAndLibrary(seriesName, libraryId))?.id || null
|
||||||
}
|
}
|
||||||
return this.libraryFilterData[libraryId].series.find(se => se.name === seriesName)
|
return this.libraryFilterData[libraryId].series.find(se => se.name === seriesName)?.id || null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset numIssues for library
|
* Reset numIssues for library
|
||||||
|
@ -186,11 +186,11 @@ class BookScanner {
|
|||||||
// Check for authors added
|
// Check for authors added
|
||||||
for (const authorName of bookMetadata.authors) {
|
for (const authorName of bookMetadata.authors) {
|
||||||
if (!media.authors.some(au => au.name === authorName)) {
|
if (!media.authors.some(au => au.name === authorName)) {
|
||||||
const existingAuthor = await Database.getAuthorByName(libraryItemData.libraryId, authorName)
|
const existingAuthorId = await Database.getAuthorIdByName(libraryItemData.libraryId, authorName)
|
||||||
if (existingAuthor) {
|
if (existingAuthorId) {
|
||||||
await Database.bookAuthorModel.create({
|
await Database.bookAuthorModel.create({
|
||||||
bookId: media.id,
|
bookId: media.id,
|
||||||
authorId: existingAuthor.id
|
authorId: existingAuthorId
|
||||||
})
|
})
|
||||||
libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" added author "${authorName}"`)
|
libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" added author "${authorName}"`)
|
||||||
authorsUpdated = true
|
authorsUpdated = true
|
||||||
@ -221,11 +221,11 @@ class BookScanner {
|
|||||||
for (const seriesObj of bookMetadata.series) {
|
for (const seriesObj of bookMetadata.series) {
|
||||||
const existingBookSeries = media.series.find(se => se.name === seriesObj.name)
|
const existingBookSeries = media.series.find(se => se.name === seriesObj.name)
|
||||||
if (!existingBookSeries) {
|
if (!existingBookSeries) {
|
||||||
const existingSeries = await Database.getSeriesByName(libraryItemData.libraryId, seriesObj.name)
|
const existingSeriesId = await Database.getSeriesIdByName(libraryItemData.libraryId, seriesObj.name)
|
||||||
if (existingSeries) {
|
if (existingSeriesId) {
|
||||||
await Database.bookSeriesModel.create({
|
await Database.bookSeriesModel.create({
|
||||||
bookId: media.id,
|
bookId: media.id,
|
||||||
seriesId: existingSeries.id,
|
seriesId: existingSeriesId,
|
||||||
sequence: seriesObj.sequence
|
sequence: seriesObj.sequence
|
||||||
})
|
})
|
||||||
libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" added series "${seriesObj.name}"${seriesObj.sequence ? ` with sequence "${seriesObj.sequence}"` : ''}`)
|
libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" added series "${seriesObj.name}"${seriesObj.sequence ? ` with sequence "${seriesObj.sequence}"` : ''}`)
|
||||||
@ -443,10 +443,10 @@ class BookScanner {
|
|||||||
}
|
}
|
||||||
if (bookMetadata.authors.length) {
|
if (bookMetadata.authors.length) {
|
||||||
for (const authorName of bookMetadata.authors) {
|
for (const authorName of bookMetadata.authors) {
|
||||||
const matchingAuthor = await Database.getAuthorByName(libraryItemData.libraryId, authorName)
|
const matchingAuthorId = await Database.getAuthorIdByName(libraryItemData.libraryId, authorName)
|
||||||
if (matchingAuthor) {
|
if (matchingAuthorId) {
|
||||||
bookObject.bookAuthors.push({
|
bookObject.bookAuthors.push({
|
||||||
authorId: matchingAuthor.id
|
authorId: matchingAuthorId
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// New author
|
// New author
|
||||||
@ -463,10 +463,10 @@ class BookScanner {
|
|||||||
if (bookMetadata.series.length) {
|
if (bookMetadata.series.length) {
|
||||||
for (const seriesObj of bookMetadata.series) {
|
for (const seriesObj of bookMetadata.series) {
|
||||||
if (!seriesObj.name) continue
|
if (!seriesObj.name) continue
|
||||||
const matchingSeries = await Database.getSeriesByName(libraryItemData.libraryId, seriesObj.name)
|
const matchingSeriesId = await Database.getSeriesIdByName(libraryItemData.libraryId, seriesObj.name)
|
||||||
if (matchingSeries) {
|
if (matchingSeriesId) {
|
||||||
bookObject.bookSeries.push({
|
bookObject.bookSeries.push({
|
||||||
seriesId: matchingSeries.id,
|
seriesId: matchingSeriesId,
|
||||||
sequence: seriesObj.sequence
|
sequence: seriesObj.sequence
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user