diff options
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/import.ts | 20 |
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' |
18 | import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import' | 18 | import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import' |
19 | import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' | 19 | import { ServerErrorCode, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' |
20 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 20 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
21 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 21 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
22 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' | 22 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' |
23 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | 23 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' |
24 | import { isArray } from '../../../helpers/custom-validators/misc' | 24 | import { isArray } from '../../../helpers/custom-validators/misc' |
25 | import { createReqFiles } from '../../../helpers/express-utils' | 25 | import { cleanUpReqFiles, createReqFiles } from '../../../helpers/express-utils' |
26 | import { logger } from '../../../helpers/logger' | 26 | import { logger } from '../../../helpers/logger' |
27 | import { getSecureTorrentName } from '../../../helpers/utils' | 27 | import { getSecureTorrentName } from '../../../helpers/utils' |
28 | import { YoutubeDL, YoutubeDLInfo } from '../../../helpers/youtube-dl' | 28 | import { 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 | ||