Add favorite property for items and associated filters.

This commit is contained in:
Rapha149 2026-03-16 19:46:45 +01:00
parent 6d3773a0b8
commit a5999fb9df
14 changed files with 308 additions and 11 deletions

View file

@ -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

View file

@ -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 = []