diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-17 15:52:38 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-18 11:35:50 +0100 |
commit | 8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4 (patch) | |
tree | 5e3392af5592d1401ada86d21f93bb7ad9da8ab1 /server/controllers | |
parent | 583cd0d2129dc855e599f981d70e537feade1632 (diff) | |
download | PeerTube-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')
-rw-r--r-- | server/controllers/api/users/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/users/me.ts | 1 | ||||
-rw-r--r-- | server/controllers/api/users/my-history.ts | 57 |
3 files changed, 60 insertions, 0 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 87fab4a40..bc24792a2 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -38,6 +38,7 @@ import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../h | |||
38 | import { meRouter } from './me' | 38 | import { meRouter } from './me' |
39 | import { deleteUserToken } from '../../../lib/oauth-model' | 39 | import { deleteUserToken } from '../../../lib/oauth-model' |
40 | import { myBlocklistRouter } from './my-blocklist' | 40 | import { myBlocklistRouter } from './my-blocklist' |
41 | import { myVideosHistoryRouter } from './my-history' | ||
41 | 42 | ||
42 | const auditLogger = auditLoggerFactory('users') | 43 | const auditLogger = auditLoggerFactory('users') |
43 | 44 | ||
@@ -55,6 +56,7 @@ const askSendEmailLimiter = new RateLimit({ | |||
55 | 56 | ||
56 | const usersRouter = express.Router() | 57 | const usersRouter = express.Router() |
57 | usersRouter.use('/', myBlocklistRouter) | 58 | usersRouter.use('/', myBlocklistRouter) |
59 | usersRouter.use('/', myVideosHistoryRouter) | ||
58 | usersRouter.use('/', meRouter) | 60 | usersRouter.use('/', meRouter) |
59 | 61 | ||
60 | usersRouter.get('/autocomplete', | 62 | usersRouter.get('/autocomplete', |
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index f712b0f0b..8a3208160 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -330,6 +330,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
330 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy | 330 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy |
331 | if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled | 331 | if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled |
332 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 332 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
333 | if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled | ||
333 | 334 | ||
334 | await sequelizeTypescript.transaction(async t => { | 335 | await sequelizeTypescript.transaction(async t => { |
335 | const userAccount = await AccountModel.load(user.Account.id) | 336 | const userAccount = await AccountModel.load(user.Account.id) |
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { | ||
3 | asyncMiddleware, | ||
4 | asyncRetryTransactionMiddleware, | ||
5 | authenticate, | ||
6 | paginationValidator, | ||
7 | setDefaultPagination, | ||
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' | ||
14 | |||
15 | const myVideosHistoryRouter = express.Router() | ||
16 | |||
17 | myVideosHistoryRouter.get('/me/history/videos', | ||
18 | authenticate, | ||
19 | paginationValidator, | ||
20 | setDefaultPagination, | ||
21 | asyncMiddleware(listMyVideosHistory) | ||
22 | ) | ||
23 | |||
24 | myVideosHistoryRouter.post('/me/history/videos/remove', | ||
25 | authenticate, | ||
26 | userHistoryRemoveValidator, | ||
27 | asyncRetryTransactionMiddleware(removeUserHistory) | ||
28 | ) | ||
29 | |||
30 | // --------------------------------------------------------------------------- | ||
31 | |||
32 | export { | ||
33 | myVideosHistoryRouter | ||
34 | } | ||
35 | |||
36 | // --------------------------------------------------------------------------- | ||
37 | |||
38 | async 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 | |||
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 | ||
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 | } | ||