diff --git a/packages/tests/src/api/server/index.ts b/packages/tests/src/api/server/index.ts index b7d654500..37e6283ec 100644 --- a/packages/tests/src/api/server/index.ts +++ b/packages/tests/src/api/server/index.ts @@ -10,6 +10,7 @@ import './follows-moderation.js' import './homepage.js' import './handle-down.js' import './jobs.js' +import './lazy-static.js' import './logs.js' import './reverse-proxy.js' import './services.js' diff --git a/packages/tests/src/api/server/lazy-static.ts b/packages/tests/src/api/server/lazy-static.ts new file mode 100644 index 000000000..7a926b4d1 --- /dev/null +++ b/packages/tests/src/api/server/lazy-static.ts @@ -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) + }) +}) diff --git a/server/core/lib/thumbnail.ts b/server/core/lib/thumbnail.ts index 99ac80232..2a26c1629 100644 --- a/server/core/lib/thumbnail.ts +++ b/server/core/lib/thumbnail.ts @@ -211,6 +211,7 @@ export function updateRemoteVideoThumbnail (options: { // Do not change the thumbnail filename if the file did not change if (hasThumbnailUrlChanged(existingThumbnail, fileUrl, video)) { + thumbnail.previousThumbnailFilename = thumbnail.filename thumbnail.filename = generatedFilename }