diff options
Diffstat (limited to 'shared/utils/videos/videos.ts')
-rw-r--r-- | shared/utils/videos/videos.ts | 29 |
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 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { existsSync, readdir, readFile } from 'fs-extra' | 4 | 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' |
@@ -16,7 +16,7 @@ import { | |||
16 | ServerInfo, | 16 | ServerInfo, |
17 | testImage | 17 | testImage |
18 | } from '../' | 18 | } from '../' |
19 | 19 | import * as validator from 'validator' | |
20 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | 20 | import { VideoDetails, VideoPrivacy } from '../../models/videos' |
21 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 21 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' |
22 | import { dateIsValid, webtorrentAdd } from '../miscs/miscs' | 22 | import { 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 | ||
600 | async 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 | |||
607 | async 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 | ||
602 | export { | 619 | export { |
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 | } |