Skip to content

Commit

Permalink
Update more API endpoints to use new user model
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Aug 11, 2024
1 parent 9facf77 commit afc1635
Show file tree
Hide file tree
Showing 23 changed files with 855 additions and 403 deletions.
2 changes: 1 addition & 1 deletion server/controllers/AuthorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class AuthorController {
if (req.method == 'DELETE' && !req.userNew.canDelete) {
Logger.warn(`[AuthorController] User "${req.userNew.username}" attempted to delete without permission`)
return res.sendStatus(403)
} else if ((req.method == 'PATCH' || req.method == 'POST') && !req.user.canUpdate) {
} else if ((req.method == 'PATCH' || req.method == 'POST') && !req.userNew.canUpdate) {
Logger.warn(`[AuthorController] User "${req.userNew.username}" attempted to update without permission`)
return res.sendStatus(403)
}
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/CollectionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class CollectionController {
if (req.method == 'DELETE' && !req.userNew.canDelete) {
Logger.warn(`[CollectionController] User "${req.userNew.username}" attempted to delete without permission`)
return res.sendStatus(403)
} else if ((req.method == 'PATCH' || req.method == 'POST') && !req.user.canUpdate) {
} else if ((req.method == 'PATCH' || req.method == 'POST') && !req.userNew.canUpdate) {
Logger.warn(`[CollectionController] User "${req.userNew.username}" attempted to update without permission`)
return res.sendStatus(403)
}
Expand Down
29 changes: 26 additions & 3 deletions server/controllers/LibraryItemController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { Request, Response, NextFunction } = require('express')
const Path = require('path')
const fs = require('../libs/fsExtra')
const Logger = require('../Logger')
Expand All @@ -15,6 +16,14 @@ const CacheManager = require('../managers/CacheManager')
const CoverManager = require('../managers/CoverManager')
const ShareManager = require('../managers/ShareManager')

/**
* @typedef RequestUserObjects
* @property {import('../models/User')} userNew
* @property {import('../objects/user/User')} user
*
* @typedef {Request & RequestUserObjects} RequestWithUser
*/

class LibraryItemController {
constructor() {}

Expand Down Expand Up @@ -328,7 +337,14 @@ class LibraryItemController {
return CacheManager.handleCoverCache(res, libraryItem.id, libraryItem.media.coverPath, options)
}

// POST: api/items/:id/play
/**
* POST: /api/items/:id/play
*
* @this {import('../routers/ApiRouter')}
*
* @param {RequestWithUser} req
* @param {Response} res
*/
startPlaybackSession(req, res) {
if (!req.libraryItem.media.numTracks && req.libraryItem.mediaType !== 'video') {
Logger.error(`[LibraryItemController] startPlaybackSession cannot playback ${req.libraryItem.id}`)
Expand All @@ -338,7 +354,14 @@ class LibraryItemController {
this.playbackSessionManager.startSessionRequest(req, res, null)
}

// POST: api/items/:id/play/:episodeId
/**
* POST: /api/items/:id/play/:episodeId
*
* @this {import('../routers/ApiRouter')}
*
* @param {RequestWithUser} req
* @param {Response} res
*/
startEpisodePlaybackSession(req, res) {
var libraryItem = req.libraryItem
if (!libraryItem.media.numTracks) {
Expand Down Expand Up @@ -830,7 +853,7 @@ class LibraryItemController {
} else if (req.method == 'DELETE' && !req.userNew.canDelete) {
Logger.warn(`[LibraryItemController] User "${req.userNew.username}" attempted to delete without permission`)
return res.sendStatus(403)
} else if ((req.method == 'PATCH' || req.method == 'POST') && !req.user.canUpdate) {
} else if ((req.method == 'PATCH' || req.method == 'POST') && !req.userNew.canUpdate) {
Logger.warn(`[LibraryItemController] User "${req.userNew.username}" attempted to update without permission`)
return res.sendStatus(403)
}
Expand Down
1 change: 0 additions & 1 deletion server/controllers/MeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const userStats = require('../utils/queries/userStats')
* @property {import('../objects/user/User')} user
*
* @typedef {Request & RequestUserObjects} RequestWithUser
*
*/

class MeController {
Expand Down
Loading

0 comments on commit afc1635

Please sign in to comment.