fix(misskey-js): content-typeはapplication/jsonでないもののみを記録するように (#14508)
This commit is contained in:
@@ -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',
|
||||
|
Reference in New Issue
Block a user