1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

Put private videos under a specific subdirectory

This commit is contained in:
Chocobozzz 2022-10-12 16:09:02 +02:00 committed by Chocobozzz
parent 38a3ccc7f8
commit 3545e72c68
105 changed files with 2929 additions and 1308 deletions

View file

@ -3,7 +3,7 @@
import { decode } from 'querystring'
import request from 'supertest'
import { URL } from 'url'
import { buildAbsoluteFixturePath } from '@shared/core-utils'
import { buildAbsoluteFixturePath, pick } from '@shared/core-utils'
import { HttpStatusCode } from '@shared/models'
export type CommonRequestParams = {
@ -21,10 +21,21 @@ export type CommonRequestParams = {
expectedStatus?: HttpStatusCode
}
function makeRawRequest (url: string, expectedStatus?: HttpStatusCode, range?: string) {
const { host, protocol, pathname } = new URL(url)
function makeRawRequest (options: {
url: string
token?: string
expectedStatus?: HttpStatusCode
range?: string
query?: { [ id: string ]: string }
}) {
const { host, protocol, pathname } = new URL(options.url)
return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, expectedStatus, range })
return makeGetRequest({
url: `${protocol}//${host}`,
path: pathname,
...pick(options, [ 'expectedStatus', 'range', 'token', 'query' ])
})
}
function makeGetRequest (options: CommonRequestParams & {

View file

@ -36,6 +36,7 @@ import {
StreamingPlaylistsCommand,
VideosCommand,
VideoStudioCommand,
VideoTokenCommand,
ViewsCommand
} from '../videos'
import { CommentsCommand } from '../videos/comments-command'
@ -145,6 +146,7 @@ export class PeerTubeServer {
videoStats?: VideoStatsCommand
views?: ViewsCommand
twoFactor?: TwoFactorCommand
videoToken?: VideoTokenCommand
constructor (options: { serverNumber: number } | { url: string }) {
if ((options as any).url) {
@ -427,5 +429,6 @@ export class PeerTubeServer {
this.videoStats = new VideoStatsCommand(this)
this.views = new ViewsCommand(this)
this.twoFactor = new TwoFactorCommand(this)
this.videoToken = new VideoTokenCommand(this)
}
}

View file

@ -14,5 +14,6 @@ export * from './services-command'
export * from './streaming-playlists-command'
export * from './comments-command'
export * from './video-studio-command'
export * from './video-token-command'
export * from './views-command'
export * from './videos-command'

View file

@ -12,6 +12,7 @@ import {
ResultList,
VideoCreateResult,
VideoDetails,
VideoPrivacy,
VideoState
} from '@shared/models'
import { unwrapBody } from '../requests'
@ -115,6 +116,31 @@ export class LiveCommand extends AbstractCommand {
return body.video
}
async quickCreate (options: OverrideCommandOptions & {
saveReplay: boolean
permanentLive: boolean
privacy?: VideoPrivacy
}) {
const { saveReplay, permanentLive, privacy } = options
const { uuid } = await this.create({
...options,
fields: {
name: 'live',
permanentLive,
saveReplay,
channelId: this.server.store.channel.id,
privacy
}
})
const video = await this.server.videos.getWithToken({ id: uuid })
const live = await this.get({ videoId: uuid })
return { video, live }
}
// ---------------------------------------------------------------------------
async sendRTMPStreamInVideo (options: OverrideCommandOptions & {

View file

@ -1,6 +1,6 @@
import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg'
import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
import { VideoDetails, VideoInclude } from '@shared/models'
import { VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models'
import { PeerTubeServer } from '../server/server'
function sendRTMPStream (options: {
@ -98,7 +98,10 @@ async function waitUntilLiveReplacedByReplayOnAllServers (servers: PeerTubeServe
}
async function findExternalSavedVideo (server: PeerTubeServer, liveDetails: VideoDetails) {
const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include: VideoInclude.BLACKLISTED })
const include = VideoInclude.BLACKLISTED
const privacyOneOf = [ VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.PUBLIC, VideoPrivacy.UNLISTED ]
const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include, privacyOneOf })
return data.find(v => v.name === liveDetails.name + ' - ' + new Date(liveDetails.publishedAt).toLocaleString())
}

View file

@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
import { HttpStatusCode, VideoToken } from '@shared/models'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class VideoTokenCommand extends AbstractCommand {
create (options: OverrideCommandOptions & {
videoId: number | string
}) {
const { videoId } = options
const path = '/api/v1/videos/' + videoId + '/token'
return unwrapBody<VideoToken>(this.postBodyRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
}))
}
async getVideoFileToken (options: OverrideCommandOptions & {
videoId: number | string
}) {
const { files } = await this.create(options)
return files.token
}
}

View file

@ -342,8 +342,9 @@ export class VideosCommand extends AbstractCommand {
async upload (options: OverrideCommandOptions & {
attributes?: VideoEdit
mode?: 'legacy' | 'resumable' // default legacy
waitTorrentGeneration?: boolean // default true
} = {}) {
const { mode = 'legacy' } = options
const { mode = 'legacy', waitTorrentGeneration } = options
let defaultChannelId = 1
try {
@ -377,7 +378,7 @@ export class VideosCommand extends AbstractCommand {
// Wait torrent generation
const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 })
if (expectedStatus === HttpStatusCode.OK_200) {
if (expectedStatus === HttpStatusCode.OK_200 && waitTorrentGeneration) {
let video: VideoDetails
do {
@ -692,6 +693,7 @@ export class VideosCommand extends AbstractCommand {
'categoryOneOf',
'licenceOneOf',
'languageOneOf',
'privacyOneOf',
'tagsOneOf',
'tagsAllOf',
'isLocal',