Skip to content

Commit

Permalink
multipart/form-dataではnullのプロパティを弾くように
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Jul 7, 2024
1 parent 137b3c6 commit 303b196
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/misskey-js/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
10 changes: 8 additions & 2 deletions packages/misskey-js/test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
}
});
});

Expand Down

0 comments on commit 303b196

Please sign in to comment.