aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-31 11:52:52 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-10-31 11:53:13 +0100
commitfd45e8f43c2638478599ca75632518054461da85 (patch)
tree01e1fb5ddad53bde8fb2c48f348fb8add51cfdb3 /server/controllers
parentb7a485121d71c95fcf5e432e4cc745cf91af4f93 (diff)
downloadPeerTube-fd45e8f43c2638478599ca75632518054461da85.tar.gz
PeerTube-fd45e8f43c2638478599ca75632518054461da85.tar.zst
PeerTube-fd45e8f43c2638478599ca75632518054461da85.zip
Add video privacy setting
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/remote/videos.ts4
-rw-r--r--server/controllers/api/users.ts21
-rw-r--r--server/controllers/api/videos/index.ts28
3 files changed, 46 insertions, 7 deletions
diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts
index 3ecc62ada..cba47f0a1 100644
--- a/server/controllers/api/remote/videos.ts
+++ b/server/controllers/api/remote/videos.ts
@@ -267,7 +267,8 @@ async function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod
267 views: videoToCreateData.views, 267 views: videoToCreateData.views,
268 likes: videoToCreateData.likes, 268 likes: videoToCreateData.likes,
269 dislikes: videoToCreateData.dislikes, 269 dislikes: videoToCreateData.dislikes,
270 remote: true 270 remote: true,
271 privacy: videoToCreateData.privacy
271 } 272 }
272 273
273 const video = db.Video.build(videoData) 274 const video = db.Video.build(videoData)
@@ -334,6 +335,7 @@ async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData
334 videoInstance.set('views', videoAttributesToUpdate.views) 335 videoInstance.set('views', videoAttributesToUpdate.views)
335 videoInstance.set('likes', videoAttributesToUpdate.likes) 336 videoInstance.set('likes', videoAttributesToUpdate.likes)
336 videoInstance.set('dislikes', videoAttributesToUpdate.dislikes) 337 videoInstance.set('dislikes', videoAttributesToUpdate.dislikes)
338 videoInstance.set('privacy', videoAttributesToUpdate.privacy)
337 339
338 await videoInstance.save(sequelizeOptions) 340 await videoInstance.save(sequelizeOptions)
339 341
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index fdc9b0c87..dcd407fdf 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -30,6 +30,8 @@ import {
30} from '../../../shared' 30} from '../../../shared'
31import { createUserAuthorAndChannel } from '../../lib' 31import { createUserAuthorAndChannel } from '../../lib'
32import { UserInstance } from '../../models' 32import { UserInstance } from '../../models'
33import { videosSortValidator } from '../../middlewares/validators/sort'
34import { setVideosSort } from '../../middlewares/sort'
33 35
34const usersRouter = express.Router() 36const usersRouter = express.Router()
35 37
@@ -38,6 +40,15 @@ usersRouter.get('/me',
38 asyncMiddleware(getUserInformation) 40 asyncMiddleware(getUserInformation)
39) 41)
40 42
43usersRouter.get('/me/videos',
44 authenticate,
45 paginationValidator,
46 videosSortValidator,
47 setVideosSort,
48 setPagination,
49 asyncMiddleware(getUserVideos)
50)
51
41usersRouter.get('/me/videos/:videoId/rating', 52usersRouter.get('/me/videos/:videoId/rating',
42 authenticate, 53 authenticate,
43 usersVideoRatingValidator, 54 usersVideoRatingValidator,
@@ -101,6 +112,13 @@ export {
101 112
102// --------------------------------------------------------------------------- 113// ---------------------------------------------------------------------------
103 114
115async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
116 const user = res.locals.oauth.token.User
117 const resultList = await db.Video.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort)
118
119 return res.json(getFormattedObjects(resultList.data, resultList.total))
120}
121
104async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 122async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
105 const options = { 123 const options = {
106 arguments: [ req, res ], 124 arguments: [ req, res ],
@@ -146,13 +164,14 @@ async function registerUser (req: express.Request, res: express.Response, next:
146} 164}
147 165
148async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { 166async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
167 // We did not load channels in res.locals.user
149 const user = await db.User.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) 168 const user = await db.User.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
150 169
151 return res.json(user.toFormattedJSON()) 170 return res.json(user.toFormattedJSON())
152} 171}
153 172
154function getUser (req: express.Request, res: express.Response, next: express.NextFunction) { 173function getUser (req: express.Request, res: express.Response, next: express.NextFunction) {
155 return res.json(res.locals.user.toFormattedJSON()) 174 return res.json(res.locals.oauth.token.User.toFormattedJSON())
156} 175}
157 176
158async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { 177async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 49f0e4630..4dd09917b 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -9,7 +9,8 @@ import {
9 REQUEST_VIDEO_EVENT_TYPES, 9 REQUEST_VIDEO_EVENT_TYPES,
10 VIDEO_CATEGORIES, 10 VIDEO_CATEGORIES,
11 VIDEO_LICENCES, 11 VIDEO_LICENCES,
12 VIDEO_LANGUAGES 12 VIDEO_LANGUAGES,
13 VIDEO_PRIVACIES
13} from '../../../initializers' 14} from '../../../initializers'
14import { 15import {
15 addEventToRemoteVideo, 16 addEventToRemoteVideo,
@@ -43,7 +44,7 @@ import {
43 resetSequelizeInstance 44 resetSequelizeInstance
44} from '../../../helpers' 45} from '../../../helpers'
45import { VideoInstance } from '../../../models' 46import { VideoInstance } from '../../../models'
46import { VideoCreate, VideoUpdate } from '../../../../shared' 47import { VideoCreate, VideoUpdate, VideoPrivacy } from '../../../../shared'
47 48
48import { abuseVideoRouter } from './abuse' 49import { abuseVideoRouter } from './abuse'
49import { blacklistRouter } from './blacklist' 50import { blacklistRouter } from './blacklist'
@@ -84,6 +85,7 @@ videosRouter.use('/', videoChannelRouter)
84videosRouter.get('/categories', listVideoCategories) 85videosRouter.get('/categories', listVideoCategories)
85videosRouter.get('/licences', listVideoLicences) 86videosRouter.get('/licences', listVideoLicences)
86videosRouter.get('/languages', listVideoLanguages) 87videosRouter.get('/languages', listVideoLanguages)
88videosRouter.get('/privacies', listVideoPrivacies)
87 89
88videosRouter.get('/', 90videosRouter.get('/',
89 paginationValidator, 91 paginationValidator,
@@ -149,6 +151,10 @@ function listVideoLanguages (req: express.Request, res: express.Response) {
149 res.json(VIDEO_LANGUAGES) 151 res.json(VIDEO_LANGUAGES)
150} 152}
151 153
154function listVideoPrivacies (req: express.Request, res: express.Response) {
155 res.json(VIDEO_PRIVACIES)
156}
157
152// Wrapper to video add that retry the function if there is a database error 158// Wrapper to video add that retry the function if there is a database error
153// We need this because we run the transaction in SERIALIZABLE isolation that can fail 159// We need this because we run the transaction in SERIALIZABLE isolation that can fail
154async function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 160async function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -179,6 +185,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
179 language: videoInfo.language, 185 language: videoInfo.language,
180 nsfw: videoInfo.nsfw, 186 nsfw: videoInfo.nsfw,
181 description: videoInfo.description, 187 description: videoInfo.description,
188 privacy: videoInfo.privacy,
182 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware 189 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
183 channelId: res.locals.videoChannel.id 190 channelId: res.locals.videoChannel.id
184 } 191 }
@@ -240,6 +247,8 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
240 247
241 // Let transcoding job send the video to friends because the video file extension might change 248 // Let transcoding job send the video to friends because the video file extension might change
242 if (CONFIG.TRANSCODING.ENABLED === true) return undefined 249 if (CONFIG.TRANSCODING.ENABLED === true) return undefined
250 // Don't send video to remote pods, it is private
251 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
243 252
244 const remoteVideo = await video.toAddRemoteJSON() 253 const remoteVideo = await video.toAddRemoteJSON()
245 // Now we'll add the video's meta data to our friends 254 // Now we'll add the video's meta data to our friends
@@ -264,6 +273,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
264 const videoInstance = res.locals.video 273 const videoInstance = res.locals.video
265 const videoFieldsSave = videoInstance.toJSON() 274 const videoFieldsSave = videoInstance.toJSON()
266 const videoInfoToUpdate: VideoUpdate = req.body 275 const videoInfoToUpdate: VideoUpdate = req.body
276 const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE
267 277
268 try { 278 try {
269 await db.sequelize.transaction(async t => { 279 await db.sequelize.transaction(async t => {
@@ -276,6 +286,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
276 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence) 286 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
277 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) 287 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
278 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) 288 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
289 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', videoInfoToUpdate.privacy)
279 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 290 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
280 291
281 await videoInstance.save(sequelizeOptions) 292 await videoInstance.save(sequelizeOptions)
@@ -287,10 +298,17 @@ async function updateVideo (req: express.Request, res: express.Response) {
287 videoInstance.Tags = tagInstances 298 videoInstance.Tags = tagInstances
288 } 299 }
289 300
290 const json = videoInstance.toUpdateRemoteJSON()
291
292 // Now we'll update the video's meta data to our friends 301 // Now we'll update the video's meta data to our friends
293 return updateVideoToFriends(json, t) 302 if (wasPrivateVideo === false) {
303 const json = videoInstance.toUpdateRemoteJSON()
304 return updateVideoToFriends(json, t)
305 }
306
307 // Video is not private anymore, send a create action to remote pods
308 if (wasPrivateVideo === true && videoInstance.privacy !== VideoPrivacy.PRIVATE) {
309 const remoteVideo = await videoInstance.toAddRemoteJSON()
310 return addVideoToFriends(remoteVideo, t)
311 }
294 }) 312 })
295 313
296 logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) 314 logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)