1
0
Fork 0

Add hls to prune storage script

This commit is contained in:
Chocobozzz 2021-12-10 10:28:46 +01:00
parent 0fbc0dec59
commit 90701ec1d8
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 32 additions and 36 deletions

View file

@ -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))
}

View file

@ -198,6 +198,15 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
return 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)

View file

@ -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)
const hlsRootCount = await countFiles(server, 'streaming-playlists/hls')
expect(hlsRootCount).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)
}
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 directory = join('streaming-playlists', 'hls')
const base = servers[0].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))
// 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]) {