From 303b196bae9450c5328d68f6b0a378f91f0d605e Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 7 Jul 2024 12:57:13 +0900 Subject: [PATCH] =?UTF-8?q?multipart/form-data=E3=81=A7=E3=81=AFnull?= =?UTF-8?q?=E3=81=AE=E3=83=97=E3=83=AD=E3=83=91=E3=83=86=E3=82=A3=E3=82=92?= =?UTF-8?q?=E5=BC=BE=E3=81=8F=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/misskey-js/src/api.ts | 5 ++++- packages/misskey-js/test/api.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index 74e84560b859..76d055cbe4ed 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -79,11 +79,14 @@ export class APIClient { if (this.assertIsRecord(params)) { for (const key in params) { const value = params[key]; + + if (value == null) continue; + if (value instanceof File || value instanceof Blob) { payload.append(key, value); } else if (typeof value === 'object') { payload.append(key, JSON.stringify(value)); - } else if (value != null) { + } else { payload.append(key, value); } } diff --git a/packages/misskey-js/test/api.ts b/packages/misskey-js/test/api.ts index f9572c179a5f..95f1946fa27b 100644 --- a/packages/misskey-js/test/api.ts +++ b/packages/misskey-js/test/api.ts @@ -111,7 +111,10 @@ describe('API', () => { const testFile = new File([], 'foo.txt'); - const res = await cli.request('drive/files/create', { file: testFile }); + const res = await cli.request('drive/files/create', { + file: testFile, + name: null, // nullのパラメータは消える + }); expect(res).toEqual({ id: 'foo' @@ -121,7 +124,10 @@ describe('API', () => { url: 'https://misskey.test/api/drive/files/create', method: 'POST', contentType: 'multipart/form-data', - body: { i: 'TOKEN', file: testFile } + body: { + i: 'TOKEN', + file: testFile, + } }); });