ActivityPub-federated video streaming platform using P2P directly in your web browser
Add hls to prune storage script
Chocobozzz90701ec1d8d2
diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.tsindex 9df80d5035..12d78fdc6d 100755--- a/scripts/prune-storage.ts+++ b/scripts/prune-storage.ts@@ -15,7 +15,8 @@ import { ActorImageModel } from '../server/models/actor/actor-image'import { uniq, values } from 'lodash'import { ThumbnailType } from '@shared/models'import { VideoFileModel } from '@server/models/video/video-file'-import { HLS_REDUNDANCY_DIRECTORY } from '@server/initializers/constants'+import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'+import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'run().then(() => process.exit(0))@@ -40,6 +41,9 @@ async function run () {toDelete = toDelete.concat(await pruneDirectory(CONFIG.STORAGE.VIDEOS_DIR, doesWebTorrentFileExist()),++ await pruneDirectory(HLS_STREAMING_PLAYLIST_DIRECTORY, doesHLSPlaylistExist()),+await pruneDirectory(CONFIG.STORAGE.TORRENTS_DIR, doesTorrentFileExist()),await pruneDirectory(CONFIG.STORAGE.REDUNDANCY_DIR, doesRedundancyExist),@@ -94,6 +98,10 @@ function doesWebTorrentFileExist () {return (filePath: string) => VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath))}+function doesHLSPlaylistExist () {+ return (hlsPath: string) => VideoStreamingPlaylistModel.doesOwnedHLSPlaylistExist(basename(hlsPath))+}+function doesTorrentFileExist () {return (filePath: string) => VideoFileModel.doesOwnedTorrentFileExist(basename(filePath))}diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.tsindex 4643c54526..e36852cad6 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<Vireturn Object.assign(playlist, { videoId: video.id, Video: video })}+ static doesOwnedHLSPlaylistExist (videoUUID: string) {+ const query = `SELECT 1 FROM "videoStreamingPlaylist" ` ++ `INNER JOIN "video" ON "video"."id" = "videoStreamingPlaylist"."videoId" ` ++ `AND "video"."remote" IS FALSE AND "video"."uuid" = $videoUUID ` ++ `AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1`++ return doesExist(query, { videoUUID })+ }+assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) {const masterPlaylistUrl = this.getMasterPlaylistUrl(video)diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.tsindex 2d4c02da74..1c0282da99 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}}-async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) {+async function assertCountAreOkay (servers: PeerTubeServer[]) {for (const server of servers) {const videosCount = await countFiles(server, 'videos')expect(videosCount).to.equal(8)@@ -52,22 +52,16 @@ async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID:const avatarsCount = await countFiles(server, 'avatars')expect(avatarsCount).to.equal(2)- }-- // When we'll prune HLS directories too- // const hlsRootCount = await countFiles(servers[1], 'streaming-playlists/hls/')- // expect(hlsRootCount).to.equal(2)- // const hlsCount = await countFiles(servers[1], 'streaming-playlists/hls/' + videoServer2UUID)- // expect(hlsCount).to.equal(10)+ const hlsRootCount = await countFiles(server, 'streaming-playlists/hls')+ expect(hlsRootCount).to.equal(2)+ }}describe('Test prune storage scripts', function () {let servers: PeerTubeServer[]const badNames: { [directory: string]: string[] } = {}- let videoServer2UUID: string-before(async function () {this.timeout(120000)@@ -77,9 +71,7 @@ describe('Test prune storage scripts', function () {for (const server of servers) {await server.videos.upload({ attributes: { name: 'video 1' } })-- const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } })- if (server.serverNumber === 2) videoServer2UUID = uuid+ await server.videos.upload({ attributes: { name: 'video 2' } })await server.users.updateMyAvatar({ fixture: 'avatar.png' })@@ -123,7 +115,7 @@ describe('Test prune storage scripts', function () {})it('Should have the files on the disk', async function () {- await assertCountAreOkay(servers, videoServer2UUID)+ await assertCountAreOkay(servers)})it('Should create some dirty files', async function () {@@ -188,27 +180,14 @@ describe('Test prune storage scripts', function () {badNames['avatars'] = [ n1, n2 ]}- // When we'll prune HLS directories too- // {- // const directory = join('streaming-playlists', 'hls')- // const base = servers[1].servers.buildDirectory(directory)-- // const n1 = buildUUID()- // await createFile(join(base, n1))- // badNames[directory] = [ n1 ]- // }-- // {- // const directory = join('streaming-playlists', 'hls', videoServer2UUID)- // const base = servers[1].servers.buildDirectory(directory)- // const n1 = buildUUID() + '-240-fragmented-.mp4'- // const n2 = buildUUID() + '-master.m3u8'-- // await createFile(join(base, n1))- // await createFile(join(base, n2))+ {+ const directory = join('streaming-playlists', 'hls')+ const base = servers[0].servers.buildDirectory(directory)- // badNames[directory] = [ n1, n2 ]- // }+ const n1 = buildUUID()+ await createFile(join(base, n1))+ badNames[directory] = [ n1 ]+ }}})@@ -220,7 +199,7 @@ describe('Test prune storage scripts', function () {})it('Should have removed files', async function () {- await assertCountAreOkay(servers, videoServer2UUID)+ await assertCountAreOkay(servers)for (const directory of Object.keys(badNames)) {for (const name of badNames[directory]) {