From 790c2837ddcb443c0f1ea6adcdcb101dfe159d01 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 9 Sep 2021 09:31:50 +0200 Subject: Fix silent 500 after resumable upload --- shared/extra-utils/requests/requests.ts | 8 +++++++- shared/extra-utils/shared/abstract-command.ts | 16 ++++++++++++++-- shared/extra-utils/videos/videos-command.ts | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) (limited to 'shared') diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts index 5bbf7f3bf..501e0b374 100644 --- a/shared/extra-utils/requests/requests.ts +++ b/shared/extra-utils/requests/requests.ts @@ -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 }) } diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index 021045e49..a57c857fc 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts @@ -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 & { diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts index d35339c8d..63980c147 100644 --- a/shared/extra-utils/videos/videos-command.ts +++ b/shared/extra-utils/videos/videos-command.ts @@ -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 -- cgit v1.2.3