1 import * as express from 'express'
4 asyncRetryTransactionMiddleware,
8 userHistoryRemoveValidator
9 } from '../../../middlewares'
10 import { UserModel } from '../../../models/account/user'
11 import { getFormattedObjects } from '../../../helpers/utils'
12 import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
13 import { sequelizeTypescript } from '../../../initializers'
15 const myVideosHistoryRouter = express.Router()
17 myVideosHistoryRouter.get('/me/history/videos',
21 asyncMiddleware(listMyVideosHistory)
24 myVideosHistoryRouter.post('/me/history/videos/remove',
26 userHistoryRemoveValidator,
27 asyncRetryTransactionMiddleware(removeUserHistory)
30 // ---------------------------------------------------------------------------
36 // ---------------------------------------------------------------------------
38 async function listMyVideosHistory (req: express.Request, res: express.Response) {
39 const user: UserModel = res.locals.oauth.token.User
41 const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count)
43 return res.json(getFormattedObjects(resultList.data, resultList.total))
46 async function removeUserHistory (req: express.Request, res: express.Response) {
47 const user: UserModel = res.locals.oauth.token.User
48 const beforeDate = req.body.beforeDate || null
50 await sequelizeTypescript.transaction(t => {
51 return UserVideoHistoryModel.removeHistoryBefore(user, beforeDate, t)
54 // Do not send the delete to other instances, we delete OUR copy of this video abuse
56 return res.type('json').status(204).end()