mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-13 06:51: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
|
|
@ -198,6 +198,67 @@ class MeController {
|
|||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* POST: /api/me/item/:id/favorite
|
||||
*
|
||||
* @param {RequestWithUser} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async addFavorite(req, res) {
|
||||
const libraryItemId = req.params.id
|
||||
await Database.userFavoriteModel.create({
|
||||
userId: req.user.id,
|
||||
libraryItemId
|
||||
})
|
||||
|
||||
// Reload favorites for the user
|
||||
await req.user.reload({
|
||||
include: [
|
||||
Database.mediaProgressModel,
|
||||
{
|
||||
model: Database.libraryItemModel,
|
||||
as: 'favorites',
|
||||
attributes: ['id'],
|
||||
through: { attributes: [] }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
SocketAuthority.clientEmitter(req.user.id, 'user_updated', req.user.toOldJSONForBrowser())
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE: /api/me/item/:id/favorite
|
||||
*
|
||||
* @param {RequestWithUser} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async removeFavorite(req, res) {
|
||||
const libraryItemId = req.params.id
|
||||
await Database.userFavoriteModel.destroy({
|
||||
where: { userId: req.user.id, libraryItemId }
|
||||
})
|
||||
|
||||
// Reload favorites for the user
|
||||
await req.user.reload({
|
||||
include: [
|
||||
Database.mediaProgressModel,
|
||||
{
|
||||
model: Database.libraryItemModel,
|
||||
as: 'favorites',
|
||||
attributes: ['id'],
|
||||
through: { attributes: [] }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
SocketAuthority.clientEmitter(req.user.id, 'user_updated', req.user.toOldJSONForBrowser())
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* POST: /api/me/item/:id/bookmark
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue