-function insertIntoDB (parameters: {
- video: MVideoThumbnailAccountDefault,
- thumbnailModel: MThumbnail,
- previewModel: MThumbnail,
- videoChannel: MChannelActorAccountDefault,
- tags: string[],
- videoImportAttributes: Partial<MVideoImport>,
- user: MUser
-}): Bluebird<MVideoImportVideo> {
- const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
-
- return sequelizeTypescript.transaction(async t => {
- const sequelizeOptions = { transaction: t }
-
- // Save video object in database
- const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight & MVideoTag)
- videoCreated.VideoChannel = videoChannel
-
- if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
- if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
-
- await autoBlacklistVideoIfNeeded({
- video: videoCreated,
- user,
- notify: false,
- isRemote: false,
- isNew: true,
- transaction: t
+async function processTorrentOrAbortRequest (req: express.Request, res: express.Response, torrentfile: Express.Multer.File) {
+ const torrentName = torrentfile.originalname
+
+ // Rename the torrent to a secured name
+ const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName))
+ await move(torrentfile.path, newTorrentPath, { overwrite: true })
+ torrentfile.path = newTorrentPath
+
+ const buf = await readFile(torrentfile.path)
+ const parsedTorrent = parseTorrent(buf) as Instance
+
+ if (parsedTorrent.files.length !== 1) {
+ cleanUpReqFiles(req)
+
+ res.fail({
+ type: ServerErrorCode.INCORRECT_FILES_IN_TORRENT,
+ message: 'Torrents with only 1 file are supported.'