From 1fb7d094229acdc190c3f7551b43ac5445814dee Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 1 Jun 2023 10:43:36 +0200 Subject: [PATCH] Don't cache upload after video deletion --- server/middlewares/validators/videos/videos.ts | 12 ++++++++---- server/tests/api/videos/resumable-upload.ts | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 7f1f39b11..fc2f95aa5 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -132,11 +132,15 @@ const videosAddResumableValidator = [ }) } - if (isTestInstance()) { - res.setHeader('x-resumable-upload-cached', 'true') - } + const videoStillExists = await VideoModel.load(sessionResponse.video.id) - return res.json(sessionResponse) + if (videoStillExists) { + if (isTestInstance()) { + res.setHeader('x-resumable-upload-cached', 'true') + } + + return res.json(sessionResponse) + } } await Redis.Instance.setUploadSession(uploadId) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 2fbefb392..9de622281 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -254,6 +254,24 @@ describe('Test resumable upload', function () { expect(result2.headers['x-resumable-upload-cached']).to.not.exist }) + it('Should not cache after video deletion', async function () { + const originalName = 'toto.mp4' + const lastModified = new Date().getTime() + + const uploadId1 = await prepareUpload({ originalName, lastModified }) + const result1 = await sendChunks({ pathUploadId: uploadId1 }) + await server.videos.remove({ id: result1.body.video.uuid }) + + const uploadId2 = await prepareUpload({ originalName, lastModified }) + const result2 = await sendChunks({ pathUploadId: uploadId2 }) + expect(result1.body.video.uuid).to.not.equal(result2.body.video.uuid) + + expect(result2.headers['x-resumable-upload-cached']).to.not.exist + + await checkFileSize(uploadId1, null) + await checkFileSize(uploadId2, null) + }) + it('Should refuse an invalid digest', async function () { const uploadId = await prepareUpload({ token: server.accessToken })