common.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* tslint:disable */
  2. /* eslint-disable */
  3. /**
  4. * Immich
  5. * Immich API
  6. *
  7. * The version of the OpenAPI document: 1.81.0
  8. *
  9. *
  10. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  11. * https://openapi-generator.tech
  12. * Do not edit the class manually.
  13. */
  14. import type { Configuration } from "./configuration";
  15. import type { RequestArgs } from "./base";
  16. import type { AxiosInstance, AxiosResponse } from 'axios';
  17. import { RequiredError } from "./base";
  18. /**
  19. *
  20. * @export
  21. */
  22. export const DUMMY_BASE_URL = 'https://example.com'
  23. /**
  24. *
  25. * @throws {RequiredError}
  26. * @export
  27. */
  28. export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
  29. if (paramValue === null || paramValue === undefined) {
  30. throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
  31. }
  32. }
  33. /**
  34. *
  35. * @export
  36. */
  37. export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
  38. if (configuration && configuration.apiKey) {
  39. const localVarApiKeyValue = typeof configuration.apiKey === 'function'
  40. ? await configuration.apiKey(keyParamName)
  41. : await configuration.apiKey;
  42. object[keyParamName] = localVarApiKeyValue;
  43. }
  44. }
  45. /**
  46. *
  47. * @export
  48. */
  49. export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
  50. if (configuration && (configuration.username || configuration.password)) {
  51. object["auth"] = { username: configuration.username, password: configuration.password };
  52. }
  53. }
  54. /**
  55. *
  56. * @export
  57. */
  58. export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
  59. if (configuration && configuration.accessToken) {
  60. const accessToken = typeof configuration.accessToken === 'function'
  61. ? await configuration.accessToken()
  62. : await configuration.accessToken;
  63. object["Authorization"] = "Bearer " + accessToken;
  64. }
  65. }
  66. /**
  67. *
  68. * @export
  69. */
  70. export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
  71. if (configuration && configuration.accessToken) {
  72. const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
  73. ? await configuration.accessToken(name, scopes)
  74. : await configuration.accessToken;
  75. object["Authorization"] = "Bearer " + localVarAccessTokenValue;
  76. }
  77. }
  78. function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
  79. if (parameter == null) return;
  80. if (typeof parameter === "object") {
  81. if (Array.isArray(parameter)) {
  82. (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
  83. }
  84. else {
  85. Object.keys(parameter).forEach(currentKey =>
  86. setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
  87. );
  88. }
  89. }
  90. else {
  91. if (urlSearchParams.has(key)) {
  92. urlSearchParams.append(key, parameter);
  93. }
  94. else {
  95. urlSearchParams.set(key, parameter);
  96. }
  97. }
  98. }
  99. /**
  100. *
  101. * @export
  102. */
  103. export const setSearchParams = function (url: URL, ...objects: any[]) {
  104. const searchParams = new URLSearchParams(url.search);
  105. setFlattenedQueryParams(searchParams, objects);
  106. url.search = searchParams.toString();
  107. }
  108. /**
  109. *
  110. * @export
  111. */
  112. export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
  113. const nonString = typeof value !== 'string';
  114. const needsSerialization = nonString && configuration && configuration.isJsonMime
  115. ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
  116. : nonString;
  117. return needsSerialization
  118. ? JSON.stringify(value !== undefined ? value : {})
  119. : (value || "");
  120. }
  121. /**
  122. *
  123. * @export
  124. */
  125. export const toPathString = function (url: URL) {
  126. return url.pathname + url.search + url.hash
  127. }
  128. /**
  129. *
  130. * @export
  131. */
  132. export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
  133. return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
  134. const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
  135. return axios.request<T, R>(axiosRequestArgs);
  136. };
  137. }