aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/import.ts12
-rw-r--r--server/helpers/custom-validators/video-imports.ts21
-rw-r--r--server/lib/schedulers/youtube-dl-update-scheduler.ts2
-rw-r--r--server/middlewares/validators/video-imports.ts14
4 files changed, 42 insertions, 7 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 9761cdbcf..680d8665f 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -41,7 +41,7 @@ videoImportsRouter.post('/imports',
41 41
42videoImportsRouter.delete('/imports/:id', 42videoImportsRouter.delete('/imports/:id',
43 authenticate, 43 authenticate,
44 videoImportDeleteValidator, 44 asyncMiddleware(videoImportDeleteValidator),
45 asyncRetryTransactionMiddleware(deleteVideoImport) 45 asyncRetryTransactionMiddleware(deleteVideoImport)
46) 46)
47 47
@@ -147,5 +147,13 @@ async function addVideoImport (req: express.Request, res: express.Response) {
147} 147}
148 148
149async function deleteVideoImport (req: express.Request, res: express.Response) { 149async function deleteVideoImport (req: express.Request, res: express.Response) {
150 // TODO: delete video import 150 await sequelizeTypescript.transaction(async t => {
151 const videoImport = res.locals.videoImport
152 const video = videoImport.Video
153
154 await videoImport.destroy({ transaction: t })
155 await video.destroy({ transaction: t })
156 })
157
158 return res.status(204).end()
151} 159}
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts
index 36c0559fd..d8b9bfaff 100644
--- a/server/helpers/custom-validators/video-imports.ts
+++ b/server/helpers/custom-validators/video-imports.ts
@@ -3,6 +3,9 @@ import 'multer'
3import * as validator from 'validator' 3import * as validator from 'validator'
4import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers' 4import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers'
5import { exists } from './misc' 5import { exists } from './misc'
6import * as express from 'express'
7import { VideoChannelModel } from '../../models/video/video-channel'
8import { VideoImportModel } from '../../models/video/video-import'
6 9
7function isVideoImportTargetUrlValid (url: string) { 10function isVideoImportTargetUrlValid (url: string) {
8 const isURLOptions = { 11 const isURLOptions = {
@@ -22,9 +25,25 @@ function isVideoImportStateValid (value: any) {
22 return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined 25 return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined
23} 26}
24 27
28async function isVideoImportExist (id: number, res: express.Response) {
29 const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
30
31 if (!videoImport) {
32 res.status(404)
33 .json({ error: 'Video import not found' })
34 .end()
35
36 return false
37 }
38
39 res.locals.videoImport = videoImport
40 return true
41}
42
25// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
26 44
27export { 45export {
28 isVideoImportStateValid, 46 isVideoImportStateValid,
29 isVideoImportTargetUrlValid 47 isVideoImportTargetUrlValid,
48 isVideoImportExist
30} 49}
diff --git a/server/lib/schedulers/youtube-dl-update-scheduler.ts b/server/lib/schedulers/youtube-dl-update-scheduler.ts
index b736f17ee..a2d919603 100644
--- a/server/lib/schedulers/youtube-dl-update-scheduler.ts
+++ b/server/lib/schedulers/youtube-dl-update-scheduler.ts
@@ -1,5 +1,5 @@
1// Thanks: https://github.com/przemyslawpluta/node-youtube-dl/blob/master/lib/downloader.js 1// Thanks: https://github.com/przemyslawpluta/node-youtube-dl/blob/master/lib/downloader.js
2// Use rewrote it to avoid sync calls 2// We rewrote it to avoid sync calls
3 3
4import { AbstractScheduler } from './abstract-scheduler' 4import { AbstractScheduler } from './abstract-scheduler'
5import { SCHEDULER_INTERVALS_MS } from '../../initializers' 5import { SCHEDULER_INTERVALS_MS } from '../../initializers'
diff --git a/server/middlewares/validators/video-imports.ts b/server/middlewares/validators/video-imports.ts
index 0ba759ff0..0dedcf803 100644
--- a/server/middlewares/validators/video-imports.ts
+++ b/server/middlewares/validators/video-imports.ts
@@ -4,9 +4,11 @@ import { isIdValid } from '../../helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6import { getCommonVideoAttributes } from './videos' 6import { getCommonVideoAttributes } from './videos'
7import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' 7import { isVideoImportTargetUrlValid, isVideoImportExist } from '../../helpers/custom-validators/video-imports'
8import { cleanUpReqFiles } from '../../helpers/utils' 8import { cleanUpReqFiles } from '../../helpers/utils'
9import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos' 9import { isVideoChannelOfAccountExist, isVideoNameValid, checkUserCanManageVideo } from '../../helpers/custom-validators/videos'
10import { VideoImportModel } from '../../models/video/video-import'
11import { UserRight } from '../../../shared'
10 12
11const videoImportAddValidator = getCommonVideoAttributes().concat([ 13const videoImportAddValidator = getCommonVideoAttributes().concat([
12 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), 14 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
@@ -32,10 +34,16 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([
32const videoImportDeleteValidator = [ 34const videoImportDeleteValidator = [
33 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), 35 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
34 36
35 (req: express.Request, res: express.Response, next: express.NextFunction) => { 37 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
36 logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.body }) 38 logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.body })
37 39
38 if (areValidationErrors(req, res)) return 40 if (areValidationErrors(req, res)) return
41 if (!await isVideoImportExist(req.params.id, res)) return
42
43 const user = res.locals.oauth.token.User
44 const videoImport: VideoImportModel = res.locals.videoImport
45
46 if (!await checkUserCanManageVideo(user, videoImport.Video, UserRight.UPDATE_ANY_VIDEO, res)) return
39 47
40 return next() 48 return next()
41 } 49 }