aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-07 10:07:53 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commita84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4 (patch)
treecf2feafcfadb5b6e9784c86d67e692db8d599b7d /server/controllers
parent990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66 (diff)
downloadPeerTube-a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4.tar.gz
PeerTube-a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4.tar.zst
PeerTube-a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4.zip
Add import.video.torrent configuration
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/config.ts8
-rw-r--r--server/controllers/api/users.ts2
-rw-r--r--server/controllers/api/videos/import.ts10
3 files changed, 15 insertions, 5 deletions
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'
9import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' 9import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
10import { customConfigUpdateValidator } from '../../middlewares/validators/config' 10import { customConfigUpdateValidator } from '../../middlewares/validators/config'
11import { ClientHtml } from '../../lib/client-html' 11import { ClientHtml } from '../../lib/client-html'
12import { CustomConfigAuditView, auditLoggerFactory } from '../../helpers/audit-logger' 12import { auditLoggerFactory, CustomConfigAuditView } from '../../helpers/audit-logger'
13 13
14const packageJSON = require('../../../../package.json') 14const packageJSON = require('../../../../package.json')
15const configRouter = express.Router() 15const configRouter = express.Router()
@@ -69,6 +69,9 @@ async function getConfig (req: express.Request, res: express.Response, next: exp
69 videos: { 69 videos: {
70 http: { 70 http: {
71 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED 71 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
72 },
73 torrent: {
74 enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
72 } 75 }
73 } 76 }
74 }, 77 },
@@ -237,6 +240,9 @@ function customConfig (): CustomConfig {
237 videos: { 240 videos: {
238 http: { 241 http: {
239 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED 242 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
243 },
244 torrent: {
245 enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
240 } 246 }
241 } 247 }
242 } 248 }
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:
196async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) { 196async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) {
197 const user = res.locals.oauth.token.User as UserModel 197 const user = res.locals.oauth.token.User as UserModel
198 const resultList = await VideoImportModel.listUserVideoImportsForApi( 198 const resultList = await VideoImportModel.listUserVideoImportsForApi(
199 user.Account.id, 199 user.id,
200 req.query.start as number, 200 req.query.start as number,
201 req.query.count as number, 201 req.query.count as number,
202 req.query.sort 202 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 {
61function addVideoImport (req: express.Request, res: express.Response) { 61function addVideoImport (req: express.Request, res: express.Response) {
62 if (req.body.targetUrl) return addYoutubeDLImport(req, res) 62 if (req.body.targetUrl) return addYoutubeDLImport(req, res)
63 63
64 const file = req.files['torrentfile'][0] 64 const file = req.files && req.files['torrentfile'] ? req.files['torrentfile'][0] : undefined
65 if (req.body.magnetUri || file) return addTorrentImport(req, res, file) 65 if (req.body.magnetUri || file) return addTorrentImport(req, res, file)
66} 66}
67 67
68async function addTorrentImport (req: express.Request, res: express.Response, torrentfile: Express.Multer.File) { 68async function addTorrentImport (req: express.Request, res: express.Response, torrentfile: Express.Multer.File) {
69 const body: VideoImportCreate = req.body 69 const body: VideoImportCreate = req.body
70 const user = res.locals.oauth.token.User
70 71
71 let videoName: string 72 let videoName: string
72 let torrentName: string 73 let torrentName: string
@@ -100,7 +101,8 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
100 const videoImportAttributes = { 101 const videoImportAttributes = {
101 magnetUri, 102 magnetUri,
102 torrentName, 103 torrentName,
103 state: VideoImportState.PENDING 104 state: VideoImportState.PENDING,
105 userId: user.id
104 } 106 }
105 const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes) 107 const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)
106 108
@@ -120,6 +122,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
120async function addYoutubeDLImport (req: express.Request, res: express.Response) { 122async function addYoutubeDLImport (req: express.Request, res: express.Response) {
121 const body: VideoImportCreate = req.body 123 const body: VideoImportCreate = req.body
122 const targetUrl = body.targetUrl 124 const targetUrl = body.targetUrl
125 const user = res.locals.oauth.token.User
123 126
124 let youtubeDLInfo: YoutubeDLInfo 127 let youtubeDLInfo: YoutubeDLInfo
125 try { 128 try {
@@ -140,7 +143,8 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
140 const tags = body.tags || youtubeDLInfo.tags 143 const tags = body.tags || youtubeDLInfo.tags
141 const videoImportAttributes = { 144 const videoImportAttributes = {
142 targetUrl, 145 targetUrl,
143 state: VideoImportState.PENDING 146 state: VideoImportState.PENDING,
147 userId: user.id
144 } 148 }
145 const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes) 149 const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)
146 150