aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-25 13:56:07 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-25 15:01:07 +0100
commitd61893f7236abbed30c25b1823e6ecad93a8e8dd (patch)
tree9cf1d47598d9a99f390c6754d289d2573788451d /shared
parentd7df188f23bb3c4773ac26e6fa8b3d82b1229e6d (diff)
downloadPeerTube-d61893f7236abbed30c25b1823e6ecad93a8e8dd.tar.gz
PeerTube-d61893f7236abbed30c25b1823e6ecad93a8e8dd.tar.zst
PeerTube-d61893f7236abbed30c25b1823e6ecad93a8e8dd.zip
Async torrent creation
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/videos/videos.ts27
1 files changed, 24 insertions, 3 deletions
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index 929eb42ca..0b6a54046 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -1,6 +1,5 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2 2
3import { HttpStatusCode } from '@shared/core-utils'
4import { expect } from 'chai' 3import { expect } from 'chai'
5import { pathExists, readdir, readFile } from 'fs-extra' 4import { pathExists, readdir, readFile } from 'fs-extra'
6import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
@@ -8,9 +7,18 @@ import { extname, join } from 'path'
8import * as request from 'supertest' 7import * as request from 'supertest'
9import { v4 as uuidv4 } from 'uuid' 8import { v4 as uuidv4 } from 'uuid'
10import validator from 'validator' 9import validator from 'validator'
10import { HttpStatusCode } from '@shared/core-utils'
11import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' 11import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
12import { VideoDetails, VideoPrivacy } from '../../models/videos' 12import { VideoDetails, VideoPrivacy } from '../../models/videos'
13import { buildAbsoluteFixturePath, buildServerDirectory, dateIsValid, immutableAssign, testImage, webtorrentAdd } from '../miscs/miscs' 13import {
14 buildAbsoluteFixturePath,
15 buildServerDirectory,
16 dateIsValid,
17 immutableAssign,
18 testImage,
19 wait,
20 webtorrentAdd
21} from '../miscs/miscs'
14import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests' 22import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests'
15import { waitJobs } from '../server/jobs' 23import { waitJobs } from '../server/jobs'
16import { ServerInfo } from '../server/servers' 24import { ServerInfo } from '../server/servers'
@@ -423,8 +431,21 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
423 req.field('originallyPublishedAt', attributes.originallyPublishedAt) 431 req.field('originallyPublishedAt', attributes.originallyPublishedAt)
424 } 432 }
425 433
426 return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) 434 const res = await req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture))
427 .expect(specialStatus) 435 .expect(specialStatus)
436
437 // Wait torrent generation
438 if (specialStatus === HttpStatusCode.OK_200) {
439 let video: VideoDetails
440 do {
441 const resVideo = await getVideoWithToken(url, accessToken, res.body.video.uuid)
442 video = resVideo.body
443
444 await wait(50)
445 } while (!video.files[0].torrentUrl)
446 }
447
448 return res
428} 449}
429 450
430function updateVideo ( 451function updateVideo (