aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-05 11:15:06 +0200
committerChocobozzz <me@florianbigard.com>2018-10-05 11:22:38 +0200
commit6e46de095d7169355dd83030f6ce4a582304153a (patch)
treedfa78e2008d3d135a00b798b05350b4975145acc /server/controllers/api
parenta585824160d016db7c9bff0e1cb1ffa3aaf73d74 (diff)
downloadPeerTube-6e46de095d7169355dd83030f6ce4a582304153a.tar.gz
PeerTube-6e46de095d7169355dd83030f6ce4a582304153a.tar.zst
PeerTube-6e46de095d7169355dd83030f6ce4a582304153a.zip
Add user history and resume videos
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/search.ts3
-rw-r--r--server/controllers/api/videos/captions.ts6
-rw-r--r--server/controllers/api/videos/comment.ts6
-rw-r--r--server/controllers/api/videos/index.ts6
-rw-r--r--server/controllers/api/videos/watching.ts36
5 files changed, 47 insertions, 10 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index fd4db7a54..4be2b5ef7 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -117,7 +117,8 @@ function searchVideos (req: express.Request, res: express.Response) {
117async function searchVideosDB (query: VideosSearchQuery, res: express.Response) { 117async function searchVideosDB (query: VideosSearchQuery, res: express.Response) {
118 const options = Object.assign(query, { 118 const options = Object.assign(query, {
119 includeLocalVideos: true, 119 includeLocalVideos: true,
120 nsfw: buildNSFWFilter(res, query.nsfw) 120 nsfw: buildNSFWFilter(res, query.nsfw),
121 userId: res.locals.oauth ? res.locals.oauth.token.User.id : undefined
121 }) 122 })
122 const resultList = await VideoModel.searchAndPopulateAccountAndServer(options) 123 const resultList = await VideoModel.searchAndPopulateAccountAndServer(options)
123 124
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts
index 4cf8de1ef..3ba918189 100644
--- a/server/controllers/api/videos/captions.ts
+++ b/server/controllers/api/videos/captions.ts
@@ -1,10 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 2import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
3import { 3import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators'
4 addVideoCaptionValidator,
5 deleteVideoCaptionValidator,
6 listVideoCaptionsValidator
7} from '../../../middlewares/validators/video-captions'
8import { createReqFiles } from '../../../helpers/express-utils' 4import { createReqFiles } from '../../../helpers/express-utils'
9import { CONFIG, sequelizeTypescript, VIDEO_CAPTIONS_MIMETYPE_EXT } from '../../../initializers' 5import { CONFIG, sequelizeTypescript, VIDEO_CAPTIONS_MIMETYPE_EXT } from '../../../initializers'
10import { getFormattedObjects } from '../../../helpers/utils' 6import { getFormattedObjects } from '../../../helpers/utils'
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index dc25e1e85..4f2b4faee 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -13,14 +13,14 @@ import {
13 setDefaultPagination, 13 setDefaultPagination,
14 setDefaultSort 14 setDefaultSort
15} from '../../../middlewares' 15} from '../../../middlewares'
16import { videoCommentThreadsSortValidator } from '../../../middlewares/validators'
17import { 16import {
18 addVideoCommentReplyValidator, 17 addVideoCommentReplyValidator,
19 addVideoCommentThreadValidator, 18 addVideoCommentThreadValidator,
20 listVideoCommentThreadsValidator, 19 listVideoCommentThreadsValidator,
21 listVideoThreadCommentsValidator, 20 listVideoThreadCommentsValidator,
22 removeVideoCommentValidator 21 removeVideoCommentValidator,
23} from '../../../middlewares/validators/video-comments' 22 videoCommentThreadsSortValidator
23} from '../../../middlewares/validators'
24import { VideoModel } from '../../../models/video/video' 24import { VideoModel } from '../../../models/video/video'
25import { VideoCommentModel } from '../../../models/video/video-comment' 25import { VideoCommentModel } from '../../../models/video/video-comment'
26import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' 26import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 15ef8d458..6a73e13d0 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -57,6 +57,7 @@ import { videoCaptionsRouter } from './captions'
57import { videoImportsRouter } from './import' 57import { videoImportsRouter } from './import'
58import { resetSequelizeInstance } from '../../../helpers/database-utils' 58import { resetSequelizeInstance } from '../../../helpers/database-utils'
59import { rename } from 'fs-extra' 59import { rename } from 'fs-extra'
60import { watchingRouter } from './watching'
60 61
61const auditLogger = auditLoggerFactory('videos') 62const auditLogger = auditLoggerFactory('videos')
62const videosRouter = express.Router() 63const videosRouter = express.Router()
@@ -86,6 +87,7 @@ videosRouter.use('/', videoCommentRouter)
86videosRouter.use('/', videoCaptionsRouter) 87videosRouter.use('/', videoCaptionsRouter)
87videosRouter.use('/', videoImportsRouter) 88videosRouter.use('/', videoImportsRouter)
88videosRouter.use('/', ownershipVideoRouter) 89videosRouter.use('/', ownershipVideoRouter)
90videosRouter.use('/', watchingRouter)
89 91
90videosRouter.get('/categories', listVideoCategories) 92videosRouter.get('/categories', listVideoCategories)
91videosRouter.get('/licences', listVideoLicences) 93videosRouter.get('/licences', listVideoLicences)
@@ -119,6 +121,7 @@ videosRouter.get('/:id/description',
119 asyncMiddleware(getVideoDescription) 121 asyncMiddleware(getVideoDescription)
120) 122)
121videosRouter.get('/:id', 123videosRouter.get('/:id',
124 optionalAuthenticate,
122 asyncMiddleware(videosGetValidator), 125 asyncMiddleware(videosGetValidator),
123 getVideo 126 getVideo
124) 127)
@@ -433,7 +436,8 @@ async function listVideos (req: express.Request, res: express.Response, next: ex
433 tagsAllOf: req.query.tagsAllOf, 436 tagsAllOf: req.query.tagsAllOf,
434 nsfw: buildNSFWFilter(res, req.query.nsfw), 437 nsfw: buildNSFWFilter(res, req.query.nsfw),
435 filter: req.query.filter as VideoFilter, 438 filter: req.query.filter as VideoFilter,
436 withFiles: false 439 withFiles: false,
440 userId: res.locals.oauth ? res.locals.oauth.token.User.id : undefined
437 }) 441 })
438 442
439 return res.json(getFormattedObjects(resultList.data, resultList.total)) 443 return res.json(getFormattedObjects(resultList.data, resultList.total))
diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts
new file mode 100644
index 000000000..e8876b47a
--- /dev/null
+++ b/server/controllers/api/videos/watching.ts
@@ -0,0 +1,36 @@
1import * as express from 'express'
2import { UserWatchingVideo } from '../../../../shared'
3import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares'
4import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
5import { UserModel } from '../../../models/account/user'
6
7const watchingRouter = express.Router()
8
9watchingRouter.put('/:videoId/watching',
10 authenticate,
11 asyncMiddleware(videoWatchingValidator),
12 asyncRetryTransactionMiddleware(userWatchVideo)
13)
14
15// ---------------------------------------------------------------------------
16
17export {
18 watchingRouter
19}
20
21// ---------------------------------------------------------------------------
22
23async function userWatchVideo (req: express.Request, res: express.Response) {
24 const user = res.locals.oauth.token.User as UserModel
25
26 const body: UserWatchingVideo = req.body
27 const { id: videoId } = res.locals.video as { id: number }
28
29 await UserVideoHistoryModel.upsert({
30 videoId,
31 userId: user.id,
32 currentTime: body.currentTime
33 })
34
35 return res.type('json').status(204).end()
36}