style: prettier

This commit is contained in:
Derrick Hammer 2024-03-18 09:10:07 -04:00
parent 7bc48484a2
commit 5bc2915655
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 46 additions and 47 deletions

View File

@ -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;
} }