aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/index.ts28
-rw-r--r--server/tests/api/single-server.ts5
-rw-r--r--server/tests/utils/videos.ts2
3 files changed, 21 insertions, 14 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) {
diff --git a/server/tests/api/single-server.ts b/server/tests/api/single-server.ts
index fbb2dd1fb..ed79f9e1c 100644
--- a/server/tests/api/single-server.ts
+++ b/server/tests/api/single-server.ts
@@ -104,7 +104,10 @@ describe('Test a single server', function () {
104 licence: 6, 104 licence: 6,
105 tags: [ 'tag1', 'tag2', 'tag3' ] 105 tags: [ 'tag1', 'tag2', 'tag3' ]
106 } 106 }
107 await uploadVideo(server.url, server.accessToken, videoAttributes) 107 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
108 expect(res.body.video).to.not.be.undefined
109 expect(res.body.video.id).to.equal(1)
110 expect(res.body.video.uuid).to.have.length.above(5)
108 }) 111 })
109 112
110 it('Should seed the uploaded video', async function () { 113 it('Should seed the uploaded video', async function () {
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts
index ff7da9bb2..bdf3368ac 100644
--- a/server/tests/utils/videos.ts
+++ b/server/tests/utils/videos.ts
@@ -201,7 +201,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string
201 } 201 }
202} 202}
203 203
204async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) { 204async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 201) {
205 const path = '/api/v1/videos/upload' 205 const path = '/api/v1/videos/upload'
206 let defaultChannelId = '1' 206 let defaultChannelId = '1'
207 207