summaryrefslogtreecommitdiff
path: root/packages/megalodon/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-06 22:53:43 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-05-08 11:23:20 -0400
commit5815d2f537139b6748c8dbd5e003a360de66ca7c (patch)
tree13e7e019cac4486b44d2a3e93d813a970cf3f54c /packages/megalodon/src
parentfix media upload error caused by extraneous array brackets (diff)
downloadsharkey-5815d2f537139b6748c8dbd5e003a360de66ca7c.tar.gz
sharkey-5815d2f537139b6748c8dbd5e003a360de66ca7c.tar.bz2
sharkey-5815d2f537139b6748c8dbd5e003a360de66ca7c.zip
fix user-agent / authorization passing in megalodon
Diffstat (limited to 'packages/megalodon/src')
-rw-r--r--packages/megalodon/src/misskey/api_client.ts42
1 files changed, 22 insertions, 20 deletions
diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts
index 550897b669..659184d156 100644
--- a/packages/megalodon/src/misskey/api_client.ts
+++ b/packages/megalodon/src/misskey/api_client.ts
@@ -1,6 +1,5 @@
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios'
import dayjs from 'dayjs'
-import FormData from 'form-data'
import { DEFAULT_UA } from '../default'
import Response from '../response'
@@ -575,22 +574,26 @@ namespace MisskeyAPI {
this.accessToken = accessToken
this.baseUrl = baseUrl
this.userAgent = userAgent
- this.abortController = new AbortController()
- axios.defaults.signal = this.abortController.signal
+ this.abortController = new AbortController();
}
/**
* GET request to misskey API.
**/
public async get<T>(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
+ if (!headers['Authorization'] && this.accessToken) {
+ headers['Authorization'] = `Bearer ${this.accessToken}`;
+ }
+ if (!headers['User-Agent']) {
+ headers['User-Agent'] = this.userAgent;
+ }
+
let options: AxiosRequestConfig = {
params: params,
- headers: {
- 'User-Agent': this.userAgent,
- ...headers,
- },
+ headers,
maxContentLength: Infinity,
- maxBodyLength: Infinity
+ maxBodyLength: Infinity,
+ signal: this.abortController.signal,
}
return axios.get<T>(this.baseUrl + path, options).then((resp: AxiosResponse<T>) => {
const res: Response<T> = {
@@ -610,22 +613,21 @@ namespace MisskeyAPI {
* @param headers Request header object
*/
public async post<T>(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
+ if (!headers['Authorization'] && this.accessToken) {
+ headers['Authorization'] = `Bearer ${this.accessToken}`;
+ }
+ if (!headers['User-Agent']) {
+ headers['User-Agent'] = this.userAgent;
+ }
+
let options: AxiosRequestConfig = {
headers: headers,
maxContentLength: Infinity,
- maxBodyLength: Infinity
+ maxBodyLength: Infinity,
+ signal: this.abortController.signal,
}
- let bodyParams = params
- if (this.accessToken) {
- if (params instanceof FormData) {
- bodyParams.append('i', this.accessToken)
- } else {
- bodyParams = Object.assign(params, {
- i: this.accessToken
- })
- }
- }
- return axios.post<T>(this.baseUrl + path, bodyParams, options).then((resp: AxiosResponse<T>) => {
+
+ return axios.post<T>(this.baseUrl + path, params, options).then((resp: AxiosResponse<T>) => {
const res: Response<T> = {
data: resp.data,
status: resp.status,