diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-12-08 08:39:15 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-12-08 09:57:29 +0100 |
commit | cadb46d832724ea1a17b085b992142aa32e212be (patch) | |
tree | df1972470ab022e95ff5dc7866c78174c36bfa37 /server/controllers | |
parent | c182778e26b8478fae9d7dd0bf0687baf7b72fd1 (diff) | |
download | PeerTube-cadb46d832724ea1a17b085b992142aa32e212be.tar.gz PeerTube-cadb46d832724ea1a17b085b992142aa32e212be.tar.zst PeerTube-cadb46d832724ea1a17b085b992142aa32e212be.zip |
Design second video upload step
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/videos/index.ts | 28 |
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' | |||
15 | import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' | 15 | import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' |
16 | import { database as db } from '../../../initializers/database' | 16 | import { database as db } from '../../../initializers/database' |
17 | import { sendAddVideo } from '../../../lib/activitypub/send/send-add' | 17 | import { sendAddVideo } from '../../../lib/activitypub/send/send-add' |
18 | import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create' | ||
18 | import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' | 19 | import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' |
19 | import { shareVideoByServer } from '../../../lib/activitypub/share' | 20 | import { shareVideoByServer } from '../../../lib/activitypub/share' |
20 | import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' | 21 | import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' |
@@ -39,7 +40,6 @@ import { abuseVideoRouter } from './abuse' | |||
39 | import { blacklistRouter } from './blacklist' | 40 | import { blacklistRouter } from './blacklist' |
40 | import { videoChannelRouter } from './channel' | 41 | import { videoChannelRouter } from './channel' |
41 | import { rateVideoRouter } from './rate' | 42 | import { rateVideoRouter } from './rate' |
42 | import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create' | ||
43 | 43 | ||
44 | const videosRouter = express.Router() | 44 | const 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 | ||
163 | async function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { | 167 | function 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 | ||
252 | async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | 256 | async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |