diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-10 10:28:46 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-10 10:28:46 +0100 |
commit | 90701ec1d8d27d0072d6b0d2b19362d471484f9a (patch) | |
tree | a03dedc7b6119d9f6d2ea35cae9b2dde20275519 /server | |
parent | 0fbc0dec59684527fad8772080a8e1f928c07ea1 (diff) | |
download | PeerTube-90701ec1d8d27d0072d6b0d2b19362d471484f9a.tar.gz PeerTube-90701ec1d8d27d0072d6b0d2b19362d471484f9a.tar.zst PeerTube-90701ec1d8d27d0072d6b0d2b19362d471484f9a.zip |
Add hls to prune storage script
Diffstat (limited to 'server')
-rw-r--r-- | server/models/video/video-streaming-playlist.ts | 9 | ||||
-rw-r--r-- | server/tests/cli/prune-storage.ts | 49 |
2 files changed, 23 insertions, 35 deletions
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 4643c5452..e36852cad 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts | |||
@@ -198,6 +198,15 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi | |||
198 | return Object.assign(playlist, { videoId: video.id, Video: video }) | 198 | return Object.assign(playlist, { videoId: video.id, Video: video }) |
199 | } | 199 | } |
200 | 200 | ||
201 | static doesOwnedHLSPlaylistExist (videoUUID: string) { | ||
202 | const query = `SELECT 1 FROM "videoStreamingPlaylist" ` + | ||
203 | `INNER JOIN "video" ON "video"."id" = "videoStreamingPlaylist"."videoId" ` + | ||
204 | `AND "video"."remote" IS FALSE AND "video"."uuid" = $videoUUID ` + | ||
205 | `AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` | ||
206 | |||
207 | return doesExist(query, { videoUUID }) | ||
208 | } | ||
209 | |||
201 | assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) { | 210 | assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) { |
202 | const masterPlaylistUrl = this.getMasterPlaylistUrl(video) | 211 | const masterPlaylistUrl = this.getMasterPlaylistUrl(video) |
203 | 212 | ||
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index 2d4c02da7..1c0282da9 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts | |||
@@ -36,7 +36,7 @@ async function assertNotExists (server: PeerTubeServer, directory: string, subst | |||
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) { | 39 | async function assertCountAreOkay (servers: PeerTubeServer[]) { |
40 | for (const server of servers) { | 40 | for (const server of servers) { |
41 | const videosCount = await countFiles(server, 'videos') | 41 | const videosCount = await countFiles(server, 'videos') |
42 | expect(videosCount).to.equal(8) | 42 | expect(videosCount).to.equal(8) |
@@ -52,22 +52,16 @@ async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: | |||
52 | 52 | ||
53 | const avatarsCount = await countFiles(server, 'avatars') | 53 | const avatarsCount = await countFiles(server, 'avatars') |
54 | expect(avatarsCount).to.equal(2) | 54 | expect(avatarsCount).to.equal(2) |
55 | } | ||
56 | |||
57 | // When we'll prune HLS directories too | ||
58 | // const hlsRootCount = await countFiles(servers[1], 'streaming-playlists/hls/') | ||
59 | // expect(hlsRootCount).to.equal(2) | ||
60 | 55 | ||
61 | // const hlsCount = await countFiles(servers[1], 'streaming-playlists/hls/' + videoServer2UUID) | 56 | const hlsRootCount = await countFiles(server, 'streaming-playlists/hls') |
62 | // expect(hlsCount).to.equal(10) | 57 | expect(hlsRootCount).to.equal(2) |
58 | } | ||
63 | } | 59 | } |
64 | 60 | ||
65 | describe('Test prune storage scripts', function () { | 61 | describe('Test prune storage scripts', function () { |
66 | let servers: PeerTubeServer[] | 62 | let servers: PeerTubeServer[] |
67 | const badNames: { [directory: string]: string[] } = {} | 63 | const badNames: { [directory: string]: string[] } = {} |
68 | 64 | ||
69 | let videoServer2UUID: string | ||
70 | |||
71 | before(async function () { | 65 | before(async function () { |
72 | this.timeout(120000) | 66 | this.timeout(120000) |
73 | 67 | ||
@@ -77,9 +71,7 @@ describe('Test prune storage scripts', function () { | |||
77 | 71 | ||
78 | for (const server of servers) { | 72 | for (const server of servers) { |
79 | await server.videos.upload({ attributes: { name: 'video 1' } }) | 73 | await server.videos.upload({ attributes: { name: 'video 1' } }) |
80 | 74 | await server.videos.upload({ attributes: { name: 'video 2' } }) | |
81 | const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) | ||
82 | if (server.serverNumber === 2) videoServer2UUID = uuid | ||
83 | 75 | ||
84 | await server.users.updateMyAvatar({ fixture: 'avatar.png' }) | 76 | await server.users.updateMyAvatar({ fixture: 'avatar.png' }) |
85 | 77 | ||
@@ -123,7 +115,7 @@ describe('Test prune storage scripts', function () { | |||
123 | }) | 115 | }) |
124 | 116 | ||
125 | it('Should have the files on the disk', async function () { | 117 | it('Should have the files on the disk', async function () { |
126 | await assertCountAreOkay(servers, videoServer2UUID) | 118 | await assertCountAreOkay(servers) |
127 | }) | 119 | }) |
128 | 120 | ||
129 | it('Should create some dirty files', async function () { | 121 | it('Should create some dirty files', async function () { |
@@ -188,27 +180,14 @@ describe('Test prune storage scripts', function () { | |||
188 | badNames['avatars'] = [ n1, n2 ] | 180 | badNames['avatars'] = [ n1, n2 ] |
189 | } | 181 | } |
190 | 182 | ||
191 | // When we'll prune HLS directories too | 183 | { |
192 | // { | 184 | const directory = join('streaming-playlists', 'hls') |
193 | // const directory = join('streaming-playlists', 'hls') | 185 | const base = servers[0].servers.buildDirectory(directory) |
194 | // const base = servers[1].servers.buildDirectory(directory) | ||
195 | |||
196 | // const n1 = buildUUID() | ||
197 | // await createFile(join(base, n1)) | ||
198 | // badNames[directory] = [ n1 ] | ||
199 | // } | ||
200 | |||
201 | // { | ||
202 | // const directory = join('streaming-playlists', 'hls', videoServer2UUID) | ||
203 | // const base = servers[1].servers.buildDirectory(directory) | ||
204 | // const n1 = buildUUID() + '-240-fragmented-.mp4' | ||
205 | // const n2 = buildUUID() + '-master.m3u8' | ||
206 | |||
207 | // await createFile(join(base, n1)) | ||
208 | // await createFile(join(base, n2)) | ||
209 | 186 | ||
210 | // badNames[directory] = [ n1, n2 ] | 187 | const n1 = buildUUID() |
211 | // } | 188 | await createFile(join(base, n1)) |
189 | badNames[directory] = [ n1 ] | ||
190 | } | ||
212 | } | 191 | } |
213 | }) | 192 | }) |
214 | 193 | ||
@@ -220,7 +199,7 @@ describe('Test prune storage scripts', function () { | |||
220 | }) | 199 | }) |
221 | 200 | ||
222 | it('Should have removed files', async function () { | 201 | it('Should have removed files', async function () { |
223 | await assertCountAreOkay(servers, videoServer2UUID) | 202 | await assertCountAreOkay(servers) |
224 | 203 | ||
225 | for (const directory of Object.keys(badNames)) { | 204 | for (const directory of Object.keys(badNames)) { |
226 | for (const name of badNames[directory]) { | 205 | for (const name of badNames[directory]) { |