aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-12-08 08:39:15 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-12-08 09:57:29 +0100
commitcadb46d832724ea1a17b085b992142aa32e212be (patch)
treedf1972470ab022e95ff5dc7866c78174c36bfa37 /server/controllers/api/videos
parentc182778e26b8478fae9d7dd0bf0687baf7b72fd1 (diff)
downloadPeerTube-cadb46d832724ea1a17b085b992142aa32e212be.tar.gz
PeerTube-cadb46d832724ea1a17b085b992142aa32e212be.tar.zst
PeerTube-cadb46d832724ea1a17b085b992142aa32e212be.zip
Design second video upload step
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/index.ts28
1 files changed, 16 insertions, 12 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 2b70d535e..f427a25c0 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -15,6 +15,7 @@ import { getServerAccount } from '../../../helpers/utils'
15import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' 15import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers'
16import { database as db } from '../../../initializers/database' 16import { database as db } from '../../../initializers/database'
17import { sendAddVideo } from '../../../lib/activitypub/send/send-add' 17import { sendAddVideo } from '../../../lib/activitypub/send/send-add'
18import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create'
18import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' 19import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update'
19import { shareVideoByServer } from '../../../lib/activitypub/share' 20import { shareVideoByServer } from '../../../lib/activitypub/share'
20import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' 21import { getVideoActivityPubUrl } from '../../../lib/activitypub/url'
@@ -39,7 +40,6 @@ import { abuseVideoRouter } from './abuse'
39import { blacklistRouter } from './blacklist' 40import { blacklistRouter } from './blacklist'
40import { videoChannelRouter } from './channel' 41import { videoChannelRouter } from './channel'
41import { rateVideoRouter } from './rate' 42import { rateVideoRouter } from './rate'
42import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create'
43 43
44const videosRouter = express.Router() 44const videosRouter = express.Router()
45 45
@@ -154,17 +154,20 @@ async function addVideoRetryWrapper (req: express.Request, res: express.Response
154 errorMessage: 'Cannot insert the video with many retries.' 154 errorMessage: 'Cannot insert the video with many retries.'
155 } 155 }
156 156
157 await retryTransactionWrapper(addVideo, options) 157 const video = await retryTransactionWrapper(addVideo, options)
158 158
159 // TODO : include Location of the new video -> 201 159 res.json({
160 res.type('json').status(204).end() 160 video: {
161 id: video.id,
162 uuid: video.uuid
163 }
164 }).end()
161} 165}
162 166
163async function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { 167function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) {
164 const videoInfo: VideoCreate = req.body 168 const videoInfo: VideoCreate = req.body
165 let videoUUID = ''
166 169
167 await db.sequelize.transaction(async t => { 170 return db.sequelize.transaction(async t => {
168 const sequelizeOptions = { transaction: t } 171 const sequelizeOptions = { transaction: t }
169 172
170 const videoData = { 173 const videoData = {
@@ -223,7 +226,6 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
223 const videoCreated = await video.save(sequelizeOptions) 226 const videoCreated = await video.save(sequelizeOptions)
224 // Do not forget to add video channel information to the created video 227 // Do not forget to add video channel information to the created video
225 videoCreated.VideoChannel = res.locals.videoChannel 228 videoCreated.VideoChannel = res.locals.videoChannel
226 videoUUID = videoCreated.uuid
227 229
228 videoFile.videoId = video.id 230 videoFile.videoId = video.id
229 231
@@ -238,15 +240,17 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
238 } 240 }
239 241
240 // Let transcoding job send the video to friends because the video file extension might change 242 // Let transcoding job send the video to friends because the video file extension might change
241 if (CONFIG.TRANSCODING.ENABLED === true) return undefined 243 if (CONFIG.TRANSCODING.ENABLED === true) return videoCreated
242 // Don't send video to remote servers, it is private 244 // Don't send video to remote servers, it is private
243 if (video.privacy === VideoPrivacy.PRIVATE) return undefined 245 if (video.privacy === VideoPrivacy.PRIVATE) return videoCreated
244 246
245 await sendAddVideo(video, t) 247 await sendAddVideo(video, t)
246 await shareVideoByServer(video, t) 248 await shareVideoByServer(video, t)
247 })
248 249
249 logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoUUID) 250 logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid)
251
252 return videoCreated
253 })
250} 254}
251 255
252async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 256async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {