diff options
-rw-r--r-- | client/src/app/videos/+video-edit/video-import.component.html | 5 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 12 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-imports.ts | 21 | ||||
-rw-r--r-- | server/lib/schedulers/youtube-dl-update-scheduler.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/video-imports.ts | 14 |
5 files changed, 47 insertions, 7 deletions
diff --git a/client/src/app/videos/+video-edit/video-import.component.html b/client/src/app/videos/+video-edit/video-import.component.html index 9d71a0717..d59c6a23a 100644 --- a/client/src/app/videos/+video-edit/video-import.component.html +++ b/client/src/app/videos/+video-edit/video-import.component.html | |||
@@ -4,6 +4,11 @@ | |||
4 | 4 | ||
5 | <div class="form-group"> | 5 | <div class="form-group"> |
6 | <label i18n for="targetUrl">URL</label> | 6 | <label i18n for="targetUrl">URL</label> |
7 | <my-help | ||
8 | helpType="custom" i18n-customHtml | ||
9 | customHtml="You can import any URL <a href='https://rg3.github.io/youtube-dl/supportedsites.html'>supported by youtube-dl</a> or URL that points to a raw MP4 file. Failure to secure these rights could cause legal trouble to yourself and your instance." | ||
10 | ></my-help> | ||
11 | |||
7 | <input type="text" id="targetUrl" [(ngModel)]="targetUrl" /> | 12 | <input type="text" id="targetUrl" [(ngModel)]="targetUrl" /> |
8 | </div> | 13 | </div> |
9 | 14 | ||
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 | ||
42 | videoImportsRouter.delete('/imports/:id', | 42 | videoImportsRouter.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 | ||
149 | async function deleteVideoImport (req: express.Request, res: express.Response) { | 149 | async 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' | |||
3 | import * as validator from 'validator' | 3 | import * as validator from 'validator' |
4 | import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers' | 4 | import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers' |
5 | import { exists } from './misc' | 5 | import { exists } from './misc' |
6 | import * as express from 'express' | ||
7 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
8 | import { VideoImportModel } from '../../models/video/video-import' | ||
6 | 9 | ||
7 | function isVideoImportTargetUrlValid (url: string) { | 10 | function 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 | ||
28 | async 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 | ||
27 | export { | 45 | export { |
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 | ||
4 | import { AbstractScheduler } from './abstract-scheduler' | 4 | import { AbstractScheduler } from './abstract-scheduler' |
5 | import { SCHEDULER_INTERVALS_MS } from '../../initializers' | 5 | import { 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' | |||
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | import { getCommonVideoAttributes } from './videos' | 6 | import { getCommonVideoAttributes } from './videos' |
7 | import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' | 7 | import { isVideoImportTargetUrlValid, isVideoImportExist } from '../../helpers/custom-validators/video-imports' |
8 | import { cleanUpReqFiles } from '../../helpers/utils' | 8 | import { cleanUpReqFiles } from '../../helpers/utils' |
9 | import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos' | 9 | import { isVideoChannelOfAccountExist, isVideoNameValid, checkUserCanManageVideo } from '../../helpers/custom-validators/videos' |
10 | import { VideoImportModel } from '../../models/video/video-import' | ||
11 | import { UserRight } from '../../../shared' | ||
10 | 12 | ||
11 | const videoImportAddValidator = getCommonVideoAttributes().concat([ | 13 | const 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([ | |||
32 | const videoImportDeleteValidator = [ | 34 | const 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 | } |