aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/videos')
-rw-r--r--shared/extra-utils/videos/videos.ts48
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'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, join } from 'path' 6import { extname, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { v4 as uuidv4 } from 'uuid'
9import validator from 'validator'
10import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
11import { VideoDetails, VideoPrivacy } from '../../models/videos'
8import { 12import {
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'
19import validator from 'validator' 21import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests'
20import { VideoDetails, VideoPrivacy } from '../../models/videos' 22import { waitJobs } from '../server/jobs'
21import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, loadLanguages, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' 23import { ServerInfo } from '../server/servers'
22import { dateIsValid, webtorrentAdd, buildServerDirectory } from '../miscs/miscs' 24import { getMyUserInformation } from '../users/users'
23 25
24loadLanguages() 26loadLanguages()
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
650async 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
659async 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
649export { 673export {
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,