mirror of https://github.com/Chocobozzz/PeerTube
Add ability to remove a video import
parent
ce32426be9
commit
299474e827
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label i18n for="targetUrl">URL</label>
|
<label i18n for="targetUrl">URL</label>
|
||||||
|
<my-help
|
||||||
|
helpType="custom" i18n-customHtml
|
||||||
|
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."
|
||||||
|
></my-help>
|
||||||
|
|
||||||
<input type="text" id="targetUrl" [(ngModel)]="targetUrl" />
|
<input type="text" id="targetUrl" [(ngModel)]="targetUrl" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ videoImportsRouter.post('/imports',
|
||||||
|
|
||||||
videoImportsRouter.delete('/imports/:id',
|
videoImportsRouter.delete('/imports/:id',
|
||||||
authenticate,
|
authenticate,
|
||||||
videoImportDeleteValidator,
|
asyncMiddleware(videoImportDeleteValidator),
|
||||||
asyncRetryTransactionMiddleware(deleteVideoImport)
|
asyncRetryTransactionMiddleware(deleteVideoImport)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -147,5 +147,13 @@ async function addVideoImport (req: express.Request, res: express.Response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteVideoImport (req: express.Request, res: express.Response) {
|
async function deleteVideoImport (req: express.Request, res: express.Response) {
|
||||||
// TODO: delete video import
|
await sequelizeTypescript.transaction(async t => {
|
||||||
|
const videoImport = res.locals.videoImport
|
||||||
|
const video = videoImport.Video
|
||||||
|
|
||||||
|
await videoImport.destroy({ transaction: t })
|
||||||
|
await video.destroy({ transaction: t })
|
||||||
|
})
|
||||||
|
|
||||||
|
return res.status(204).end()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@ import 'multer'
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers'
|
import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers'
|
||||||
import { exists } from './misc'
|
import { exists } from './misc'
|
||||||
|
import * as express from 'express'
|
||||||
|
import { VideoChannelModel } from '../../models/video/video-channel'
|
||||||
|
import { VideoImportModel } from '../../models/video/video-import'
|
||||||
|
|
||||||
function isVideoImportTargetUrlValid (url: string) {
|
function isVideoImportTargetUrlValid (url: string) {
|
||||||
const isURLOptions = {
|
const isURLOptions = {
|
||||||
|
@ -22,9 +25,25 @@ function isVideoImportStateValid (value: any) {
|
||||||
return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined
|
return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isVideoImportExist (id: number, res: express.Response) {
|
||||||
|
const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
|
||||||
|
|
||||||
|
if (!videoImport) {
|
||||||
|
res.status(404)
|
||||||
|
.json({ error: 'Video import not found' })
|
||||||
|
.end()
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
res.locals.videoImport = videoImport
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
isVideoImportStateValid,
|
isVideoImportStateValid,
|
||||||
isVideoImportTargetUrlValid
|
isVideoImportTargetUrlValid,
|
||||||
|
isVideoImportExist
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Thanks: https://github.com/przemyslawpluta/node-youtube-dl/blob/master/lib/downloader.js
|
// Thanks: https://github.com/przemyslawpluta/node-youtube-dl/blob/master/lib/downloader.js
|
||||||
// Use rewrote it to avoid sync calls
|
// We rewrote it to avoid sync calls
|
||||||
|
|
||||||
import { AbstractScheduler } from './abstract-scheduler'
|
import { AbstractScheduler } from './abstract-scheduler'
|
||||||
import { SCHEDULER_INTERVALS_MS } from '../../initializers'
|
import { SCHEDULER_INTERVALS_MS } from '../../initializers'
|
||||||
|
|
|
@ -4,9 +4,11 @@ import { isIdValid } from '../../helpers/custom-validators/misc'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { getCommonVideoAttributes } from './videos'
|
import { getCommonVideoAttributes } from './videos'
|
||||||
import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
|
import { isVideoImportTargetUrlValid, isVideoImportExist } from '../../helpers/custom-validators/video-imports'
|
||||||
import { cleanUpReqFiles } from '../../helpers/utils'
|
import { cleanUpReqFiles } from '../../helpers/utils'
|
||||||
import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos'
|
import { isVideoChannelOfAccountExist, isVideoNameValid, checkUserCanManageVideo } from '../../helpers/custom-validators/videos'
|
||||||
|
import { VideoImportModel } from '../../models/video/video-import'
|
||||||
|
import { UserRight } from '../../../shared'
|
||||||
|
|
||||||
const videoImportAddValidator = getCommonVideoAttributes().concat([
|
const videoImportAddValidator = getCommonVideoAttributes().concat([
|
||||||
body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
|
body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
|
||||||
|
@ -32,10 +34,16 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([
|
||||||
const videoImportDeleteValidator = [
|
const videoImportDeleteValidator = [
|
||||||
param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
|
param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
|
||||||
|
|
||||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.body })
|
logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.body })
|
||||||
|
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
|
if (!await isVideoImportExist(req.params.id, res)) return
|
||||||
|
|
||||||
|
const user = res.locals.oauth.token.User
|
||||||
|
const videoImport: VideoImportModel = res.locals.videoImport
|
||||||
|
|
||||||
|
if (!await checkUserCanManageVideo(user, videoImport.Video, UserRight.UPDATE_ANY_VIDEO, res)) return
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue