aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/videos/index.ts36
1 files changed, 25 insertions, 11 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 7a9cd9d37..6fa84c801 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -45,6 +45,7 @@ import { VideoCreate, VideoUpdate } from '../../../../shared'
45import { abuseVideoRouter } from './abuse' 45import { abuseVideoRouter } from './abuse'
46import { blacklistRouter } from './blacklist' 46import { blacklistRouter } from './blacklist'
47import { rateVideoRouter } from './rate' 47import { rateVideoRouter } from './rate'
48import { VideoInstance } from '../../../models/video/video-interface'
48 49
49const videosRouter = express.Router() 50const videosRouter = express.Router()
50 51
@@ -106,7 +107,7 @@ videosRouter.get('/:id',
106videosRouter.delete('/:id', 107videosRouter.delete('/:id',
107 authenticate, 108 authenticate,
108 videosRemoveValidator, 109 videosRemoveValidator,
109 removeVideo 110 removeVideoRetryWrapper
110) 111)
111 112
112videosRouter.get('/search/:value', 113videosRouter.get('/search/:value',
@@ -291,7 +292,6 @@ function updateVideoRetryWrapper (req: express.Request, res: express.Response, n
291 292
292 retryTransactionWrapper(updateVideo, options) 293 retryTransactionWrapper(updateVideo, options)
293 .then(() => { 294 .then(() => {
294 // TODO : include Location of the new video -> 201
295 return res.type('json').status(204).end() 295 return res.type('json').status(204).end()
296 }) 296 })
297 .catch(err => next(err)) 297 .catch(err => next(err))
@@ -396,18 +396,32 @@ function listVideos (req: express.Request, res: express.Response, next: express.
396 .catch(err => next(err)) 396 .catch(err => next(err))
397} 397}
398 398
399function removeVideo (req: express.Request, res: express.Response, next: express.NextFunction) { 399function removeVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
400 const videoInstance = res.locals.video 400 const options = {
401 arguments: [ req, res ],
402 errorMessage: 'Cannot remove the video with many retries.'
403 }
401 404
402 videoInstance.destroy() 405 retryTransactionWrapper(removeVideo, options)
403 .then(() => { 406 .then(() => {
404 logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid) 407 return res.type('json').status(204).end()
405 res.type('json').status(204).end()
406 })
407 .catch(err => {
408 logger.error('Errors when removed the video.', err)
409 return next(err)
410 }) 408 })
409 .catch(err => next(err))
410}
411
412function removeVideo (req: express.Request, res: express.Response) {
413 const videoInstance: VideoInstance = res.locals.video
414
415 return db.sequelize.transaction(t => {
416 return videoInstance.destroy({ transaction: t })
417 })
418 .then(() => {
419 logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid)
420 })
421 .catch(err => {
422 logger.error('Errors when removed the video.', err)
423 throw err
424 })
411} 425}
412 426
413function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 427function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) {