]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users/my-history.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users / my-history.ts
index 2fcb25acf5d3540bf9696f61ed9ee842da500ba5..bc5b40f59ab3446fd1affa7699e312fa264d3ec8 100644 (file)
@@ -9,7 +9,8 @@ import {
   paginationValidator,
   setDefaultPagination,
   userHistoryListValidator,
-  userHistoryRemoveValidator
+  userHistoryRemoveAllValidator,
+  userHistoryRemoveElementValidator
 } from '../../../middlewares'
 import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
 
@@ -23,10 +24,16 @@ myVideosHistoryRouter.get('/me/history/videos',
   asyncMiddleware(listMyVideosHistory)
 )
 
+myVideosHistoryRouter.delete('/me/history/videos/:videoId',
+  authenticate,
+  userHistoryRemoveElementValidator,
+  asyncMiddleware(removeUserHistoryElement)
+)
+
 myVideosHistoryRouter.post('/me/history/videos/remove',
   authenticate,
-  userHistoryRemoveValidator,
-  asyncRetryTransactionMiddleware(removeUserHistory)
+  userHistoryRemoveAllValidator,
+  asyncRetryTransactionMiddleware(removeAllUserHistory)
 )
 
 // ---------------------------------------------------------------------------
@@ -45,7 +52,15 @@ async function listMyVideosHistory (req: express.Request, res: express.Response)
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
 
-async function removeUserHistory (req: express.Request, res: express.Response) {
+async function removeUserHistoryElement (req: express.Request, res: express.Response) {
+  const user = res.locals.oauth.token.User
+
+  await UserVideoHistoryModel.removeUserHistoryElement(user, parseInt(req.params.videoId + ''))
+
+  return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+}
+
+async function removeAllUserHistory (req: express.Request, res: express.Response) {
   const user = res.locals.oauth.token.User
   const beforeDate = req.body.beforeDate || null