1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add ability to delete history element

This commit is contained in:
Chocobozzz 2022-01-18 11:23:41 +01:00
parent 3b83faccff
commit 7177b46ca1
No known key found for this signature in database
GPG key ID: 583A612D890159BE
11 changed files with 181 additions and 26 deletions

View 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