]>
Commit | Line | Data |
---|---|---|
8b9a525a C |
1 | import * as express from 'express' |
2 | import { | |
3 | asyncMiddleware, | |
4 | asyncRetryTransactionMiddleware, | |
5 | authenticate, | |
6 | paginationValidator, | |
7 | setDefaultPagination, | |
8 | userHistoryRemoveValidator | |
9 | } from '../../../middlewares' | |
8b9a525a C |
10 | import { getFormattedObjects } from '../../../helpers/utils' |
11 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' | |
12 | import { sequelizeTypescript } from '../../../initializers' | |
13 | ||
14 | const myVideosHistoryRouter = express.Router() | |
15 | ||
16 | myVideosHistoryRouter.get('/me/history/videos', | |
17 | authenticate, | |
18 | paginationValidator, | |
19 | setDefaultPagination, | |
20 | asyncMiddleware(listMyVideosHistory) | |
21 | ) | |
22 | ||
23 | myVideosHistoryRouter.post('/me/history/videos/remove', | |
24 | authenticate, | |
25 | userHistoryRemoveValidator, | |
26 | asyncRetryTransactionMiddleware(removeUserHistory) | |
27 | ) | |
28 | ||
29 | // --------------------------------------------------------------------------- | |
30 | ||
31 | export { | |
32 | myVideosHistoryRouter | |
33 | } | |
34 | ||
35 | // --------------------------------------------------------------------------- | |
36 | ||
37 | async function listMyVideosHistory (req: express.Request, res: express.Response) { | |
dae86118 | 38 | const user = res.locals.oauth.token.User |
8b9a525a C |
39 | |
40 | const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count) | |
41 | ||
42 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | |
43 | } | |
44 | ||
45 | async function removeUserHistory (req: express.Request, res: express.Response) { | |
dae86118 | 46 | const user = res.locals.oauth.token.User |
8b9a525a C |
47 | const beforeDate = req.body.beforeDate || null |
48 | ||
49 | await sequelizeTypescript.transaction(t => { | |
8f0bc73d | 50 | return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t) |
8b9a525a C |
51 | }) |
52 | ||
53 | // Do not send the delete to other instances, we delete OUR copy of this video abuse | |
54 | ||
55 | return res.type('json').status(204).end() | |
56 | } |