Delete correctly redundancy files
This commit is contained in:
parent
be691a57c5
commit
25378bc866
6 changed files with 48 additions and 12 deletions
|
@ -4,8 +4,8 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"licence": "GPLv3",
|
"licence": "GPLv3",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Florian Bigard",
|
"name": "Chocobozzz",
|
||||||
"email": "me@florianbigard.com",
|
"email": "chocobozzz@cpy.re",
|
||||||
"url": "http://github.com/Chocobozzz"
|
"url": "http://github.com/Chocobozzz"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
"peertube": "dist/server/tools/peertube.js"
|
"peertube": "dist/server/tools/peertube.js"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Florian Bigard",
|
"name": "Chocobozzz",
|
||||||
"email": "florian.bigard@gmail.com",
|
"email": "chocobozzz@cpy.re",
|
||||||
"url": "http://github.com/Chocobozzz"
|
"url": "http://github.com/Chocobozzz"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {
|
import {
|
||||||
AfterDestroy,
|
|
||||||
AllowNull,
|
AllowNull,
|
||||||
|
BeforeDestroy,
|
||||||
BelongsTo,
|
BelongsTo,
|
||||||
Column,
|
Column,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
|
@ -115,14 +115,16 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
|
||||||
})
|
})
|
||||||
Actor: ActorModel
|
Actor: ActorModel
|
||||||
|
|
||||||
@AfterDestroy
|
@BeforeDestroy
|
||||||
static removeFile (instance: VideoRedundancyModel) {
|
static async removeFile (instance: VideoRedundancyModel) {
|
||||||
// Not us
|
// Not us
|
||||||
if (!instance.strategy) return
|
if (!instance.strategy) return
|
||||||
|
|
||||||
logger.info('Removing duplicated video file %s-%s.', instance.VideoFile.Video.uuid, instance.VideoFile.resolution)
|
const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId)
|
||||||
|
|
||||||
return instance.VideoFile.Video.removeFile(instance.VideoFile)
|
logger.info('Removing duplicated video file %s-%s.', videoFile.Video.uuid, videoFile.resolution)
|
||||||
|
|
||||||
|
return videoFile.Video.removeFile(videoFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
static async loadLocalByFileId (videoFileId: number) {
|
static async loadLocalByFileId (videoFileId: number) {
|
||||||
|
|
|
@ -107,6 +107,19 @@ export class VideoFileModel extends Model<VideoFileModel> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static loadWithVideo (id: number) {
|
||||||
|
const options = {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: VideoModel.unscoped(),
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return VideoFileModel.findById(id, options)
|
||||||
|
}
|
||||||
|
|
||||||
hasSameUniqueKeysThan (other: VideoFileModel) {
|
hasSameUniqueKeysThan (other: VideoFileModel) {
|
||||||
return this.fps === other.fps &&
|
return this.fps === other.fps &&
|
||||||
this.resolution === other.resolution &&
|
this.resolution === other.resolution &&
|
||||||
|
|
|
@ -16,7 +16,8 @@ import {
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
viewVideo,
|
viewVideo,
|
||||||
wait,
|
wait,
|
||||||
waitUntilLog
|
waitUntilLog,
|
||||||
|
checkVideoFilesWereRemoved, removeVideo
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { waitJobs } from '../../utils/server/jobs'
|
import { waitJobs } from '../../utils/server/jobs'
|
||||||
import * as magnetUtil from 'magnet-uri'
|
import * as magnetUtil from 'magnet-uri'
|
||||||
|
@ -242,6 +243,8 @@ describe('Test videos redundancy', function () {
|
||||||
await wait(5000)
|
await wait(5000)
|
||||||
|
|
||||||
await check1WebSeed(strategy)
|
await check1WebSeed(strategy)
|
||||||
|
|
||||||
|
await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
|
@ -287,6 +290,8 @@ describe('Test videos redundancy', function () {
|
||||||
await wait(5000)
|
await wait(5000)
|
||||||
|
|
||||||
await check1WebSeed(strategy)
|
await check1WebSeed(strategy)
|
||||||
|
|
||||||
|
await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
|
@ -344,6 +349,18 @@ describe('Test videos redundancy', function () {
|
||||||
await checkStatsWith2Webseed(strategy)
|
await checkStatsWith2Webseed(strategy)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should remove the video and the redundancy files', async function () {
|
||||||
|
this.timeout(20000)
|
||||||
|
|
||||||
|
await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID)
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
await checkVideoFilesWereRemoved(video1Server2UUID, server.serverNumber)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
return cleanServers()
|
return cleanServers()
|
||||||
})
|
})
|
||||||
|
|
|
@ -267,10 +267,14 @@ function removeVideo (url: string, token: string, id: number | string, expectedS
|
||||||
.expect(expectedStatus)
|
.expect(expectedStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
|
async function checkVideoFilesWereRemoved (
|
||||||
|
videoUUID: string,
|
||||||
|
serverNumber: number,
|
||||||
|
directories = [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]
|
||||||
|
) {
|
||||||
const testDirectory = 'test' + serverNumber
|
const testDirectory = 'test' + serverNumber
|
||||||
|
|
||||||
for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]) {
|
for (const directory of directories) {
|
||||||
const directoryPath = join(root(), testDirectory, directory)
|
const directoryPath = join(root(), testDirectory, directory)
|
||||||
|
|
||||||
const directoryExists = existsSync(directoryPath)
|
const directoryExists = existsSync(directoryPath)
|
||||||
|
|
Loading…
Reference in a new issue