style: prettier
This commit is contained in:
parent
7bc48484a2
commit
5bc2915655
|
@ -1,5 +1,5 @@
|
||||||
import {AxiosHeaders, AxiosProgressEvent, AxiosRequestConfig} from "axios";
|
import { AxiosHeaders, AxiosProgressEvent, AxiosRequestConfig } from "axios";
|
||||||
import {S5Client} from "../client.js";
|
import { S5Client } from "../client.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom client options.
|
* Custom client options.
|
||||||
|
@ -12,64 +12,63 @@ import {S5Client} from "../client.js";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type CustomClientOptions = {
|
export type CustomClientOptions = {
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
customUserAgent?: string;
|
customUserAgent?: string;
|
||||||
customCookie?: string;
|
customCookie?: string;
|
||||||
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||||
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function optionsToConfig(
|
export function optionsToConfig(
|
||||||
client: S5Client,
|
client: S5Client,
|
||||||
def: CustomClientOptions,
|
def: CustomClientOptions,
|
||||||
...options: CustomClientOptions[]
|
...options: CustomClientOptions[]
|
||||||
): AxiosRequestConfig {
|
): AxiosRequestConfig {
|
||||||
const config: AxiosRequestConfig = {};
|
const config: AxiosRequestConfig = {};
|
||||||
|
|
||||||
config.baseURL = client.portalUrl;
|
config.baseURL = client.portalUrl;
|
||||||
|
|
||||||
const extraOptions = options.reduce((acc, val) => {
|
const extraOptions = options.reduce((acc, val) => {
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
...val,
|
...val,
|
||||||
};
|
};
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const finalOptions = {
|
const finalOptions = {
|
||||||
...def,
|
...def,
|
||||||
...client.customOptions,
|
...client.customOptions,
|
||||||
...extraOptions,
|
...extraOptions,
|
||||||
} as CustomClientOptions;
|
} as CustomClientOptions;
|
||||||
|
|
||||||
if (finalOptions?.onDownloadProgress) {
|
if (finalOptions?.onDownloadProgress) {
|
||||||
config.onDownloadProgress = finalOptions?.onDownloadProgress;
|
config.onDownloadProgress = finalOptions?.onDownloadProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalOptions?.onUploadProgress) {
|
if (finalOptions?.onUploadProgress) {
|
||||||
config.onUploadProgress = finalOptions?.onUploadProgress;
|
config.onUploadProgress = finalOptions?.onUploadProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = new AxiosHeaders(config.headers as AxiosHeaders)
|
const headers = new AxiosHeaders(config.headers as AxiosHeaders);
|
||||||
|
|
||||||
if (finalOptions?.customCookie) {
|
if (finalOptions?.customCookie) {
|
||||||
headers.set("Cookie", finalOptions.customCookie);
|
headers.set("Cookie", finalOptions.customCookie);
|
||||||
|
}
|
||||||
|
if (finalOptions?.customUserAgent) {
|
||||||
|
headers.set("User-Agent", finalOptions.customUserAgent);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (finalOptions?.apiKey) {
|
||||||
if (finalOptions?.customUserAgent) {
|
headers.set("Authorization", `Bearer ${finalOptions.apiKey}`);
|
||||||
headers.set("User-Agent", finalOptions.customUserAgent);
|
config.withCredentials = true;
|
||||||
}
|
|
||||||
|
|
||||||
if (finalOptions?.apiKey) {
|
config.params = {
|
||||||
headers.set("Authorization", `Bearer ${finalOptions.apiKey}`);
|
...config.params,
|
||||||
config.withCredentials = true;
|
auth_token: finalOptions?.apiKey,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
config.params = {
|
config.headers = headers;
|
||||||
...config.params,
|
|
||||||
auth_token: finalOptions?.apiKey,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
config.headers = headers;
|
return config;
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue