common.ts 4.1 KB

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