aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-12 16:09:02 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-10-24 14:48:24 +0200
commit3545e72c686ff1725bbdfd8d16d693e2f4aa75a3 (patch)
treee7f1d12ef5dae1e1142c3a8d0b681c1dbbb0de10 /shared
parent38a3ccc7f8ad0ea94362b58c732af7c387ab46be (diff)
downloadPeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.gz
PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.zst
PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.zip
Put private videos under a specific subdirectory
Diffstat (limited to 'shared')
-rw-r--r--shared/core-utils/common/url.ts12
-rw-r--r--shared/models/server/debug.model.ts1
-rw-r--r--shared/models/videos/index.ts2
-rw-r--r--shared/models/videos/video-token.model.ts6
-rw-r--r--shared/server-commands/requests/requests.ts19
-rw-r--r--shared/server-commands/server/server.ts3
-rw-r--r--shared/server-commands/videos/index.ts1
-rw-r--r--shared/server-commands/videos/live-command.ts26
-rw-r--r--shared/server-commands/videos/live.ts7
-rw-r--r--shared/server-commands/videos/video-token-command.ts31
-rw-r--r--shared/server-commands/videos/videos-command.ts6
11 files changed, 106 insertions, 8 deletions
diff --git a/shared/core-utils/common/url.ts b/shared/core-utils/common/url.ts
index fd54e7594..d1c399f7b 100644
--- a/shared/core-utils/common/url.ts
+++ b/shared/core-utils/common/url.ts
@@ -1,6 +1,16 @@
1import { Video, VideoPlaylist } from '../../models' 1import { Video, VideoPlaylist } from '../../models'
2import { secondsToTime } from './date' 2import { secondsToTime } from './date'
3 3
4function addQueryParams (url: string, params: { [ id: string ]: string }) {
5 const objUrl = new URL(url)
6
7 for (const key of Object.keys(params)) {
8 objUrl.searchParams.append(key, params[key])
9 }
10
11 return objUrl.toString()
12}
13
4function buildPlaylistLink (playlist: Pick<VideoPlaylist, 'shortUUID'>, base?: string) { 14function buildPlaylistLink (playlist: Pick<VideoPlaylist, 'shortUUID'>, base?: string) {
5 return (base ?? window.location.origin) + buildPlaylistWatchPath(playlist) 15 return (base ?? window.location.origin) + buildPlaylistWatchPath(playlist)
6} 16}
@@ -103,6 +113,8 @@ function decoratePlaylistLink (options: {
103// --------------------------------------------------------------------------- 113// ---------------------------------------------------------------------------
104 114
105export { 115export {
116 addQueryParams,
117
106 buildPlaylistLink, 118 buildPlaylistLink,
107 buildVideoLink, 119 buildVideoLink,
108 120
diff --git a/shared/models/server/debug.model.ts b/shared/models/server/debug.model.ts
index 1c4597b8b..41f2109af 100644
--- a/shared/models/server/debug.model.ts
+++ b/shared/models/server/debug.model.ts
@@ -8,4 +8,5 @@ export interface SendDebugCommand {
8 | 'process-video-views-buffer' 8 | 'process-video-views-buffer'
9 | 'process-video-viewers' 9 | 'process-video-viewers'
10 | 'process-video-channel-sync-latest' 10 | 'process-video-channel-sync-latest'
11 | 'process-update-videos-scheduler'
11} 12}
diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts
index f8e6976d3..4c1790228 100644
--- a/shared/models/videos/index.ts
+++ b/shared/models/videos/index.ts
@@ -33,6 +33,8 @@ export * from './video-storage.enum'
33export * from './video-streaming-playlist.model' 33export * from './video-streaming-playlist.model'
34export * from './video-streaming-playlist.type' 34export * from './video-streaming-playlist.type'
35 35
36export * from './video-token.model'
37
36export * from './video-update.model' 38export * from './video-update.model'
37export * from './video-view.model' 39export * from './video-view.model'
38export * from './video.model' 40export * from './video.model'
diff --git a/shared/models/videos/video-token.model.ts b/shared/models/videos/video-token.model.ts
new file mode 100644
index 000000000..aefea565f
--- /dev/null
+++ b/shared/models/videos/video-token.model.ts
@@ -0,0 +1,6 @@
1export interface VideoToken {
2 files: {
3 token: string
4 expires: string | Date
5 }
6}
diff --git a/shared/server-commands/requests/requests.ts b/shared/server-commands/requests/requests.ts
index 8cc1245e0..b247017fd 100644
--- a/shared/server-commands/requests/requests.ts
+++ b/shared/server-commands/requests/requests.ts
@@ -3,7 +3,7 @@
3import { decode } from 'querystring' 3import { decode } from 'querystring'
4import request from 'supertest' 4import request from 'supertest'
5import { URL } from 'url' 5import { URL } from 'url'
6import { buildAbsoluteFixturePath } from '@shared/core-utils' 6import { buildAbsoluteFixturePath, pick } from '@shared/core-utils'
7import { HttpStatusCode } from '@shared/models' 7import { HttpStatusCode } from '@shared/models'
8 8
9export type CommonRequestParams = { 9export type CommonRequestParams = {
@@ -21,10 +21,21 @@ export type CommonRequestParams = {
21 expectedStatus?: HttpStatusCode 21 expectedStatus?: HttpStatusCode
22} 22}
23 23
24function makeRawRequest (url: string, expectedStatus?: HttpStatusCode, range?: string) { 24function makeRawRequest (options: {
25 const { host, protocol, pathname } = new URL(url) 25 url: string
26 token?: string
27 expectedStatus?: HttpStatusCode
28 range?: string
29 query?: { [ id: string ]: string }
30}) {
31 const { host, protocol, pathname } = new URL(options.url)
32
33 return makeGetRequest({
34 url: `${protocol}//${host}`,
35 path: pathname,
26 36
27 return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, expectedStatus, range }) 37 ...pick(options, [ 'expectedStatus', 'range', 'token', 'query' ])
38 })
28} 39}
29 40
30function makeGetRequest (options: CommonRequestParams & { 41function makeGetRequest (options: CommonRequestParams & {
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts
index 7096faf21..c062e6986 100644
--- a/shared/server-commands/server/server.ts
+++ b/shared/server-commands/server/server.ts
@@ -36,6 +36,7 @@ import {
36 StreamingPlaylistsCommand, 36 StreamingPlaylistsCommand,
37 VideosCommand, 37 VideosCommand,
38 VideoStudioCommand, 38 VideoStudioCommand,
39 VideoTokenCommand,
39 ViewsCommand 40 ViewsCommand
40} from '../videos' 41} from '../videos'
41import { CommentsCommand } from '../videos/comments-command' 42import { CommentsCommand } from '../videos/comments-command'
@@ -145,6 +146,7 @@ export class PeerTubeServer {
145 videoStats?: VideoStatsCommand 146 videoStats?: VideoStatsCommand
146 views?: ViewsCommand 147 views?: ViewsCommand
147 twoFactor?: TwoFactorCommand 148 twoFactor?: TwoFactorCommand
149 videoToken?: VideoTokenCommand
148 150
149 constructor (options: { serverNumber: number } | { url: string }) { 151 constructor (options: { serverNumber: number } | { url: string }) {
150 if ((options as any).url) { 152 if ((options as any).url) {
@@ -427,5 +429,6 @@ export class PeerTubeServer {
427 this.videoStats = new VideoStatsCommand(this) 429 this.videoStats = new VideoStatsCommand(this)
428 this.views = new ViewsCommand(this) 430 this.views = new ViewsCommand(this)
429 this.twoFactor = new TwoFactorCommand(this) 431 this.twoFactor = new TwoFactorCommand(this)
432 this.videoToken = new VideoTokenCommand(this)
430 } 433 }
431} 434}
diff --git a/shared/server-commands/videos/index.ts b/shared/server-commands/videos/index.ts
index b4d6fa37b..c17f6ef20 100644
--- a/shared/server-commands/videos/index.ts
+++ b/shared/server-commands/videos/index.ts
@@ -14,5 +14,6 @@ export * from './services-command'
14export * from './streaming-playlists-command' 14export * from './streaming-playlists-command'
15export * from './comments-command' 15export * from './comments-command'
16export * from './video-studio-command' 16export * from './video-studio-command'
17export * from './video-token-command'
17export * from './views-command' 18export * from './views-command'
18export * from './videos-command' 19export * from './videos-command'
diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts
index b163f7189..de193fa49 100644
--- a/shared/server-commands/videos/live-command.ts
+++ b/shared/server-commands/videos/live-command.ts
@@ -12,6 +12,7 @@ import {
12 ResultList, 12 ResultList,
13 VideoCreateResult, 13 VideoCreateResult,
14 VideoDetails, 14 VideoDetails,
15 VideoPrivacy,
15 VideoState 16 VideoState
16} from '@shared/models' 17} from '@shared/models'
17import { unwrapBody } from '../requests' 18import { unwrapBody } from '../requests'
@@ -115,6 +116,31 @@ export class LiveCommand extends AbstractCommand {
115 return body.video 116 return body.video
116 } 117 }
117 118
119 async quickCreate (options: OverrideCommandOptions & {
120 saveReplay: boolean
121 permanentLive: boolean
122 privacy?: VideoPrivacy
123 }) {
124 const { saveReplay, permanentLive, privacy } = options
125
126 const { uuid } = await this.create({
127 ...options,
128
129 fields: {
130 name: 'live',
131 permanentLive,
132 saveReplay,
133 channelId: this.server.store.channel.id,
134 privacy
135 }
136 })
137
138 const video = await this.server.videos.getWithToken({ id: uuid })
139 const live = await this.get({ videoId: uuid })
140
141 return { video, live }
142 }
143
118 // --------------------------------------------------------------------------- 144 // ---------------------------------------------------------------------------
119 145
120 async sendRTMPStreamInVideo (options: OverrideCommandOptions & { 146 async sendRTMPStreamInVideo (options: OverrideCommandOptions & {
diff --git a/shared/server-commands/videos/live.ts b/shared/server-commands/videos/live.ts
index 0d9c32aab..ee7444b64 100644
--- a/shared/server-commands/videos/live.ts
+++ b/shared/server-commands/videos/live.ts
@@ -1,6 +1,6 @@
1import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' 1import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg'
2import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' 2import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
3import { VideoDetails, VideoInclude } from '@shared/models' 3import { VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models'
4import { PeerTubeServer } from '../server/server' 4import { PeerTubeServer } from '../server/server'
5 5
6function sendRTMPStream (options: { 6function sendRTMPStream (options: {
@@ -98,7 +98,10 @@ async function waitUntilLiveReplacedByReplayOnAllServers (servers: PeerTubeServe
98} 98}
99 99
100async function findExternalSavedVideo (server: PeerTubeServer, liveDetails: VideoDetails) { 100async function findExternalSavedVideo (server: PeerTubeServer, liveDetails: VideoDetails) {
101 const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include: VideoInclude.BLACKLISTED }) 101 const include = VideoInclude.BLACKLISTED
102 const privacyOneOf = [ VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.PUBLIC, VideoPrivacy.UNLISTED ]
103
104 const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include, privacyOneOf })
102 105
103 return data.find(v => v.name === liveDetails.name + ' - ' + new Date(liveDetails.publishedAt).toLocaleString()) 106 return data.find(v => v.name === liveDetails.name + ' - ' + new Date(liveDetails.publishedAt).toLocaleString())
104} 107}
diff --git a/shared/server-commands/videos/video-token-command.ts b/shared/server-commands/videos/video-token-command.ts
new file mode 100644
index 000000000..0531bee65
--- /dev/null
+++ b/shared/server-commands/videos/video-token-command.ts
@@ -0,0 +1,31 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2
3import { HttpStatusCode, VideoToken } from '@shared/models'
4import { unwrapBody } from '../requests'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export class VideoTokenCommand extends AbstractCommand {
8
9 create (options: OverrideCommandOptions & {
10 videoId: number | string
11 }) {
12 const { videoId } = options
13 const path = '/api/v1/videos/' + videoId + '/token'
14
15 return unwrapBody<VideoToken>(this.postBodyRequest({
16 ...options,
17
18 path,
19 implicitToken: true,
20 defaultExpectedStatus: HttpStatusCode.OK_200
21 }))
22 }
23
24 async getVideoFileToken (options: OverrideCommandOptions & {
25 videoId: number | string
26 }) {
27 const { files } = await this.create(options)
28
29 return files.token
30 }
31}
diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts
index 168391523..5ec3b6ba8 100644
--- a/shared/server-commands/videos/videos-command.ts
+++ b/shared/server-commands/videos/videos-command.ts
@@ -342,8 +342,9 @@ export class VideosCommand extends AbstractCommand {
342 async upload (options: OverrideCommandOptions & { 342 async upload (options: OverrideCommandOptions & {
343 attributes?: VideoEdit 343 attributes?: VideoEdit
344 mode?: 'legacy' | 'resumable' // default legacy 344 mode?: 'legacy' | 'resumable' // default legacy
345 waitTorrentGeneration?: boolean // default true
345 } = {}) { 346 } = {}) {
346 const { mode = 'legacy' } = options 347 const { mode = 'legacy', waitTorrentGeneration } = options
347 let defaultChannelId = 1 348 let defaultChannelId = 1
348 349
349 try { 350 try {
@@ -377,7 +378,7 @@ export class VideosCommand extends AbstractCommand {
377 378
378 // Wait torrent generation 379 // Wait torrent generation
379 const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 }) 380 const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 })
380 if (expectedStatus === HttpStatusCode.OK_200) { 381 if (expectedStatus === HttpStatusCode.OK_200 && waitTorrentGeneration) {
381 let video: VideoDetails 382 let video: VideoDetails
382 383
383 do { 384 do {
@@ -692,6 +693,7 @@ export class VideosCommand extends AbstractCommand {
692 'categoryOneOf', 693 'categoryOneOf',
693 'licenceOneOf', 694 'licenceOneOf',
694 'languageOneOf', 695 'languageOneOf',
696 'privacyOneOf',
695 'tagsOneOf', 697 'tagsOneOf',
696 'tagsAllOf', 698 'tagsAllOf',
697 'isLocal', 699 'isLocal',