UNPKG

@jellyfin/sdk

Version:
104 lines (101 loc) 3.35 kB
import { RequiredError } from './base.js'; /* tslint:disable */ /* eslint-disable */ /** * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * Do not edit the class manually. * * Jellyfin API * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * * @export */ const DUMMY_BASE_URL = 'https://example.com'; /** * * @throws {RequiredError} * @export */ const assertParamExists = function (functionName, paramName, paramValue) { if (paramValue === null || paramValue === undefined) { throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); } }; /** * * @export */ const setApiKeyToObject = async function (object, keyParamName, configuration) { if (configuration && configuration.apiKey) { const localVarApiKeyValue = typeof configuration.apiKey === 'function' ? await configuration.apiKey(keyParamName) : await configuration.apiKey; object[keyParamName] = localVarApiKeyValue; } }; function setFlattenedQueryParams(urlSearchParams, parameter, key = "") { if (parameter == null) return; if (typeof parameter === "object") { if (Array.isArray(parameter)) { parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); } else { Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)); } } else { if (urlSearchParams.has(key)) { urlSearchParams.append(key, parameter); } else { urlSearchParams.set(key, parameter); } } } /** * * @export */ const setSearchParams = function (url, ...objects) { const searchParams = new URLSearchParams(url.search); setFlattenedQueryParams(searchParams, objects); url.search = searchParams.toString(); }; /** * * @export */ const serializeDataIfNeeded = function (value, requestOptions, configuration) { const nonString = typeof value !== 'string'; const needsSerialization = nonString && configuration && configuration.isJsonMime ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization ? JSON.stringify(value !== undefined ? value : {}) : (value || ""); }; /** * * @export */ const toPathString = function (url) { return url.pathname + url.search + url.hash; }; /** * * @export */ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) { return (axios = globalAxios, basePath = BASE_PATH) => { var _a; const axiosRequestArgs = { ...axiosArgs.options, url: (axios.defaults.baseURL ? '' : (_a = configuration === null || configuration === void 0 ? void 0 : configuration.basePath) !== null && _a !== void 0 ? _a : basePath) + axiosArgs.url }; return axios.request(axiosRequestArgs); }; }; export { DUMMY_BASE_URL, assertParamExists, createRequestFunction, serializeDataIfNeeded, setApiKeyToObject, setSearchParams, toPathString };