diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/videos/index.ts | 36 |
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' | |||
45 | import { abuseVideoRouter } from './abuse' | 45 | import { abuseVideoRouter } from './abuse' |
46 | import { blacklistRouter } from './blacklist' | 46 | import { blacklistRouter } from './blacklist' |
47 | import { rateVideoRouter } from './rate' | 47 | import { rateVideoRouter } from './rate' |
48 | import { VideoInstance } from '../../../models/video/video-interface' | ||
48 | 49 | ||
49 | const videosRouter = express.Router() | 50 | const videosRouter = express.Router() |
50 | 51 | ||
@@ -106,7 +107,7 @@ videosRouter.get('/:id', | |||
106 | videosRouter.delete('/:id', | 107 | videosRouter.delete('/:id', |
107 | authenticate, | 108 | authenticate, |
108 | videosRemoveValidator, | 109 | videosRemoveValidator, |
109 | removeVideo | 110 | removeVideoRetryWrapper |
110 | ) | 111 | ) |
111 | 112 | ||
112 | videosRouter.get('/search/:value', | 113 | videosRouter.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 | ||
399 | function removeVideo (req: express.Request, res: express.Response, next: express.NextFunction) { | 399 | function 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 | |||
412 | function 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 | ||
413 | function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 427 | function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |