diff options
Diffstat (limited to 'shared/extra-utils/videos')
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 99e591cb2..2f7f2182c 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -5,21 +5,23 @@ import { pathExists, readdir, readFile } from 'fs-extra' | |||
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { extname, join } from 'path' | 6 | import { extname, join } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import { v4 as uuidv4 } from 'uuid' | ||
9 | import validator from 'validator' | ||
10 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | ||
11 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | ||
8 | import { | 12 | import { |
9 | buildAbsoluteFixturePath, | 13 | buildAbsoluteFixturePath, |
10 | getMyUserInformation, | 14 | buildServerDirectory, |
15 | dateIsValid, | ||
11 | immutableAssign, | 16 | immutableAssign, |
12 | makeGetRequest, | ||
13 | makePutBodyRequest, | ||
14 | makeUploadRequest, | ||
15 | root, | 17 | root, |
16 | ServerInfo, | 18 | testImage, |
17 | testImage | 19 | webtorrentAdd |
18 | } from '../' | 20 | } from '../miscs/miscs' |
19 | import validator from 'validator' | 21 | import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' |
20 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | 22 | import { waitJobs } from '../server/jobs' |
21 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, loadLanguages, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 23 | import { ServerInfo } from '../server/servers' |
22 | import { dateIsValid, webtorrentAdd, buildServerDirectory } from '../miscs/miscs' | 24 | import { getMyUserInformation } from '../users/users' |
23 | 25 | ||
24 | loadLanguages() | 26 | loadLanguages() |
25 | 27 | ||
@@ -644,11 +646,34 @@ async function getLocalIdByUUID (url: string, uuid: string) { | |||
644 | return res.body.id | 646 | return res.body.id |
645 | } | 647 | } |
646 | 648 | ||
649 | // serverNumber starts from 1 | ||
650 | async function uploadRandomVideoOnServers (servers: ServerInfo[], serverNumber: number, additionalParams: any = {}) { | ||
651 | const server = servers.find(s => s.serverNumber === serverNumber) | ||
652 | const res = await uploadRandomVideo(server, false, additionalParams) | ||
653 | |||
654 | await waitJobs(servers) | ||
655 | |||
656 | return res | ||
657 | } | ||
658 | |||
659 | async function uploadRandomVideo (server: ServerInfo, wait = true, additionalParams: any = {}) { | ||
660 | const prefixName = additionalParams.prefixName || '' | ||
661 | const name = prefixName + uuidv4() | ||
662 | |||
663 | const data = Object.assign({ name }, additionalParams) | ||
664 | const res = await uploadVideo(server.url, server.accessToken, data) | ||
665 | |||
666 | if (wait) await waitJobs([ server ]) | ||
667 | |||
668 | return { uuid: res.body.video.uuid, name } | ||
669 | } | ||
670 | |||
647 | // --------------------------------------------------------------------------- | 671 | // --------------------------------------------------------------------------- |
648 | 672 | ||
649 | export { | 673 | export { |
650 | getVideoDescription, | 674 | getVideoDescription, |
651 | getVideoCategories, | 675 | getVideoCategories, |
676 | uploadRandomVideo, | ||
652 | getVideoLicences, | 677 | getVideoLicences, |
653 | videoUUIDToId, | 678 | videoUUIDToId, |
654 | getVideoPrivacies, | 679 | getVideoPrivacies, |
@@ -666,6 +691,7 @@ export { | |||
666 | getVideosListWithToken, | 691 | getVideosListWithToken, |
667 | uploadVideo, | 692 | uploadVideo, |
668 | getVideosWithFilters, | 693 | getVideosWithFilters, |
694 | uploadRandomVideoOnServers, | ||
669 | updateVideo, | 695 | updateVideo, |
670 | rateVideo, | 696 | rateVideo, |
671 | viewVideo, | 697 | viewVideo, |