mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-16 02:09:33 +01:00
Fix:Only show authors with books for users #2250
This commit is contained in:
parent
0ee6336b02
commit
ef1cdf6ad2
@ -621,7 +621,7 @@ class LibraryController {
|
|||||||
model: Database.bookModel,
|
model: Database.bookModel,
|
||||||
attributes: ['id', 'tags', 'explicit'],
|
attributes: ['id', 'tags', 'explicit'],
|
||||||
where: bookWhere,
|
where: bookWhere,
|
||||||
required: false,
|
required: !req.user.isAdminOrUp, // Only show authors with 0 books for admin users or up
|
||||||
through: {
|
through: {
|
||||||
attributes: []
|
attributes: []
|
||||||
}
|
}
|
||||||
|
@ -308,6 +308,8 @@ module.exports = {
|
|||||||
async getNewestAuthors(library, user, limit) {
|
async getNewestAuthors(library, user, limit) {
|
||||||
if (library.mediaType !== 'book') return { authors: [], count: 0 }
|
if (library.mediaType !== 'book') return { authors: [], count: 0 }
|
||||||
|
|
||||||
|
const { bookWhere, replacements } = libraryItemsBookFilters.getUserPermissionBookWhereQuery(user)
|
||||||
|
|
||||||
const { rows: authors, count } = await Database.authorModel.findAndCountAll({
|
const { rows: authors, count } = await Database.authorModel.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
libraryId: library.id,
|
libraryId: library.id,
|
||||||
@ -315,9 +317,15 @@ module.exports = {
|
|||||||
[Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
|
[Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
replacements,
|
||||||
include: {
|
include: {
|
||||||
model: Database.bookAuthorModel,
|
model: Database.bookModel,
|
||||||
required: true // Must belong to a book
|
attributes: ['id', 'tags', 'explicit'],
|
||||||
|
where: bookWhere,
|
||||||
|
required: true, // Must belong to a book
|
||||||
|
through: {
|
||||||
|
attributes: []
|
||||||
|
}
|
||||||
},
|
},
|
||||||
limit,
|
limit,
|
||||||
distinct: true,
|
distinct: true,
|
||||||
@ -328,7 +336,7 @@ module.exports = {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
authors: authors.map((au) => {
|
authors: authors.map((au) => {
|
||||||
const numBooks = au.bookAuthors?.length || 0
|
const numBooks = au.books.length || 0
|
||||||
return au.getOldAuthor().toJSONExpanded(numBooks)
|
return au.getOldAuthor().toJSONExpanded(numBooks)
|
||||||
}),
|
}),
|
||||||
count
|
count
|
||||||
|
Loading…
Reference in New Issue
Block a user