diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-25 13:56:07 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-02-25 15:01:07 +0100 |
commit | d61893f7236abbed30c25b1823e6ecad93a8e8dd (patch) | |
tree | 9cf1d47598d9a99f390c6754d289d2573788451d /shared/extra-utils | |
parent | d7df188f23bb3c4773ac26e6fa8b3d82b1229e6d (diff) | |
download | PeerTube-d61893f7236abbed30c25b1823e6ecad93a8e8dd.tar.gz PeerTube-d61893f7236abbed30c25b1823e6ecad93a8e8dd.tar.zst PeerTube-d61893f7236abbed30c25b1823e6ecad93a8e8dd.zip |
Async torrent creation
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 27 |
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 | ||
3 | import { HttpStatusCode } from '@shared/core-utils' | ||
4 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
5 | import { pathExists, readdir, readFile } from 'fs-extra' | 4 | import { pathExists, readdir, readFile } from 'fs-extra' |
6 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
@@ -8,9 +7,18 @@ import { extname, join } from 'path' | |||
8 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
9 | import { v4 as uuidv4 } from 'uuid' | 8 | import { v4 as uuidv4 } from 'uuid' |
10 | import validator from 'validator' | 9 | import validator from 'validator' |
10 | import { HttpStatusCode } from '@shared/core-utils' | ||
11 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 11 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' |
12 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | 12 | import { VideoDetails, VideoPrivacy } from '../../models/videos' |
13 | import { buildAbsoluteFixturePath, buildServerDirectory, dateIsValid, immutableAssign, testImage, webtorrentAdd } from '../miscs/miscs' | 13 | import { |
14 | buildAbsoluteFixturePath, | ||
15 | buildServerDirectory, | ||
16 | dateIsValid, | ||
17 | immutableAssign, | ||
18 | testImage, | ||
19 | wait, | ||
20 | webtorrentAdd | ||
21 | } from '../miscs/miscs' | ||
14 | import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests' | 22 | import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests' |
15 | import { waitJobs } from '../server/jobs' | 23 | import { waitJobs } from '../server/jobs' |
16 | import { ServerInfo } from '../server/servers' | 24 | import { 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 | ||
430 | function updateVideo ( | 451 | function updateVideo ( |