aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-01-27 08:30:56 +0100
committerChocobozzz <me@florianbigard.com>2023-01-27 08:30:56 +0100
commit8059e050ef4e800c95851ac97abbb2330fe17882 (patch)
tree6cd6cc94cea7d5234e95ddb86aed5be206c4f81c /server
parent2e5dd0bef8797dad82e5a908c30bc126cb924033 (diff)
downloadPeerTube-8059e050ef4e800c95851ac97abbb2330fe17882.tar.gz
PeerTube-8059e050ef4e800c95851ac97abbb2330fe17882.tar.zst
PeerTube-8059e050ef4e800c95851ac97abbb2330fe17882.zip
Fix live with base url object storage
Diffstat (limited to 'server')
-rw-r--r--server/lib/live/live-manager.ts4
-rw-r--r--server/lib/object-storage/urls.ts2
-rw-r--r--server/tests/api/object-storage/live.ts62
-rw-r--r--server/tests/api/object-storage/videos.ts12
-rw-r--r--server/tests/shared/live.ts23
-rw-r--r--server/tests/shared/mock-servers/mock-object-storage.ts2
6 files changed, 89 insertions, 16 deletions
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts
index 9ea983119..fa4e1df07 100644
--- a/server/lib/live/live-manager.ts
+++ b/server/lib/live/live-manager.ts
@@ -487,7 +487,9 @@ class LiveManager {
487 ? VideoStorage.OBJECT_STORAGE 487 ? VideoStorage.OBJECT_STORAGE
488 : VideoStorage.FILE_SYSTEM 488 : VideoStorage.FILE_SYSTEM
489 489
490 playlist.assignP2PMediaLoaderInfoHashes(video, allResolutions) 490 if (playlist.storage === VideoStorage.FILE_SYSTEM) {
491 playlist.assignP2PMediaLoaderInfoHashes(video, allResolutions)
492 }
491 493
492 return playlist.save() 494 return playlist.save()
493 } 495 }
diff --git a/server/lib/object-storage/urls.ts b/server/lib/object-storage/urls.ts
index a47a98b98..b8ef94559 100644
--- a/server/lib/object-storage/urls.ts
+++ b/server/lib/object-storage/urls.ts
@@ -57,5 +57,7 @@ function getBaseUrl (bucketInfo: BucketInfo, baseUrl?: string) {
57 57
58const regex = new RegExp('https?://[^/]+') 58const regex = new RegExp('https?://[^/]+')
59function replaceByBaseUrl (fileUrl: string, baseUrl: string) { 59function replaceByBaseUrl (fileUrl: string, baseUrl: string) {
60 if (!fileUrl) return fileUrl
61
60 return fileUrl.replace(regex, baseUrl) 62 return fileUrl.replace(regex, baseUrl)
61} 63}
diff --git a/server/tests/api/object-storage/live.ts b/server/tests/api/object-storage/live.ts
index ad2b554b7..2a3fc4779 100644
--- a/server/tests/api/object-storage/live.ts
+++ b/server/tests/api/object-storage/live.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { expectStartWith, testVideoResolutions } from '@server/tests/shared' 4import { expectStartWith, MockObjectStorageProxy, testVideoResolutions } from '@server/tests/shared'
5import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' 5import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
6import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models' 6import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models'
7import { 7import {
@@ -93,7 +93,7 @@ describe('Object storage for lives', function () {
93 await servers[0].config.enableTranscoding() 93 await servers[0].config.enableTranscoding()
94 }) 94 })
95 95
96 describe('Without live transcoding', async function () { 96 describe('Without live transcoding', function () {
97 let videoUUID: string 97 let videoUUID: string
98 98
99 before(async function () { 99 before(async function () {
@@ -134,7 +134,7 @@ describe('Object storage for lives', function () {
134 }) 134 })
135 }) 135 })
136 136
137 describe('With live transcoding', async function () { 137 describe('With live transcoding', function () {
138 const resolutions = [ 720, 480, 360, 240, 144 ] 138 const resolutions = [ 720, 480, 360, 240, 144 ]
139 139
140 before(async function () { 140 before(async function () {
@@ -223,6 +223,62 @@ describe('Object storage for lives', function () {
223 }) 223 })
224 }) 224 })
225 225
226 describe('With object storage base url', function () {
227 const mockObjectStorageProxy = new MockObjectStorageProxy()
228 let baseMockUrl: string
229
230 before(async function () {
231 this.timeout(120000)
232
233 const port = await mockObjectStorageProxy.initialize()
234 baseMockUrl = `http://127.0.0.1:${port}/streaming-playlists`
235
236 await ObjectStorageCommand.createMockBucket('streaming-playlists')
237
238 const config = {
239 object_storage: {
240 enabled: true,
241 endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(),
242 region: ObjectStorageCommand.getMockRegion(),
243
244 credentials: ObjectStorageCommand.getMockCredentialsConfig(),
245
246 streaming_playlists: {
247 bucket_name: 'streaming-playlists',
248 prefix: '',
249 base_url: baseMockUrl
250 }
251 }
252 }
253
254 await servers[0].kill()
255 await servers[0].run(config)
256
257 await servers[0].config.enableLive({ transcoding: true, resolutions: 'min' })
258 })
259
260 it('Should publish a live and replace the base url', async function () {
261 this.timeout(240000)
262
263 const videoUUIDPermanent = await createLive(servers[0], true)
264
265 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDPermanent })
266 await waitUntilLivePublishedOnAllServers(servers, videoUUIDPermanent)
267
268 await testVideoResolutions({
269 originServer: servers[0],
270 servers,
271 liveVideoId: videoUUIDPermanent,
272 resolutions: [ 720 ],
273 transcoded: true,
274 objectStorage: true,
275 objectStorageBaseUrl: baseMockUrl
276 })
277
278 await stopFfmpeg(ffmpegCommand)
279 })
280 })
281
226 after(async function () { 282 after(async function () {
227 await killallServers(servers) 283 await killallServers(servers)
228 }) 284 })
diff --git a/server/tests/api/object-storage/videos.ts b/server/tests/api/object-storage/videos.ts
index 1b3c389d7..6862658cc 100644
--- a/server/tests/api/object-storage/videos.ts
+++ b/server/tests/api/object-storage/videos.ts
@@ -9,7 +9,7 @@ import {
9 expectLogDoesNotContain, 9 expectLogDoesNotContain,
10 expectStartWith, 10 expectStartWith,
11 generateHighBitrateVideo, 11 generateHighBitrateVideo,
12 MockObjectStorage 12 MockObjectStorageProxy
13} from '@server/tests/shared' 13} from '@server/tests/shared'
14import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' 14import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
15import { HttpStatusCode, VideoDetails } from '@shared/models' 15import { HttpStatusCode, VideoDetails } from '@shared/models'
@@ -124,7 +124,7 @@ function runTestSuite (options: {
124 124
125 useMockBaseUrl?: boolean 125 useMockBaseUrl?: boolean
126}) { 126}) {
127 const mockObjectStorage = new MockObjectStorage() 127 const mockObjectStorageProxy = new MockObjectStorageProxy()
128 const { fixture } = options 128 const { fixture } = options
129 let baseMockUrl: string 129 let baseMockUrl: string
130 130
@@ -138,8 +138,10 @@ function runTestSuite (options: {
138 before(async function () { 138 before(async function () {
139 this.timeout(120000) 139 this.timeout(120000)
140 140
141 const port = await mockObjectStorage.initialize() 141 const port = await mockObjectStorageProxy.initialize()
142 baseMockUrl = options.useMockBaseUrl ? `http://127.0.0.1:${port}` : undefined 142 baseMockUrl = options.useMockBaseUrl
143 ? `http://127.0.0.1:${port}`
144 : undefined
143 145
144 await ObjectStorageCommand.createMockBucket(options.playlistBucket) 146 await ObjectStorageCommand.createMockBucket(options.playlistBucket)
145 await ObjectStorageCommand.createMockBucket(options.webtorrentBucket) 147 await ObjectStorageCommand.createMockBucket(options.webtorrentBucket)
@@ -254,7 +256,7 @@ function runTestSuite (options: {
254 }) 256 })
255 257
256 after(async function () { 258 after(async function () {
257 await mockObjectStorage.terminate() 259 await mockObjectStorageProxy.terminate()
258 260
259 await cleanupTests(servers) 261 await cleanupTests(servers)
260 }) 262 })
diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts
index 1c868eb5b..ff0b2f226 100644
--- a/server/tests/shared/live.ts
+++ b/server/tests/shared/live.ts
@@ -3,10 +3,10 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path' 5import { join } from 'path'
6import { sha1 } from '@shared/extra-utils'
6import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models' 7import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models'
7import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands' 8import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands'
8import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists' 9import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists'
9import { sha1 } from '@shared/extra-utils'
10 10
11async function checkLiveCleanup (options: { 11async function checkLiveCleanup (options: {
12 server: PeerTubeServer 12 server: PeerTubeServer
@@ -42,9 +42,19 @@ async function testVideoResolutions (options: {
42 liveVideoId: string 42 liveVideoId: string
43 resolutions: number[] 43 resolutions: number[]
44 transcoded: boolean 44 transcoded: boolean
45
45 objectStorage: boolean 46 objectStorage: boolean
47 objectStorageBaseUrl?: string
46}) { 48}) {
47 const { originServer, servers, liveVideoId, resolutions, transcoded, objectStorage } = options 49 const {
50 originServer,
51 servers,
52 liveVideoId,
53 resolutions,
54 transcoded,
55 objectStorage,
56 objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl()
57 } = options
48 58
49 for (const server of servers) { 59 for (const server of servers) {
50 const { data } = await server.videos.list() 60 const { data } = await server.videos.list()
@@ -66,7 +76,7 @@ async function testVideoResolutions (options: {
66 }) 76 })
67 77
68 if (objectStorage) { 78 if (objectStorage) {
69 expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl()) 79 expect(hlsPlaylist.playlistUrl).to.contain(objectStorageBaseUrl)
70 } 80 }
71 81
72 for (let i = 0; i < resolutions.length; i++) { 82 for (let i = 0; i < resolutions.length; i++) {
@@ -77,15 +87,16 @@ async function testVideoResolutions (options: {
77 videoUUID: video.uuid, 87 videoUUID: video.uuid,
78 playlistNumber: i, 88 playlistNumber: i,
79 segment: segmentNum, 89 segment: segmentNum,
80 objectStorage 90 objectStorage,
91 objectStorageBaseUrl
81 }) 92 })
82 93
83 const baseUrl = objectStorage 94 const baseUrl = objectStorage
84 ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls' 95 ? join(objectStorageBaseUrl, 'hls')
85 : originServer.url + '/static/streaming-playlists/hls' 96 : originServer.url + '/static/streaming-playlists/hls'
86 97
87 if (objectStorage) { 98 if (objectStorage) {
88 expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl()) 99 expect(hlsPlaylist.segmentsSha256Url).to.contain(objectStorageBaseUrl)
89 } 100 }
90 101
91 const subPlaylist = await originServer.streamingPlaylists.get({ 102 const subPlaylist = await originServer.streamingPlaylists.get({
diff --git a/server/tests/shared/mock-servers/mock-object-storage.ts b/server/tests/shared/mock-servers/mock-object-storage.ts
index 8c325bf11..ae76c4f3f 100644
--- a/server/tests/shared/mock-servers/mock-object-storage.ts
+++ b/server/tests/shared/mock-servers/mock-object-storage.ts
@@ -5,7 +5,7 @@ import { pipeline } from 'stream'
5import { ObjectStorageCommand } from '@shared/server-commands' 5import { ObjectStorageCommand } from '@shared/server-commands'
6import { getPort, randomListen, terminateServer } from './shared' 6import { getPort, randomListen, terminateServer } from './shared'
7 7
8export class MockObjectStorage { 8export class MockObjectStorageProxy {
9 private server: Server 9 private server: Server
10 10
11 async initialize () { 11 async initialize () {