Verified Commit 790c2837 authored by Chocobozzz's avatar Chocobozzz
Browse files

Fix silent 500 after resumable upload

parent b4c945f3
......@@ -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 })
}
......
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
}
......@@ -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)
})
......
......@@ -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 })
}
......
......@@ -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 & {
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment