1
0
Fork 0

Fix silent 500 after resumable upload

This commit is contained in:
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 { move } from 'fs-extra'
import { basename } from 'path' import { basename } from 'path'
import { getLowercaseExtension } from '@server/helpers/core-utils' 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 { uuidToShort } from '@server/helpers/uuid'
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' 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 videoInfo = videoPhysicalFile.metadata
const files = { previewfile: videoInfo.previewfile } const files = { previewfile: videoInfo.previewfile }
// Don't need the meta file anymore
await deleteResumableUploadMetaFile(videoPhysicalFile.path)
return addVideo({ res, videoPhysicalFile, videoInfo, files }) 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 { join } from 'path'
import { RESUMABLE_UPLOAD_DIRECTORY } from '../initializers/constants' import { RESUMABLE_UPLOAD_DIRECTORY } from '../initializers/constants'
@ -9,13 +7,8 @@ function getResumableUploadPath (filename?: string) {
return RESUMABLE_UPLOAD_DIRECTORY return RESUMABLE_UPLOAD_DIRECTORY
} }
function deleteResumableUploadMetaFile (filepath: string) {
return remove(filepath + METAFILE_EXTNAME)
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
getResumableUploadPath, getResumableUploadPath
deleteResumableUploadMetaFile
} }

View file

@ -113,6 +113,7 @@ describe('Test resumable upload', function () {
it('Should correctly delete files after an upload', async function () { it('Should correctly delete files after an upload', async function () {
const uploadId = await prepareUpload() const uploadId = await prepareUpload()
await sendChunks({ pathUploadId: uploadId }) await sendChunks({ pathUploadId: uploadId })
await server.videos.endResumableUpload({ pathUploadId: uploadId })
expect(await countResumableUploads()).to.equal(0) 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) 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 }) 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 } query?: { [ id: string ]: any }
} }
interface InternalDeleteCommandOptions extends InternalCommonCommandOptions {
query?: { [ id: string ]: any }
rawQuery?: string
}
abstract class AbstractCommand { abstract class AbstractCommand {
constructor ( constructor (
@ -82,8 +87,15 @@ abstract class AbstractCommand {
}) })
} }
protected deleteRequest (options: InternalCommonCommandOptions) { protected deleteRequest (options: InternalDeleteCommandOptions) {
return makeDeleteRequest(this.buildCommonRequestOptions(options)) const { query, rawQuery } = options
return makeDeleteRequest({
...this.buildCommonRequestOptions(options),
query,
rawQuery
})
} }
protected putBodyRequest (options: InternalCommonCommandOptions & { protected putBodyRequest (options: InternalCommonCommandOptions & {

View file

@ -449,6 +449,8 @@ export class VideosCommand extends AbstractCommand {
const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size }) const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size })
await this.endResumableUpload({ ...options, pathUploadId })
return result.body?.video || result.body as any 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 & { quickUpload (options: OverrideCommandOptions & {
name: string name: string
nsfw?: boolean nsfw?: boolean