Add hls to prune storage script
This commit is contained in:
parent
0fbc0dec59
commit
90701ec1d8
3 changed files with 32 additions and 36 deletions
|
@ -15,7 +15,8 @@ import { ActorImageModel } from '../server/models/actor/actor-image'
|
||||||
import { uniq, values } from 'lodash'
|
import { uniq, values } from 'lodash'
|
||||||
import { ThumbnailType } from '@shared/models'
|
import { ThumbnailType } from '@shared/models'
|
||||||
import { VideoFileModel } from '@server/models/video/video-file'
|
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()
|
run()
|
||||||
.then(() => process.exit(0))
|
.then(() => process.exit(0))
|
||||||
|
@ -40,6 +41,9 @@ async function run () {
|
||||||
|
|
||||||
toDelete = toDelete.concat(
|
toDelete = toDelete.concat(
|
||||||
await pruneDirectory(CONFIG.STORAGE.VIDEOS_DIR, doesWebTorrentFileExist()),
|
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.TORRENTS_DIR, doesTorrentFileExist()),
|
||||||
|
|
||||||
await pruneDirectory(CONFIG.STORAGE.REDUNDANCY_DIR, doesRedundancyExist),
|
await pruneDirectory(CONFIG.STORAGE.REDUNDANCY_DIR, doesRedundancyExist),
|
||||||
|
@ -94,6 +98,10 @@ function doesWebTorrentFileExist () {
|
||||||
return (filePath: string) => VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath))
|
return (filePath: string) => VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doesHLSPlaylistExist () {
|
||||||
|
return (hlsPath: string) => VideoStreamingPlaylistModel.doesOwnedHLSPlaylistExist(basename(hlsPath))
|
||||||
|
}
|
||||||
|
|
||||||
function doesTorrentFileExist () {
|
function doesTorrentFileExist () {
|
||||||
return (filePath: string) => VideoFileModel.doesOwnedTorrentFileExist(basename(filePath))
|
return (filePath: string) => VideoFileModel.doesOwnedTorrentFileExist(basename(filePath))
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,15 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
|
||||||
return Object.assign(playlist, { videoId: video.id, Video: video })
|
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[]) {
|
assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) {
|
||||||
const masterPlaylistUrl = this.getMasterPlaylistUrl(video)
|
const masterPlaylistUrl = this.getMasterPlaylistUrl(video)
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
for (const server of servers) {
|
||||||
const videosCount = await countFiles(server, 'videos')
|
const videosCount = await countFiles(server, 'videos')
|
||||||
expect(videosCount).to.equal(8)
|
expect(videosCount).to.equal(8)
|
||||||
|
@ -52,22 +52,16 @@ async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID:
|
||||||
|
|
||||||
const avatarsCount = await countFiles(server, 'avatars')
|
const avatarsCount = await countFiles(server, 'avatars')
|
||||||
expect(avatarsCount).to.equal(2)
|
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 () {
|
describe('Test prune storage scripts', function () {
|
||||||
let servers: PeerTubeServer[]
|
let servers: PeerTubeServer[]
|
||||||
const badNames: { [directory: string]: string[] } = {}
|
const badNames: { [directory: string]: string[] } = {}
|
||||||
|
|
||||||
let videoServer2UUID: string
|
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(120000)
|
this.timeout(120000)
|
||||||
|
|
||||||
|
@ -77,9 +71,7 @@ describe('Test prune storage scripts', function () {
|
||||||
|
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
await server.videos.upload({ attributes: { name: 'video 1' } })
|
await server.videos.upload({ attributes: { name: 'video 1' } })
|
||||||
|
await server.videos.upload({ attributes: { name: 'video 2' } })
|
||||||
const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } })
|
|
||||||
if (server.serverNumber === 2) videoServer2UUID = uuid
|
|
||||||
|
|
||||||
await server.users.updateMyAvatar({ fixture: 'avatar.png' })
|
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 () {
|
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 () {
|
it('Should create some dirty files', async function () {
|
||||||
|
@ -188,27 +180,14 @@ describe('Test prune storage scripts', function () {
|
||||||
badNames['avatars'] = [ n1, n2 ]
|
badNames['avatars'] = [ n1, n2 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we'll prune HLS directories too
|
{
|
||||||
// {
|
const directory = join('streaming-playlists', 'hls')
|
||||||
// const directory = join('streaming-playlists', 'hls')
|
const base = servers[0].servers.buildDirectory(directory)
|
||||||
// const base = servers[1].servers.buildDirectory(directory)
|
|
||||||
|
|
||||||
// const n1 = buildUUID()
|
const n1 = buildUUID()
|
||||||
// await createFile(join(base, n1))
|
await createFile(join(base, n1))
|
||||||
// badNames[directory] = [ 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 ]
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -220,7 +199,7 @@ describe('Test prune storage scripts', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have removed files', async function () {
|
it('Should have removed files', async function () {
|
||||||
await assertCountAreOkay(servers, videoServer2UUID)
|
await assertCountAreOkay(servers)
|
||||||
|
|
||||||
for (const directory of Object.keys(badNames)) {
|
for (const directory of Object.keys(badNames)) {
|
||||||
for (const name of badNames[directory]) {
|
for (const name of badNames[directory]) {
|
||||||
|
|
Loading…
Reference in a new issue