aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/import.ts20
1 files changed, 15 insertions, 5 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