UNPKG

@fdm-monster/server

Version:

FDM Monster is a bulk OctoPrint, Klipper, PrusaLink and BambuLab manager to set up, configure and monitor 3D printers. Our aim is to provide neat overview over your farm.

76 lines (75 loc) 2.32 kB
import { getDefaultTimeout } from "../constants/server-settings.constants.js"; import { contentTypeHeaderKey, jsonContentType, multiPartContentType } from "../services/octoprint/constants/octoprint-service.constants.js"; import axios from "axios"; //#region src/shared/default-http-client.builder.ts var DefaultHttpClientBuilder = class { axiosOptions; constructor() { this.axiosOptions = { baseURL: "", timeout: getDefaultTimeout().apiTimeout, headers: { [contentTypeHeaderKey]: jsonContentType } }; } build() { const axiosConfig = { baseURL: this.axiosOptions.baseURL, timeout: this.axiosOptions.timeout, headers: this.axiosOptions.headers, data: this.axiosOptions.data, maxBodyLength: this.axiosOptions.maxBodyLength ?? 1e3 * 1e3 * 1e3, maxContentLength: this.axiosOptions.maxContentLength ?? 1e3 * 1e3 * 1e3, responseType: this.axiosOptions.responseType, onUploadProgress: this.axiosOptions.onUploadProgress }; return axios.create(axiosConfig); } withMaxBodyLength(maxBodyLength) { this.axiosOptions.maxBodyLength = maxBodyLength; return this; } withMaxContentLength(maxContentLength) { this.axiosOptions.maxContentLength = maxContentLength; return this; } withBaseUrl(baseUrl) { if (!baseUrl?.length) throw new Error("Base address may not be an empty string"); this.axiosOptions.baseURL = baseUrl; return this; } /** * Set the timeout for the http client. * @param timeout the value for timeout in milliseconds. */ withTimeout(timeout) { if (!timeout || timeout <= 0) throw new Error("Timeout value (milliseconds) must be greater than 0"); this.axiosOptions.timeout = timeout; return this; } withMultiPartFormData() { this.withHeaders({ "Content-Type": multiPartContentType }); return this; } withStreamResponse() { this.axiosOptions.responseType = "stream"; return this; } withOnUploadProgress(handler) { this.axiosOptions.onUploadProgress = handler; return this; } withJsonContentTypeHeader() { this.withHeaders({ [contentTypeHeaderKey]: jsonContentType }); return this; } withHeaders(headers) { this.axiosOptions.headers = { ...this.axiosOptions.headers, ...headers }; return this; } }; //#endregion export { DefaultHttpClientBuilder }; //# sourceMappingURL=default-http-client.builder.js.map