refs #714 Add headers for pleroma api_clients
This commit is contained in:
parent
46ae259232
commit
f382e65da7
|
@ -60,6 +60,7 @@
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"https-proxy-agent": "^5.0.0",
|
"https-proxy-agent": "^5.0.0",
|
||||||
"oauth": "^0.9.15",
|
"oauth": "^0.9.15",
|
||||||
|
"object-assign-deep": "^0.4.0",
|
||||||
"socks-proxy-agent": "^5.0.0",
|
"socks-proxy-agent": "^5.0.0",
|
||||||
"typescript": "4.2.3",
|
"typescript": "4.2.3",
|
||||||
"uuid": "^8.0.0",
|
"uuid": "^8.0.0",
|
||||||
|
@ -68,6 +69,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/core-js": "^2.5.0",
|
"@types/core-js": "^2.5.0",
|
||||||
"@types/jest": "^26.0.20",
|
"@types/jest": "^26.0.20",
|
||||||
|
"@types/object-assign-deep": "^0.4.0",
|
||||||
"@types/uuid": "^8.0.0",
|
"@types/uuid": "^8.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.19.2",
|
"@typescript-eslint/eslint-plugin": "^2.19.2",
|
||||||
"@typescript-eslint/parser": "^2.19.2",
|
"@typescript-eslint/parser": "^2.19.2",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { OAuth2 } from 'oauth'
|
import { OAuth2 } from 'oauth'
|
||||||
|
import FormData from 'form-data'
|
||||||
|
|
||||||
import MastodonAPI from './mastodon/api_client'
|
import MastodonAPI from './mastodon/api_client'
|
||||||
import WebSocket from './mastodon/web_socket'
|
import WebSocket from './mastodon/web_socket'
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import FormData from 'form-data'
|
||||||
|
|
||||||
import MisskeyAPI from './misskey/api_client'
|
import MisskeyAPI from './misskey/api_client'
|
||||||
import { DEFAULT_UA } from './default'
|
import { DEFAULT_UA } from './default'
|
||||||
import { ProxyConfig } from './proxy_config'
|
import { ProxyConfig } from './proxy_config'
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { OAuth2 } from 'oauth'
|
import { OAuth2 } from 'oauth'
|
||||||
|
import FormData from 'form-data'
|
||||||
|
|
||||||
import PleromaAPI from './pleroma/api_client'
|
import PleromaAPI from './pleroma/api_client'
|
||||||
import WebSocket from './pleroma/web_socket'
|
import WebSocket from './pleroma/web_socket'
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import axios, { AxiosResponse, CancelTokenSource, AxiosRequestConfig } from 'axios'
|
import axios, { AxiosResponse, CancelTokenSource, AxiosRequestConfig } from 'axios'
|
||||||
|
import objectAssignDeep from 'object-assign-deep'
|
||||||
|
|
||||||
import MegalodonEntity from '../entity'
|
import MegalodonEntity from '../entity'
|
||||||
import PleromaEntity from './entity'
|
import PleromaEntity from './entity'
|
||||||
|
@ -217,11 +218,11 @@ namespace PleromaAPI {
|
||||||
* Interface
|
* Interface
|
||||||
*/
|
*/
|
||||||
export interface Interface {
|
export interface Interface {
|
||||||
get<T = any>(path: string, params?: any): Promise<Response<T>>
|
get<T = any>(path: string, params?: any, headers?: { [key: string]: string }): Promise<Response<T>>
|
||||||
put<T = any>(path: string, params?: any): Promise<Response<T>>
|
put<T = any>(path: string, params?: any, headers?: { [key: string]: string }): Promise<Response<T>>
|
||||||
patch<T = any>(path: string, params?: any): Promise<Response<T>>
|
patch<T = any>(path: string, params?: any, headers?: { [key: string]: string }): Promise<Response<T>>
|
||||||
post<T = any>(path: string, params?: any): Promise<Response<T>>
|
post<T = any>(path: string, params?: any, headers?: { [key: string]: string }): Promise<Response<T>>
|
||||||
del<T = any>(path: string, params?: any): Promise<Response<T>>
|
del<T = any>(path: string, params?: any, headers?: { [key: string]: string }): Promise<Response<T>>
|
||||||
cancel(): void
|
cancel(): void
|
||||||
socket(path: string, stream: string, params?: string): WebSocket
|
socket(path: string, stream: string, params?: string): WebSocket
|
||||||
}
|
}
|
||||||
|
@ -266,13 +267,14 @@ namespace PleromaAPI {
|
||||||
* @param path relative path from baseUrl
|
* @param path relative path from baseUrl
|
||||||
* @param params Query parameters
|
* @param params Query parameters
|
||||||
*/
|
*/
|
||||||
public async get<T>(path: string, params = {}): Promise<Response<T>> {
|
public async get<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
|
||||||
let options: AxiosRequestConfig = {
|
let options: AxiosRequestConfig = {
|
||||||
cancelToken: this.cancelTokenSource.token,
|
cancelToken: this.cancelTokenSource.token,
|
||||||
params: params
|
params: params,
|
||||||
|
headers: headers
|
||||||
}
|
}
|
||||||
if (this.accessToken) {
|
if (this.accessToken) {
|
||||||
options = Object.assign(options, {
|
options = objectAssignDeep({}, options, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.accessToken}`
|
Authorization: `Bearer ${this.accessToken}`
|
||||||
}
|
}
|
||||||
|
@ -309,12 +311,13 @@ namespace PleromaAPI {
|
||||||
* @param path relative path from baseUrl
|
* @param path relative path from baseUrl
|
||||||
* @param params Form data. If you want to post file, please use FormData()
|
* @param params Form data. If you want to post file, please use FormData()
|
||||||
*/
|
*/
|
||||||
public async put<T>(path: string, params = {}): Promise<Response<T>> {
|
public async put<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
|
||||||
let options: AxiosRequestConfig = {
|
let options: AxiosRequestConfig = {
|
||||||
cancelToken: this.cancelTokenSource.token
|
cancelToken: this.cancelTokenSource.token,
|
||||||
|
headers: headers
|
||||||
}
|
}
|
||||||
if (this.accessToken) {
|
if (this.accessToken) {
|
||||||
options = Object.assign(options, {
|
options = objectAssignDeep({}, options, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.accessToken}`
|
Authorization: `Bearer ${this.accessToken}`
|
||||||
}
|
}
|
||||||
|
@ -351,12 +354,13 @@ namespace PleromaAPI {
|
||||||
* @param path relative path from baseUrl
|
* @param path relative path from baseUrl
|
||||||
* @param params Form data. If you want to post file, please use FormData()
|
* @param params Form data. If you want to post file, please use FormData()
|
||||||
*/
|
*/
|
||||||
public async patch<T>(path: string, params = {}): Promise<Response<T>> {
|
public async patch<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
|
||||||
let options: AxiosRequestConfig = {
|
let options: AxiosRequestConfig = {
|
||||||
cancelToken: this.cancelTokenSource.token
|
cancelToken: this.cancelTokenSource.token,
|
||||||
|
headers: headers
|
||||||
}
|
}
|
||||||
if (this.accessToken) {
|
if (this.accessToken) {
|
||||||
options = Object.assign(options, {
|
options = objectAssignDeep({}, options, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.accessToken}`
|
Authorization: `Bearer ${this.accessToken}`
|
||||||
}
|
}
|
||||||
|
@ -393,12 +397,13 @@ namespace PleromaAPI {
|
||||||
* @param path relative path from baseUrl
|
* @param path relative path from baseUrl
|
||||||
* @param params Form data
|
* @param params Form data
|
||||||
*/
|
*/
|
||||||
public async post<T>(path: string, params = {}): Promise<Response<T>> {
|
public async post<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
|
||||||
let options: AxiosRequestConfig = {
|
let options: AxiosRequestConfig = {
|
||||||
cancelToken: this.cancelTokenSource.token
|
cancelToken: this.cancelTokenSource.token,
|
||||||
|
headers: headers
|
||||||
}
|
}
|
||||||
if (this.accessToken) {
|
if (this.accessToken) {
|
||||||
options = Object.assign(options, {
|
options = objectAssignDeep({}, options, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.accessToken}`
|
Authorization: `Bearer ${this.accessToken}`
|
||||||
}
|
}
|
||||||
|
@ -426,13 +431,14 @@ namespace PleromaAPI {
|
||||||
* @param path relative path from baseUrl
|
* @param path relative path from baseUrl
|
||||||
* @param params Form data
|
* @param params Form data
|
||||||
*/
|
*/
|
||||||
public async del<T>(path: string, params = {}): Promise<Response<T>> {
|
public async del<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
|
||||||
let options: AxiosRequestConfig = {
|
let options: AxiosRequestConfig = {
|
||||||
cancelToken: this.cancelTokenSource.token,
|
cancelToken: this.cancelTokenSource.token,
|
||||||
data: params
|
data: params,
|
||||||
|
headers: headers
|
||||||
}
|
}
|
||||||
if (this.accessToken) {
|
if (this.accessToken) {
|
||||||
options = Object.assign(options, {
|
options = objectAssignDeep({}, options, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.accessToken}`
|
Authorization: `Bearer ${this.accessToken}`
|
||||||
}
|
}
|
||||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -703,6 +703,11 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
|
|
||||||
|
"@types/object-assign-deep@^0.4.0":
|
||||||
|
version "0.4.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/object-assign-deep/-/object-assign-deep-0.4.0.tgz#23c66300f2d04676b927ee700308d0d1b5f8df89"
|
||||||
|
integrity sha512-3D0F3rHRNDc8cQSXNzwF1jBrJi28Mdrhc10ZLlqbJWDPYRWTTWB9Tc8JoKrgBvLKioXoPoHT6Uzf3s2F7akCUg==
|
||||||
|
|
||||||
"@types/prettier@^2.0.0":
|
"@types/prettier@^2.0.0":
|
||||||
version "2.1.6"
|
version "2.1.6"
|
||||||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.1.6.tgz#f4b1efa784e8db479cdb8b14403e2144b1e9ff03"
|
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.1.6.tgz#f4b1efa784e8db479cdb8b14403e2144b1e9ff03"
|
||||||
|
@ -3473,6 +3478,11 @@ oauth@^0.9.15:
|
||||||
resolved "https://registry.yarnpkg.com/oauth/-/oauth-0.9.15.tgz#bd1fefaf686c96b75475aed5196412ff60cfb9c1"
|
resolved "https://registry.yarnpkg.com/oauth/-/oauth-0.9.15.tgz#bd1fefaf686c96b75475aed5196412ff60cfb9c1"
|
||||||
integrity sha1-vR/vr2hslrdUda7VGWQS/2DPucE=
|
integrity sha1-vR/vr2hslrdUda7VGWQS/2DPucE=
|
||||||
|
|
||||||
|
object-assign-deep@^0.4.0:
|
||||||
|
version "0.4.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/object-assign-deep/-/object-assign-deep-0.4.0.tgz#43505d3679abb9686ab359b97ac14cc837a9d143"
|
||||||
|
integrity sha512-54Uvn3s+4A/cMWx9tlRez1qtc7pN7pbQ+Yi7mjLjcBpWLlP+XbSHiHbQW6CElDiV4OvuzqnMrBdkgxI1mT8V/Q==
|
||||||
|
|
||||||
object-copy@^0.1.0:
|
object-copy@^0.1.0:
|
||||||
version "0.1.0"
|
version "0.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/object-copy/-/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c"
|
resolved "https://registry.yarnpkg.com/object-copy/-/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c"
|
||||||
|
|
Loading…
Reference in a new issue