refactor: rewrite header handling, lowercase apiKey, and cleanup
This commit is contained in:
parent
ba370250a2
commit
7bc48484a2
|
@ -88,7 +88,7 @@ export async function getCidUrl(
|
|||
): Promise<string> {
|
||||
const opt = { ...this.customOptions, customOptions };
|
||||
return addUrlQuery(path.join(this.portalUrl, cid), {
|
||||
auth_token: opt.ApiKey,
|
||||
auth_token: opt.apiKey,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { AxiosProgressEvent, AxiosRequestConfig } from "axios";
|
||||
import { S5Client } from "../client.js";
|
||||
import {AxiosHeaders, AxiosProgressEvent, AxiosRequestConfig} from "axios";
|
||||
import {S5Client} from "../client.js";
|
||||
|
||||
/**
|
||||
* Custom client options.
|
||||
*
|
||||
* @property [ApiKey] - Authentication password to use for a single S5 node/portal.
|
||||
* @property [apiKey] - Authentication password to use for a single S5 node/portal.
|
||||
* @property [customUserAgent] - Custom user agent header to set.
|
||||
* @property [customCookie] - Custom cookie header to set. WARNING: the Cookie header cannot be set in browsers. This is meant for usage in server contexts.
|
||||
* @property [onDownloadProgress] - Optional callback to track download progress.
|
||||
|
@ -12,7 +12,7 @@ import { S5Client } from "../client.js";
|
|||
*/
|
||||
|
||||
export type CustomClientOptions = {
|
||||
ApiKey?: string;
|
||||
apiKey?: string;
|
||||
customUserAgent?: string;
|
||||
customCookie?: string;
|
||||
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||
|
@ -39,7 +39,7 @@ export function optionsToConfig(
|
|||
...def,
|
||||
...client.customOptions,
|
||||
...extraOptions,
|
||||
};
|
||||
} as CustomClientOptions;
|
||||
|
||||
if (finalOptions?.onDownloadProgress) {
|
||||
config.onDownloadProgress = finalOptions?.onDownloadProgress;
|
||||
|
@ -49,32 +49,27 @@ export function optionsToConfig(
|
|||
config.onUploadProgress = finalOptions?.onUploadProgress;
|
||||
}
|
||||
|
||||
const headers = new AxiosHeaders(config.headers as AxiosHeaders)
|
||||
|
||||
if (finalOptions?.customCookie) {
|
||||
config.headers = {
|
||||
Cookie: finalOptions?.customCookie,
|
||||
};
|
||||
}
|
||||
headers.set("Cookie", finalOptions.customCookie);
|
||||
|
||||
}
|
||||
if (finalOptions?.customUserAgent) {
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
"User-Agent": finalOptions?.customUserAgent,
|
||||
};
|
||||
headers.set("User-Agent", finalOptions.customUserAgent);
|
||||
}
|
||||
|
||||
if (finalOptions?.ApiKey) {
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
Authorization: `Bearer ${finalOptions?.ApiKey}`,
|
||||
};
|
||||
|
||||
if (finalOptions?.apiKey) {
|
||||
headers.set("Authorization", `Bearer ${finalOptions.apiKey}`);
|
||||
config.withCredentials = true;
|
||||
|
||||
config.params = {
|
||||
...config.params,
|
||||
auth_token: finalOptions?.ApiKey,
|
||||
auth_token: finalOptions?.apiKey,
|
||||
};
|
||||
}
|
||||
|
||||
config.headers = headers;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue