1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Delete remote thumbnails/preview on update

This commit is contained in:
Chocobozzz 2025-01-28 14:11:43 +01:00
parent 372e15eb49
commit 9f64909fc7
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 67 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import './follows-moderation.js'
import './homepage.js' import './homepage.js'
import './handle-down.js' import './handle-down.js'
import './jobs.js' import './jobs.js'
import './lazy-static.js'
import './logs.js' import './logs.js'
import './reverse-proxy.js' import './reverse-proxy.js'
import './services.js' import './services.js'

View file

@ -0,0 +1,65 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */
import {
cleanupTests,
createMultipleServers,
doubleFollow,
makeGetRequest,
makeRawRequest,
PeerTubeServer,
setAccessTokensToServers,
waitJobs
} from '@peertube/peertube-server-commands'
import { checkDirectoryIsEmpty } from '@tests/shared/directories.js'
import { HttpStatusCode } from '../../../../models/src/http/http-status-codes.js'
describe('Test lazy static endpoinds', function () {
let servers: PeerTubeServer[]
let videoId: string
before(async function () {
this.timeout(240000)
servers = await createMultipleServers(2)
await setAccessTokensToServers(servers)
await doubleFollow(servers[0], servers[1])
const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
videoId = uuid
await waitJobs(servers)
})
it('Should remove previous thumbnails/previews after an update', async function () {
this.timeout(60000)
const fetchRemoteImages = async () => {
const video = await servers[1].videos.get({ id: videoId })
await makeGetRequest({ url: servers[1].url, path: video.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 })
await makeGetRequest({ url: servers[1].url, path: video.previewPath, expectedStatus: HttpStatusCode.OK_200 })
}
await fetchRemoteImages()
// Update video
await servers[0].videos.update({
id: videoId,
attributes: { thumbnailfile: 'custom-thumbnail.jpg', previewfile: 'custom-preview.jpg' }
})
await waitJobs(servers)
await fetchRemoteImages()
// Remove video
await servers[0].videos.remove({ id: videoId })
await waitJobs(servers)
await checkDirectoryIsEmpty(servers[1], 'thumbnails')
await checkDirectoryIsEmpty(servers[1], 'previews')
})
after(async function () {
await cleanupTests(servers)
})
})

View file

@ -211,6 +211,7 @@ export function updateRemoteVideoThumbnail (options: {
// Do not change the thumbnail filename if the file did not change // Do not change the thumbnail filename if the file did not change
if (hasThumbnailUrlChanged(existingThumbnail, fileUrl, video)) { if (hasThumbnailUrlChanged(existingThumbnail, fileUrl, video)) {
thumbnail.previousThumbnailFilename = thumbnail.filename
thumbnail.filename = generatedFilename thumbnail.filename = generatedFilename
} }