aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-11 14:56:00 +0200
committerChocobozzz <me@florianbigard.com>2021-05-11 14:56:30 +0200
commit32985a0a779e0e2100a3990b1f1188645e58dfb1 (patch)
treef96e0166858b10642e2cbf97906d63c57b85ebc1 /server
parenta3c997b34cad79fce92c67951a3c8140a9888973 (diff)
downloadPeerTube-32985a0a779e0e2100a3990b1f1188645e58dfb1.tar.gz
PeerTube-32985a0a779e0e2100a3990b1f1188645e58dfb1.tar.zst
PeerTube-32985a0a779e0e2100a3990b1f1188645e58dfb1.zip
Error if importing a torrent with multiple files
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/import.ts20
-rw-r--r--server/middlewares/validators/videos/video-imports.ts3
2 files changed, 15 insertions, 8 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 37fd42b90..4ed58f978 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -16,13 +16,13 @@ import {
16 MVideoWithBlacklistLight 16 MVideoWithBlacklistLight
17} from '@server/types/models' 17} from '@server/types/models'
18import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import' 18import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import'
19import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' 19import { ServerErrorCode, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared'
20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 21import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
22import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' 22import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
23import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' 23import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
24import { isArray } from '../../../helpers/custom-validators/misc' 24import { isArray } from '../../../helpers/custom-validators/misc'
25import { createReqFiles } from '../../../helpers/express-utils' 25import { cleanUpReqFiles, createReqFiles } from '../../../helpers/express-utils'
26import { logger } from '../../../helpers/logger' 26import { logger } from '../../../helpers/logger'
27import { getSecureTorrentName } from '../../../helpers/utils' 27import { getSecureTorrentName } from '../../../helpers/utils'
28import { YoutubeDL, YoutubeDLInfo } from '../../../helpers/youtube-dl' 28import { YoutubeDL, YoutubeDLInfo } from '../../../helpers/youtube-dl'
@@ -86,13 +86,23 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
86 86
87 // Rename the torrent to a secured name 87 // Rename the torrent to a secured name
88 const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName)) 88 const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName))
89 await move(torrentfile.path, newTorrentPath) 89 await move(torrentfile.path, newTorrentPath, { overwrite: true })
90 torrentfile.path = newTorrentPath 90 torrentfile.path = newTorrentPath
91 91
92 const buf = await readFile(torrentfile.path) 92 const buf = await readFile(torrentfile.path)
93 const parsedTorrent = parseTorrent(buf) 93 const parsedTorrent = parseTorrent(buf) as parseTorrent.Instance
94 94
95 videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[0] : parsedTorrent.name as string 95 if (parsedTorrent.files.length !== 1) {
96 cleanUpReqFiles(req)
97
98 return res.status(HttpStatusCode.BAD_REQUEST_400)
99 .json({
100 code: ServerErrorCode.INCORRECT_FILES_IN_TORRENT,
101 error: 'Torrents with only 1 file are supported.'
102 })
103 }
104
105 videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[0] : parsedTorrent.name
96 } else { 106 } else {
97 magnetUri = body.magnetUri 107 magnetUri = body.magnetUri
98 108
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts
index c53af3861..d0643ff26 100644
--- a/server/middlewares/validators/videos/video-imports.ts
+++ b/server/middlewares/validators/videos/video-imports.ts
@@ -47,14 +47,12 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
47 cleanUpReqFiles(req) 47 cleanUpReqFiles(req)
48 return res.status(HttpStatusCode.CONFLICT_409) 48 return res.status(HttpStatusCode.CONFLICT_409)
49 .json({ error: 'HTTP import is not enabled on this instance.' }) 49 .json({ error: 'HTTP import is not enabled on this instance.' })
50 .end()
51 } 50 }
52 51
53 if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) { 52 if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) {
54 cleanUpReqFiles(req) 53 cleanUpReqFiles(req)
55 return res.status(HttpStatusCode.CONFLICT_409) 54 return res.status(HttpStatusCode.CONFLICT_409)
56 .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' }) 55 .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' })
57 .end()
58 } 56 }
59 57
60 if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) 58 if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
@@ -65,7 +63,6 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
65 63
66 return res.status(HttpStatusCode.BAD_REQUEST_400) 64 return res.status(HttpStatusCode.BAD_REQUEST_400)
67 .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' }) 65 .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' })
68 .end()
69 } 66 }
70 67
71 if (!await isImportAccepted(req, res)) return cleanUpReqFiles(req) 68 if (!await isImportAccepted(req, res)) return cleanUpReqFiles(req)