diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-05 11:15:06 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-05 11:22:38 +0200 |
commit | 6e46de095d7169355dd83030f6ce4a582304153a (patch) | |
tree | dfa78e2008d3d135a00b798b05350b4975145acc /server/controllers/api | |
parent | a585824160d016db7c9bff0e1cb1ffa3aaf73d74 (diff) | |
download | PeerTube-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.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/videos/captions.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/watching.ts | 36 |
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) { | |||
117 | async function searchVideosDB (query: VideosSearchQuery, res: express.Response) { | 117 | async 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' | 2 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' |
3 | import { | 3 | import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' |
4 | addVideoCaptionValidator, | ||
5 | deleteVideoCaptionValidator, | ||
6 | listVideoCaptionsValidator | ||
7 | } from '../../../middlewares/validators/video-captions' | ||
8 | import { createReqFiles } from '../../../helpers/express-utils' | 4 | import { createReqFiles } from '../../../helpers/express-utils' |
9 | import { CONFIG, sequelizeTypescript, VIDEO_CAPTIONS_MIMETYPE_EXT } from '../../../initializers' | 5 | import { CONFIG, sequelizeTypescript, VIDEO_CAPTIONS_MIMETYPE_EXT } from '../../../initializers' |
10 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { 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' |
16 | import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' | ||
17 | import { | 16 | import { |
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' | ||
24 | import { VideoModel } from '../../../models/video/video' | 24 | import { VideoModel } from '../../../models/video/video' |
25 | import { VideoCommentModel } from '../../../models/video/video-comment' | 25 | import { VideoCommentModel } from '../../../models/video/video-comment' |
26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | 26 | import { 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' | |||
57 | import { videoImportsRouter } from './import' | 57 | import { videoImportsRouter } from './import' |
58 | import { resetSequelizeInstance } from '../../../helpers/database-utils' | 58 | import { resetSequelizeInstance } from '../../../helpers/database-utils' |
59 | import { rename } from 'fs-extra' | 59 | import { rename } from 'fs-extra' |
60 | import { watchingRouter } from './watching' | ||
60 | 61 | ||
61 | const auditLogger = auditLoggerFactory('videos') | 62 | const auditLogger = auditLoggerFactory('videos') |
62 | const videosRouter = express.Router() | 63 | const videosRouter = express.Router() |
@@ -86,6 +87,7 @@ videosRouter.use('/', videoCommentRouter) | |||
86 | videosRouter.use('/', videoCaptionsRouter) | 87 | videosRouter.use('/', videoCaptionsRouter) |
87 | videosRouter.use('/', videoImportsRouter) | 88 | videosRouter.use('/', videoImportsRouter) |
88 | videosRouter.use('/', ownershipVideoRouter) | 89 | videosRouter.use('/', ownershipVideoRouter) |
90 | videosRouter.use('/', watchingRouter) | ||
89 | 91 | ||
90 | videosRouter.get('/categories', listVideoCategories) | 92 | videosRouter.get('/categories', listVideoCategories) |
91 | videosRouter.get('/licences', listVideoLicences) | 93 | videosRouter.get('/licences', listVideoLicences) |
@@ -119,6 +121,7 @@ videosRouter.get('/:id/description', | |||
119 | asyncMiddleware(getVideoDescription) | 121 | asyncMiddleware(getVideoDescription) |
120 | ) | 122 | ) |
121 | videosRouter.get('/:id', | 123 | videosRouter.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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { UserWatchingVideo } from '../../../../shared' | ||
3 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares' | ||
4 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' | ||
5 | import { UserModel } from '../../../models/account/user' | ||
6 | |||
7 | const watchingRouter = express.Router() | ||
8 | |||
9 | watchingRouter.put('/:videoId/watching', | ||
10 | authenticate, | ||
11 | asyncMiddleware(videoWatchingValidator), | ||
12 | asyncRetryTransactionMiddleware(userWatchVideo) | ||
13 | ) | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | watchingRouter | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | async 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 | } | ||