mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-13 23:11:29 +00:00
Add favorite property for items and associated filters.
This commit is contained in:
parent
6d3773a0b8
commit
a5999fb9df
14 changed files with 308 additions and 11 deletions
|
|
@ -106,7 +106,11 @@ module.exports = {
|
|||
let mediaWhere = {}
|
||||
const replacements = {}
|
||||
|
||||
if (group === 'progress') {
|
||||
if (group === 'favorite') {
|
||||
mediaWhere['$libraryItem.userFavorites.userId$'] = {
|
||||
[Sequelize.Op.not]: null
|
||||
}
|
||||
} else if (group === 'progress') {
|
||||
if (value === 'not-finished') {
|
||||
mediaWhere['$mediaProgresses.isFinished$'] = {
|
||||
[Sequelize.Op.or]: [null, false]
|
||||
|
|
@ -531,6 +535,15 @@ module.exports = {
|
|||
libraryItemWhere['createdAt'] = {
|
||||
[Sequelize.Op.gte]: new Date(new Date() - 60 * 24 * 60 * 60 * 1000) // 60 days ago
|
||||
}
|
||||
} else if (filterGroup === 'favorite' && user) {
|
||||
libraryItemIncludes.push({
|
||||
model: Database.userFavoriteModel,
|
||||
attributes: ['userId'],
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
required: true
|
||||
})
|
||||
}
|
||||
|
||||
// When sorting by progress but not filtering by progress, include media progresses
|
||||
|
|
|
|||
|
|
@ -52,7 +52,11 @@ module.exports = {
|
|||
let mediaWhere = {}
|
||||
const replacements = {}
|
||||
|
||||
if (['genres', 'tags'].includes(group)) {
|
||||
if (group === 'favorite') {
|
||||
mediaWhere['$libraryItem.userFavorites.userId$'] = {
|
||||
[Sequelize.Op.not]: null
|
||||
}
|
||||
} else if (['genres', 'tags'].includes(group)) {
|
||||
mediaWhere[group] = Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(${group}) WHERE json_valid(${group}) AND json_each.value = :filterValue)`), {
|
||||
[Sequelize.Op.gte]: 1
|
||||
})
|
||||
|
|
@ -172,6 +176,15 @@ module.exports = {
|
|||
libraryItemWhere['createdAt'] = {
|
||||
[Sequelize.Op.gte]: new Date(new Date() - 60 * 24 * 60 * 60 * 1000) // 60 days ago
|
||||
}
|
||||
} else if (filterGroup === 'favorite' && user) {
|
||||
libraryItemIncludes.push({
|
||||
model: Database.userFavoriteModel,
|
||||
attributes: ['userId'],
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
required: true
|
||||
})
|
||||
}
|
||||
|
||||
const podcastIncludes = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue