aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users/my-history.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-12-17 15:52:38 +0100
committerChocobozzz <me@florianbigard.com>2018-12-18 11:35:50 +0100
commit8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4 (patch)
tree5e3392af5592d1401ada86d21f93bb7ad9da8ab1 /server/controllers/api/users/my-history.ts
parent583cd0d2129dc855e599f981d70e537feade1632 (diff)
downloadPeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.gz
PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.zst
PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.zip
Add history on server side
Add ability to disable, clear and list user videos history
Diffstat (limited to 'server/controllers/api/users/my-history.ts')
-rw-r--r--server/controllers/api/users/my-history.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts
new file mode 100644
index 000000000..6cd782c47
--- /dev/null
+++ b/server/controllers/api/users/my-history.ts
@@ -0,0 +1,57 @@
1import * as express from 'express'
2import {
3 asyncMiddleware,
4 asyncRetryTransactionMiddleware,
5 authenticate,
6 paginationValidator,
7 setDefaultPagination,
8 userHistoryRemoveValidator
9} from '../../../middlewares'
10import { UserModel } from '../../../models/account/user'
11import { getFormattedObjects } from '../../../helpers/utils'
12import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
13import { sequelizeTypescript } from '../../../initializers'
14
15const myVideosHistoryRouter = express.Router()
16
17myVideosHistoryRouter.get('/me/history/videos',
18 authenticate,
19 paginationValidator,
20 setDefaultPagination,
21 asyncMiddleware(listMyVideosHistory)
22)
23
24myVideosHistoryRouter.post('/me/history/videos/remove',
25 authenticate,
26 userHistoryRemoveValidator,
27 asyncRetryTransactionMiddleware(removeUserHistory)
28)
29
30// ---------------------------------------------------------------------------
31
32export {
33 myVideosHistoryRouter
34}
35
36// ---------------------------------------------------------------------------
37
38async function listMyVideosHistory (req: express.Request, res: express.Response) {
39 const user: UserModel = res.locals.oauth.token.User
40
41 const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count)
42
43 return res.json(getFormattedObjects(resultList.data, resultList.total))
44}
45
46async function removeUserHistory (req: express.Request, res: express.Response) {
47 const user: UserModel = res.locals.oauth.token.User
48 const beforeDate = req.body.beforeDate || null
49
50 await sequelizeTypescript.transaction(t => {
51 return UserVideoHistoryModel.removeHistoryBefore(user, beforeDate, t)
52 })
53
54 // Do not send the delete to other instances, we delete OUR copy of this video abuse
55
56 return res.type('json').status(204).end()
57}