From a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Aug 2018 10:07:53 +0200 Subject: Add import.video.torrent configuration --- server/controllers/api/config.ts | 8 +++++++- server/controllers/api/users.ts | 2 +- server/controllers/api/videos/import.ts | 10 +++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 950a1498e..6f05c33db 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -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 } } } diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 879ba3f91..36bf0e0fe 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -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 diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index df151e79d..94dafcdbd 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -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) -- cgit v1.2.3