X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers.js;h=f854b30826697269d12520bb7b4d1da73dbfcb0a;hb=d38b82810638b9f664c9016fac2684454c273a77;hp=324c99b4cce8ab9d3730ed36d049e160149f50eb;hpb=ad4a8a1cca1049f600ebcdce9260c1021cd821a5;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users.js b/server/controllers/api/users.js index 324c99b4c..f854b3082 100644 --- a/server/controllers/api/users.js +++ b/server/controllers/api/users.js @@ -18,7 +18,16 @@ const validatorsUsers = middlewares.validators.users const router = express.Router() -router.get('/me', oAuth.authenticate, getUserInformation) +router.get('/me', + oAuth.authenticate, + getUserInformation +) + +router.get('/me/videos/:videoId/rating', + oAuth.authenticate, + validatorsUsers.usersVideoRating, + getUserVideoRating +) router.get('/', validatorsPagination.pagination, @@ -80,6 +89,22 @@ function getUserInformation (req, res, next) { }) } +function getUserVideoRating (req, res, next) { + const videoId = req.params.videoId + const userId = res.locals.oauth.token.User.id + + db.UserVideoRate.load(userId, videoId, function (err, ratingObj) { + if (err) return next(err) + + const rating = ratingObj ? ratingObj.type : 'none' + + res.json({ + videoId, + rating + }) + }) +} + function listUsers (req, res, next) { db.User.listForApi(req.query.start, req.query.count, req.query.sort, function (err, usersList, usersTotal) { if (err) return next(err)