mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-17 00:41:30 +00:00
Merge ac841856df into 47ea6b5092
This commit is contained in:
commit
8e28f36579
15 changed files with 310 additions and 12 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class UserController {
|
|||
|
||||
const includes = (req.query.include || '').split(',').map((i) => i.trim())
|
||||
|
||||
// Minimal toJSONForBrowser does not include mediaProgress and bookmarks
|
||||
// Minimal toJSONForBrowser does not include mediaProgress, bookmarks and favorites
|
||||
const allUsers = await Database.userModel.findAll()
|
||||
const users = allUsers.map((u) => u.toOldJSONForBrowser(hideRootToken, true))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue