1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add import.video.torrent configuration

This commit is contained in:
Chocobozzz 2018-08-07 10:07:53 +02:00
parent 990b6a0b0c
commit a84b8fa5cf
23 changed files with 112 additions and 106 deletions

View file

@ -9,7 +9,7 @@ import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers'
import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
import { customConfigUpdateValidator } from '../../middlewares/validators/config'
import { ClientHtml } from '../../lib/client-html'
import { CustomConfigAuditView, auditLoggerFactory } from '../../helpers/audit-logger'
import { auditLoggerFactory, CustomConfigAuditView } from '../../helpers/audit-logger'
const packageJSON = require('../../../../package.json')
const configRouter = express.Router()
@ -69,6 +69,9 @@ async function getConfig (req: express.Request, res: express.Response, next: exp
videos: {
http: {
enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
},
torrent: {
enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
}
}
},
@ -237,6 +240,9 @@ function customConfig (): CustomConfig {
videos: {
http: {
enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
},
torrent: {
enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
}
}
}

View file

@ -196,7 +196,7 @@ async function getUserVideos (req: express.Request, res: express.Response, next:
async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) {
const user = res.locals.oauth.token.User as UserModel
const resultList = await VideoImportModel.listUserVideoImportsForApi(
user.Account.id,
user.id,
req.query.start as number,
req.query.count as number,
req.query.sort

View file

@ -61,12 +61,13 @@ export {
function addVideoImport (req: express.Request, res: express.Response) {
if (req.body.targetUrl) return addYoutubeDLImport(req, res)
const file = req.files['torrentfile'][0]
const file = req.files && req.files['torrentfile'] ? req.files['torrentfile'][0] : undefined
if (req.body.magnetUri || file) return addTorrentImport(req, res, file)
}
async function addTorrentImport (req: express.Request, res: express.Response, torrentfile: Express.Multer.File) {
const body: VideoImportCreate = req.body
const user = res.locals.oauth.token.User
let videoName: string
let torrentName: string
@ -100,7 +101,8 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
const videoImportAttributes = {
magnetUri,
torrentName,
state: VideoImportState.PENDING
state: VideoImportState.PENDING,
userId: user.id
}
const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)
@ -120,6 +122,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
async function addYoutubeDLImport (req: express.Request, res: express.Response) {
const body: VideoImportCreate = req.body
const targetUrl = body.targetUrl
const user = res.locals.oauth.token.User
let youtubeDLInfo: YoutubeDLInfo
try {
@ -140,7 +143,8 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
const tags = body.tags || youtubeDLInfo.tags
const videoImportAttributes = {
targetUrl,
state: VideoImportState.PENDING
state: VideoImportState.PENDING,
userId: user.id
}
const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)