aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-01-18 11:23:41 +0100
committerChocobozzz <me@florianbigard.com>2022-01-18 11:23:41 +0100
commit7177b46ca1b35aa9d7ed39a06c1dcf41a4fc6180 (patch)
tree016cb0d966fe9fea8a6381eb246e966f5c4eae57 /server/controllers/api
parent3b83faccfffc13adaef0b63c211b1ce4944e8b3b (diff)
downloadPeerTube-7177b46ca1b35aa9d7ed39a06c1dcf41a4fc6180.tar.gz
PeerTube-7177b46ca1b35aa9d7ed39a06c1dcf41a4fc6180.tar.zst
PeerTube-7177b46ca1b35aa9d7ed39a06c1dcf41a4fc6180.zip
Add ability to delete history element
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/my-history.ts23
1 files changed, 19 insertions, 4 deletions
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts
index 2fcb25acf..bc5b40f59 100644
--- a/server/controllers/api/users/my-history.ts
+++ b/server/controllers/api/users/my-history.ts
@@ -9,7 +9,8 @@ import {
9 paginationValidator, 9 paginationValidator,
10 setDefaultPagination, 10 setDefaultPagination,
11 userHistoryListValidator, 11 userHistoryListValidator,
12 userHistoryRemoveValidator 12 userHistoryRemoveAllValidator,
13 userHistoryRemoveElementValidator
13} from '../../../middlewares' 14} from '../../../middlewares'
14import { UserVideoHistoryModel } from '../../../models/user/user-video-history' 15import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
15 16
@@ -23,10 +24,16 @@ myVideosHistoryRouter.get('/me/history/videos',
23 asyncMiddleware(listMyVideosHistory) 24 asyncMiddleware(listMyVideosHistory)
24) 25)
25 26
27myVideosHistoryRouter.delete('/me/history/videos/:videoId',
28 authenticate,
29 userHistoryRemoveElementValidator,
30 asyncMiddleware(removeUserHistoryElement)
31)
32
26myVideosHistoryRouter.post('/me/history/videos/remove', 33myVideosHistoryRouter.post('/me/history/videos/remove',
27 authenticate, 34 authenticate,
28 userHistoryRemoveValidator, 35 userHistoryRemoveAllValidator,
29 asyncRetryTransactionMiddleware(removeUserHistory) 36 asyncRetryTransactionMiddleware(removeAllUserHistory)
30) 37)
31 38
32// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
@@ -45,7 +52,15 @@ async function listMyVideosHistory (req: express.Request, res: express.Response)
45 return res.json(getFormattedObjects(resultList.data, resultList.total)) 52 return res.json(getFormattedObjects(resultList.data, resultList.total))
46} 53}
47 54
48async function removeUserHistory (req: express.Request, res: express.Response) { 55async function removeUserHistoryElement (req: express.Request, res: express.Response) {
56 const user = res.locals.oauth.token.User
57
58 await UserVideoHistoryModel.removeUserHistoryElement(user, parseInt(req.params.videoId + ''))
59
60 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
61}
62
63async function removeAllUserHistory (req: express.Request, res: express.Response) {
49 const user = res.locals.oauth.token.User 64 const user = res.locals.oauth.token.User
50 const beforeDate = req.body.beforeDate || null 65 const beforeDate = req.body.beforeDate || null
51 66