diff options
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 4 | ||||
-rw-r--r-- | server/tests/api/videos/resumable-upload.ts | 24 |
2 files changed, 17 insertions, 11 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 9034772c0..b829e4eb4 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -2,6 +2,7 @@ import express from 'express' | |||
2 | import { body, header, param, query, ValidationChain } from 'express-validator' | 2 | import { body, header, param, query, ValidationChain } from 'express-validator' |
3 | import { isTestInstance } from '@server/helpers/core-utils' | 3 | import { isTestInstance } from '@server/helpers/core-utils' |
4 | import { getResumableUploadPath } from '@server/helpers/upload' | 4 | import { getResumableUploadPath } from '@server/helpers/upload' |
5 | import { uploadx } from '@server/lib/uploadx' | ||
5 | import { Redis } from '@server/lib/redis' | 6 | import { Redis } from '@server/lib/redis' |
6 | import { getServerActor } from '@server/models/application/application' | 7 | import { getServerActor } from '@server/models/application/application' |
7 | import { ExpressPromiseHandler } from '@server/types/express-handler' | 8 | import { ExpressPromiseHandler } from '@server/types/express-handler' |
@@ -40,7 +41,6 @@ import { | |||
40 | } from '../../../helpers/custom-validators/videos' | 41 | } from '../../../helpers/custom-validators/videos' |
41 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 42 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
42 | import { logger } from '../../../helpers/logger' | 43 | import { logger } from '../../../helpers/logger' |
43 | import { deleteFileAndCatch } from '../../../helpers/utils' | ||
44 | import { getVideoWithAttributes } from '../../../helpers/video' | 44 | import { getVideoWithAttributes } from '../../../helpers/video' |
45 | import { CONFIG } from '../../../initializers/config' | 45 | import { CONFIG } from '../../../initializers/config' |
46 | import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' | 46 | import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' |
@@ -115,7 +115,7 @@ const videosAddResumableValidator = [ | |||
115 | const user = res.locals.oauth.token.User | 115 | const user = res.locals.oauth.token.User |
116 | const body: express.CustomUploadXFile<express.UploadXFileMetadata> = req.body | 116 | const body: express.CustomUploadXFile<express.UploadXFileMetadata> = req.body |
117 | const file = { ...body, duration: undefined, path: getResumableUploadPath(body.name), filename: body.metadata.filename } | 117 | const file = { ...body, duration: undefined, path: getResumableUploadPath(body.name), filename: body.metadata.filename } |
118 | const cleanup = () => deleteFileAndCatch(file.path) | 118 | const cleanup = () => uploadx.storage.delete(file).catch(err => logger.error('Cannot delete the file %s', file.name, { err })) |
119 | 119 | ||
120 | const uploadId = req.query.upload_id | 120 | const uploadId = req.query.upload_id |
121 | const sessionExists = await Redis.Instance.doesUploadSessionExist(uploadId) | 121 | const sessionExists = await Redis.Instance.doesUploadSessionExist(uploadId) |
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 9de622281..91eb61833 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts | |||
@@ -93,10 +93,10 @@ describe('Test resumable upload', function () { | |||
93 | expect((await stat(filePath)).size).to.equal(expectedSize) | 93 | expect((await stat(filePath)).size).to.equal(expectedSize) |
94 | } | 94 | } |
95 | 95 | ||
96 | async function countResumableUploads () { | 96 | async function countResumableUploads (wait?: number) { |
97 | const subPath = join('tmp', 'resumable-uploads') | 97 | const subPath = join('tmp', 'resumable-uploads') |
98 | const filePath = server.servers.buildDirectory(subPath) | 98 | const filePath = server.servers.buildDirectory(subPath) |
99 | 99 | await new Promise(resolve => setTimeout(resolve, wait)) | |
100 | const files = await readdir(filePath) | 100 | const files = await readdir(filePath) |
101 | return files.length | 101 | return files.length |
102 | } | 102 | } |
@@ -122,14 +122,20 @@ describe('Test resumable upload', function () { | |||
122 | 122 | ||
123 | describe('Directory cleaning', function () { | 123 | describe('Directory cleaning', function () { |
124 | 124 | ||
125 | // FIXME: https://github.com/kukhariev/node-uploadx/pull/524/files#r852989382 | 125 | it('Should correctly delete files after an upload', async function () { |
126 | // it('Should correctly delete files after an upload', async function () { | 126 | const uploadId = await prepareUpload() |
127 | // const uploadId = await prepareUpload() | 127 | await sendChunks({ pathUploadId: uploadId }) |
128 | // await sendChunks({ pathUploadId: uploadId }) | 128 | await server.videos.endResumableUpload({ pathUploadId: uploadId }) |
129 | // await server.videos.endResumableUpload({ pathUploadId: uploadId }) | 129 | |
130 | expect(await countResumableUploads()).to.equal(0) | ||
131 | }) | ||
130 | 132 | ||
131 | // expect(await countResumableUploads()).to.equal(0) | 133 | it('Should correctly delete corrupt files', async function () { |
132 | // }) | 134 | const uploadId = await prepareUpload({ size: 8 * 1024 }) |
135 | await sendChunks({ pathUploadId: uploadId, size: 8 * 1024, expectedStatus: HttpStatusCode.UNPROCESSABLE_ENTITY_422 }) | ||
136 | |||
137 | expect(await countResumableUploads(2000)).to.equal(0) | ||
138 | }) | ||
133 | 139 | ||
134 | it('Should not delete files after an unfinished upload', async function () { | 140 | it('Should not delete files after an unfinished upload', async function () { |
135 | await prepareUpload() | 141 | await prepareUpload() |