aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-10 10:28:46 +0100
committerChocobozzz <me@florianbigard.com>2021-12-10 10:28:46 +0100
commit90701ec1d8d27d0072d6b0d2b19362d471484f9a (patch)
treea03dedc7b6119d9f6d2ea35cae9b2dde20275519
parent0fbc0dec59684527fad8772080a8e1f928c07ea1 (diff)
downloadPeerTube-90701ec1d8d27d0072d6b0d2b19362d471484f9a.tar.gz
PeerTube-90701ec1d8d27d0072d6b0d2b19362d471484f9a.tar.zst
PeerTube-90701ec1d8d27d0072d6b0d2b19362d471484f9a.zip
Add hls to prune storage script
-rwxr-xr-xscripts/prune-storage.ts10
-rw-r--r--server/models/video/video-streaming-playlist.ts9
-rw-r--r--server/tests/cli/prune-storage.ts49
3 files changed, 32 insertions, 36 deletions
diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts
index 9df80d503..12d78fdc6 100755
--- a/scripts/prune-storage.ts
+++ b/scripts/prune-storage.ts
@@ -15,7 +15,8 @@ import { ActorImageModel } from '../server/models/actor/actor-image'
15import { uniq, values } from 'lodash' 15import { uniq, values } from 'lodash'
16import { ThumbnailType } from '@shared/models' 16import { ThumbnailType } from '@shared/models'
17import { VideoFileModel } from '@server/models/video/video-file' 17import { VideoFileModel } from '@server/models/video/video-file'
18import { HLS_REDUNDANCY_DIRECTORY } from '@server/initializers/constants' 18import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
19import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
19 20
20run() 21run()
21 .then(() => process.exit(0)) 22 .then(() => process.exit(0))
@@ -40,6 +41,9 @@ async function run () {
40 41
41 toDelete = toDelete.concat( 42 toDelete = toDelete.concat(
42 await pruneDirectory(CONFIG.STORAGE.VIDEOS_DIR, doesWebTorrentFileExist()), 43 await pruneDirectory(CONFIG.STORAGE.VIDEOS_DIR, doesWebTorrentFileExist()),
44
45 await pruneDirectory(HLS_STREAMING_PLAYLIST_DIRECTORY, doesHLSPlaylistExist()),
46
43 await pruneDirectory(CONFIG.STORAGE.TORRENTS_DIR, doesTorrentFileExist()), 47 await pruneDirectory(CONFIG.STORAGE.TORRENTS_DIR, doesTorrentFileExist()),
44 48
45 await pruneDirectory(CONFIG.STORAGE.REDUNDANCY_DIR, doesRedundancyExist), 49 await pruneDirectory(CONFIG.STORAGE.REDUNDANCY_DIR, doesRedundancyExist),
@@ -94,6 +98,10 @@ function doesWebTorrentFileExist () {
94 return (filePath: string) => VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath)) 98 return (filePath: string) => VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath))
95} 99}
96 100
101function doesHLSPlaylistExist () {
102 return (hlsPath: string) => VideoStreamingPlaylistModel.doesOwnedHLSPlaylistExist(basename(hlsPath))
103}
104
97function doesTorrentFileExist () { 105function doesTorrentFileExist () {
98 return (filePath: string) => VideoFileModel.doesOwnedTorrentFileExist(basename(filePath)) 106 return (filePath: string) => VideoFileModel.doesOwnedTorrentFileExist(basename(filePath))
99} 107}
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
39async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) { 39async 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
65describe('Test prune storage scripts', function () { 61describe('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]) {