Fix silent 500 after resumable upload

pull/4429/head
Chocobozzz 2021-09-09 09:31:50 +02:00
parent b4c945f3c7
commit 790c2837dd
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 39 additions and 15 deletions

View File

@ -2,7 +2,7 @@ import express from 'express'
import { move } from 'fs-extra'
import { basename } from 'path'
import { getLowercaseExtension } from '@server/helpers/core-utils'
import { deleteResumableUploadMetaFile, getResumableUploadPath } from '@server/helpers/upload'
import { getResumableUploadPath } from '@server/helpers/upload'
import { uuidToShort } from '@server/helpers/uuid'
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
@ -130,9 +130,6 @@ export async function addVideoResumable (_req: express.Request, res: express.Res
const videoInfo = videoPhysicalFile.metadata
const files = { previewfile: videoInfo.previewfile }
// Don't need the meta file anymore
await deleteResumableUploadMetaFile(videoPhysicalFile.path)
return addVideo({ res, videoPhysicalFile, videoInfo, files })
}

View File

@ -1,5 +1,3 @@
import { METAFILE_EXTNAME } from '@uploadx/core'
import { remove } from 'fs-extra'
import { join } from 'path'
import { RESUMABLE_UPLOAD_DIRECTORY } from '../initializers/constants'
@ -9,13 +7,8 @@ function getResumableUploadPath (filename?: string) {
return RESUMABLE_UPLOAD_DIRECTORY
}
function deleteResumableUploadMetaFile (filepath: string) {
return remove(filepath + METAFILE_EXTNAME)
}
// ---------------------------------------------------------------------------
export {
getResumableUploadPath,
deleteResumableUploadMetaFile
getResumableUploadPath
}

View File

@ -113,6 +113,7 @@ describe('Test resumable upload', function () {
it('Should correctly delete files after an upload', async function () {
const uploadId = await prepareUpload()
await sendChunks({ pathUploadId: uploadId })
await server.videos.endResumableUpload({ pathUploadId: uploadId })
expect(await countResumableUploads()).to.equal(0)
})

View File

@ -57,9 +57,15 @@ function makeActivityPubGetRequest (url: string, path: string, expectedStatus =
})
}
function makeDeleteRequest (options: CommonRequestParams) {
function makeDeleteRequest (options: CommonRequestParams & {
query?: any
rawQuery?: string
}) {
const req = request(options.url).delete(options.path)
if (options.query) req.query(options.query)
if (options.rawQuery) req.query(options.rawQuery)
return buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
}

View File

@ -40,6 +40,11 @@ interface InternalGetCommandOptions extends InternalCommonCommandOptions {
query?: { [ id: string ]: any }
}
interface InternalDeleteCommandOptions extends InternalCommonCommandOptions {
query?: { [ id: string ]: any }
rawQuery?: string
}
abstract class AbstractCommand {
constructor (
@ -82,8 +87,15 @@ abstract class AbstractCommand {
})
}
protected deleteRequest (options: InternalCommonCommandOptions) {
return makeDeleteRequest(this.buildCommonRequestOptions(options))
protected deleteRequest (options: InternalDeleteCommandOptions) {
const { query, rawQuery } = options
return makeDeleteRequest({
...this.buildCommonRequestOptions(options),
query,
rawQuery
})
}
protected putBodyRequest (options: InternalCommonCommandOptions & {

View File

@ -449,6 +449,8 @@ export class VideosCommand extends AbstractCommand {
const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size })
await this.endResumableUpload({ ...options, pathUploadId })
return result.body?.video || result.body as any
}
@ -542,6 +544,19 @@ export class VideosCommand extends AbstractCommand {
})
}
endResumableUpload (options: OverrideCommandOptions & {
pathUploadId: string
}) {
return this.deleteRequest({
...options,
path: '/api/v1/videos/upload-resumable',
rawQuery: options.pathUploadId,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
quickUpload (options: OverrideCommandOptions & {
name: string
nsfw?: boolean