aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/videos/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils/videos/videos.ts')
-rw-r--r--shared/utils/videos/videos.ts29
1 files changed, 24 insertions, 5 deletions
diff --git a/shared/utils/videos/videos.ts b/shared/utils/videos/videos.ts
index 2c09f0086..16b5165f1 100644
--- a/shared/utils/videos/videos.ts
+++ b/shared/utils/videos/videos.ts
@@ -1,7 +1,7 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { existsSync, readdir, readFile } from 'fs-extra' 4import { 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'
@@ -16,7 +16,7 @@ import {
16 ServerInfo, 16 ServerInfo,
17 testImage 17 testImage
18} from '../' 18} from '../'
19 19import * as validator from 'validator'
20import { VideoDetails, VideoPrivacy } from '../../models/videos' 20import { VideoDetails, VideoPrivacy } from '../../models/videos'
21import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' 21import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
22import { dateIsValid, webtorrentAdd } from '../miscs/miscs' 22import { dateIsValid, webtorrentAdd } from '../miscs/miscs'
@@ -311,8 +311,8 @@ async function checkVideoFilesWereRemoved (
311 for (const directory of directories) { 311 for (const directory of directories) {
312 const directoryPath = join(root(), testDirectory, directory) 312 const directoryPath = join(root(), testDirectory, directory)
313 313
314 const directoryExists = existsSync(directoryPath) 314 const directoryExists = await pathExists(directoryPath)
315 if (!directoryExists) continue 315 if (directoryExists === false) continue
316 316
317 const files = await readdir(directoryPath) 317 const files = await readdir(directoryPath)
318 for (const file of files) { 318 for (const file of files) {
@@ -597,12 +597,30 @@ async function completeVideoCheck (
597 } 597 }
598} 598}
599 599
600async function videoUUIDToId (url: string, id: number | string) {
601 if (validator.isUUID('' + id) === false) return id
602
603 const res = await getVideo(url, id)
604 return res.body.id
605}
606
607async function uploadVideoAndGetId (options: { server: ServerInfo, videoName: string, nsfw?: boolean, token?: string }) {
608 const videoAttrs: any = { name: options.videoName }
609 if (options.nsfw) videoAttrs.nsfw = options.nsfw
610
611
612 const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
613
614 return { id: res.body.video.id, uuid: res.body.video.uuid }
615}
616
600// --------------------------------------------------------------------------- 617// ---------------------------------------------------------------------------
601 618
602export { 619export {
603 getVideoDescription, 620 getVideoDescription,
604 getVideoCategories, 621 getVideoCategories,
605 getVideoLicences, 622 getVideoLicences,
623 videoUUIDToId,
606 getVideoPrivacies, 624 getVideoPrivacies,
607 getVideoLanguages, 625 getVideoLanguages,
608 getMyVideos, 626 getMyVideos,
@@ -624,5 +642,6 @@ export {
624 getLocalVideos, 642 getLocalVideos,
625 completeVideoCheck, 643 completeVideoCheck,
626 checkVideoFilesWereRemoved, 644 checkVideoFilesWereRemoved,
627 getPlaylistVideos 645 getPlaylistVideos,
646 uploadVideoAndGetId
628} 647}