Update author API endpoints to load library items from DB

This commit is contained in:
advplyr 2023-08-06 15:06:45 -05:00
parent 56e3449db6
commit 345ff1aa66
5 changed files with 80 additions and 22 deletions

View file

@ -357,5 +357,21 @@ module.exports = {
return oldLibraryItem
})
}
},
/**
* Get library items for an author, optional use user permissions
* @param {oldAuthor} author
* @param {[oldUser]} user
* @param {number} limit
* @param {number} offset
* @returns {object} { libraryItems:LibraryItem[], count:number }
*/
async getLibraryItemsForAuthor(author, user, limit, offset) {
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(author.libraryId, user, 'authors', author.id, 'addedAt', true, false, [], limit, offset)
return {
count,
libraryItems
}
}
}

View file

@ -11,6 +11,8 @@ module.exports = {
getUserPermissionBookWhereQuery(user) {
const bookWhere = []
const replacements = {}
if (!user) return { bookWhere, replacements }
if (!user.canAccessExplicitContent) {
bookWhere.push({
explicit: false
@ -325,7 +327,7 @@ module.exports = {
/**
* Get library items for book media type using filter and sort
* @param {string} libraryId
* @param {oldUser} user
* @param {[oldUser]} user
* @param {[string]} filterGroup
* @param {[string]} filterValue
* @param {string} sortBy
@ -467,7 +469,7 @@ module.exports = {
isInvalid: true
}
]
} else if (filterGroup === 'progress') {
} else if (filterGroup === 'progress' && user) {
bookIncludes.push({
model: Database.models.mediaProgress,
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt'],