X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Futils%2Fvideos%2Fvideos.ts;h=2c09f008604556cdc226a79f37047b4f33fe9545;hb=418d092afa81e2c8fe8ac6838fc4b5eb0af6a782;hp=b3206e56606b78666bf3dbf245c89722084124b8;hpb=b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/utils/videos/videos.ts b/shared/utils/videos/videos.ts index b3206e566..2c09f0086 100644 --- a/shared/utils/videos/videos.ts +++ b/shared/utils/videos/videos.ts @@ -16,9 +16,10 @@ import { ServerInfo, testImage } from '../' + import { VideoDetails, VideoPrivacy } from '../../models/videos' -import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers' -import { dateIsValid, webtorrentAdd } from '../index' +import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' +import { dateIsValid, webtorrentAdd } from '../miscs/miscs' type VideoAttributes = { name?: string @@ -27,8 +28,10 @@ type VideoAttributes = { language?: string nsfw?: boolean commentsEnabled?: boolean + downloadEnabled?: boolean waitTranscoding?: boolean description?: string + originallyPublishedAt?: string tags?: string[] channelId?: number privacy?: VideoPrivacy @@ -220,6 +223,28 @@ function getVideoChannelVideos ( }) } +function getPlaylistVideos ( + url: string, + accessToken: string, + playlistId: number | string, + start: number, + count: number, + query: { nsfw?: boolean } = {} +) { + const path = '/api/v1/video-playlists/' + playlistId + '/videos' + + return makeGetRequest({ + url, + path, + query: immutableAssign(query, { + start, + count + }), + token: accessToken, + statusCodeExpected: 200 + }) +} + function getVideosListPagination (url: string, start: number, count: number, sort?: string) { const path = '/api/v1/videos' @@ -270,7 +295,16 @@ function removeVideo (url: string, token: string, id: number | string, expectedS async function checkVideoFilesWereRemoved ( videoUUID: string, serverNumber: number, - directories = [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ] + directories = [ + 'redundancy', + 'videos', + 'thumbnails', + 'torrents', + 'previews', + 'captions', + join('playlists', 'hls'), + join('redundancy', 'hls') + ] ) { const testDirectory = 'test' + serverNumber @@ -278,7 +312,7 @@ async function checkVideoFilesWereRemoved ( const directoryPath = join(root(), testDirectory, directory) const directoryExists = existsSync(directoryPath) - expect(directoryExists).to.be.true + if (!directoryExists) continue const files = await readdir(directoryPath) for (const file of files) { @@ -310,6 +344,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg tags: [ 'tag' ], privacy: VideoPrivacy.PUBLIC, commentsEnabled: true, + downloadEnabled: true, fixture: 'video_short.webm' }, videoAttributesArg) @@ -320,6 +355,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg .field('name', attributes.name) .field('nsfw', JSON.stringify(attributes.nsfw)) .field('commentsEnabled', JSON.stringify(attributes.commentsEnabled)) + .field('downloadEnabled', JSON.stringify(attributes.downloadEnabled)) .field('waitTranscoding', JSON.stringify(attributes.waitTranscoding)) .field('privacy', attributes.privacy.toString()) .field('channelId', attributes.channelId) @@ -356,6 +392,10 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg } } + if (attributes.originallyPublishedAt !== undefined) { + req.field('originallyPublishedAt', attributes.originallyPublishedAt) + } + return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) .expect(specialStatus) } @@ -370,6 +410,8 @@ function updateVideo (url: string, accessToken: string, id: number | string, att if (attributes.language) body['language'] = attributes.language if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw) if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled) + if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled) + if (attributes.originallyPublishedAt !== undefined) body['originallyPublishedAt'] = attributes.originallyPublishedAt if (attributes.description) body['description'] = attributes.description if (attributes.tags) body['tags'] = attributes.tags if (attributes.privacy) body['privacy'] = attributes.privacy @@ -416,7 +458,7 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { return new Promise((res, rej) => { const torrentName = videoUUID + '-' + resolution + '.torrent' - const torrentPath = join(__dirname, '..', '..', '..', '..', 'test' + server.serverNumber, 'torrents', torrentName) + const torrentPath = join(root(), 'test' + server.serverNumber, 'torrents', torrentName) readFile(torrentPath, (err, data) => { if (err) return rej(err) @@ -435,9 +477,11 @@ async function completeVideoCheck ( language: string nsfw: boolean commentsEnabled: boolean + downloadEnabled: boolean description: string publishedAt?: string support: string + originallyPublishedAt?: string, account: { name: string host: string @@ -495,6 +539,12 @@ async function completeVideoCheck ( expect(video.publishedAt).to.equal(attributes.publishedAt) } + if (attributes.originallyPublishedAt) { + expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt) + } else { + expect(video.originallyPublishedAt).to.be.null + } + const res = await getVideo(url, video.uuid) const videoDetails: VideoDetails = res.body @@ -509,6 +559,7 @@ async function completeVideoCheck ( expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) + expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled) for (const attributeFile of attributes.files) { const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution) @@ -572,5 +623,6 @@ export { parseTorrentVideo, getLocalVideos, completeVideoCheck, - checkVideoFilesWereRemoved + checkVideoFilesWereRemoved, + getPlaylistVideos }