fix(misskey-js): content-typeはapplication/jsonでないもののみを記録するように (#14508)

This commit is contained in:
かっこかり
2024-09-06 17:22:45 +09:00
committed by GitHub
parent cdb0566c5b
commit 8d19bdbb65
3 changed files with 22 additions and 393 deletions

View File

@@ -56,6 +56,10 @@ export class APIClient {
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
}
private assertSpecialEpReqType(ep: keyof Endpoints): ep is keyof typeof endpointReqTypes {
return ep in endpointReqTypes;
}
public request<E extends keyof Endpoints, P extends Endpoints[E]['req']>(
endpoint: E,
params: P = {} as P,
@@ -63,9 +67,10 @@ export class APIClient {
): Promise<SwitchCaseResponseType<E, P>> {
return new Promise((resolve, reject) => {
let mediaType = 'application/json';
if (endpoint in endpointReqTypes) {
if (this.assertSpecialEpReqType(endpoint) && endpointReqTypes[endpoint] != null) {
mediaType = endpointReqTypes[endpoint];
}
let payload: FormData | string = '{}';
if (mediaType === 'application/json') {
@@ -100,7 +105,7 @@ export class APIClient {
method: 'POST',
body: payload,
headers: {
'Content-Type': endpointReqTypes[endpoint],
'Content-Type': mediaType,
},
credentials: 'omit',
cache: 'no-cache',