aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts10
-rw-r--r--server/controllers/api/videos/import.ts20
-rw-r--r--server/middlewares/validators/videos/video-imports.ts3
-rw-r--r--shared/models/server/server-error-code.enum.ts1
4 files changed, 24 insertions, 10 deletions
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
index 3aae24732..23bd5ef76 100644
--- a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
@@ -5,7 +5,7 @@ import { scrollToTop } from '@app/helpers'
5import { FormValidatorService } from '@app/shared/shared-forms' 5import { FormValidatorService } from '@app/shared/shared-forms'
6import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main' 6import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main'
7import { LoadingBarService } from '@ngx-loading-bar/core' 7import { LoadingBarService } from '@ngx-loading-bar/core'
8import { VideoPrivacy, VideoUpdate } from '@shared/models' 8import { ServerErrorCode, VideoPrivacy, VideoUpdate } from '@shared/models'
9import { hydrateFormFromVideo } from '../shared/video-edit-utils' 9import { hydrateFormFromVideo } from '../shared/video-edit-utils'
10import { VideoSend } from './video-send' 10import { VideoSend } from './video-send'
11 11
@@ -113,7 +113,13 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Af
113 this.loadingBar.useRef().complete() 113 this.loadingBar.useRef().complete()
114 this.isImportingVideo = false 114 this.isImportingVideo = false
115 this.firstStepError.emit() 115 this.firstStepError.emit()
116 this.notifier.error(err.message) 116
117 let message = err.message
118 if (err.body?.code === ServerErrorCode.INCORRECT_FILES_IN_TORRENT) {
119 message = $localize`Torrents with only 1 file are supported.`
120 }
121
122 this.notifier.error(message)
117 } 123 }
118 ) 124 )
119 } 125 }
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)
diff --git a/shared/models/server/server-error-code.enum.ts b/shared/models/server/server-error-code.enum.ts
index c02b0e6c7..d17d958be 100644
--- a/shared/models/server/server-error-code.enum.ts
+++ b/shared/models/server/server-error-code.enum.ts
@@ -2,4 +2,5 @@ export const enum ServerErrorCode {
2 DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 1, 2 DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 1,
3 MAX_INSTANCE_LIVES_LIMIT_REACHED = 2, 3 MAX_INSTANCE_LIVES_LIMIT_REACHED = 2,
4 MAX_USER_LIVES_LIMIT_REACHED = 3, 4 MAX_USER_LIVES_LIMIT_REACHED = 3,
5 INCORRECT_FILES_IN_TORRENT = 4
5} 6}