index.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { WEBUI_BASE_URL } from '$lib/constants';
  2. export const getBackendConfig = async () => {
  3. let error = null;
  4. const res = await fetch(`${WEBUI_BASE_URL}/api/config`, {
  5. method: 'GET',
  6. headers: {
  7. 'Content-Type': 'application/json'
  8. }
  9. })
  10. .then(async (res) => {
  11. if (!res.ok) throw await res.json();
  12. return res.json();
  13. })
  14. .catch((err) => {
  15. console.log(err);
  16. error = err;
  17. return null;
  18. });
  19. if (error) {
  20. throw error;
  21. }
  22. return res;
  23. };
  24. export const getChangelog = async () => {
  25. let error = null;
  26. const res = await fetch(`${WEBUI_BASE_URL}/api/changelog`, {
  27. method: 'GET',
  28. headers: {
  29. 'Content-Type': 'application/json'
  30. }
  31. })
  32. .then(async (res) => {
  33. if (!res.ok) throw await res.json();
  34. return res.json();
  35. })
  36. .catch((err) => {
  37. console.log(err);
  38. error = err;
  39. return null;
  40. });
  41. if (error) {
  42. throw error;
  43. }
  44. return res;
  45. };
  46. export const getVersionUpdates = async () => {
  47. let error = null;
  48. const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, {
  49. method: 'GET',
  50. headers: {
  51. 'Content-Type': 'application/json'
  52. }
  53. })
  54. .then(async (res) => {
  55. if (!res.ok) throw await res.json();
  56. return res.json();
  57. })
  58. .catch((err) => {
  59. console.log(err);
  60. error = err;
  61. return null;
  62. });
  63. if (error) {
  64. throw error;
  65. }
  66. return res;
  67. };
  68. export const getModelFilterConfig = async (token: string) => {
  69. let error = null;
  70. const res = await fetch(`${WEBUI_BASE_URL}/api/config/model/filter`, {
  71. method: 'GET',
  72. headers: {
  73. 'Content-Type': 'application/json',
  74. Authorization: `Bearer ${token}`
  75. }
  76. })
  77. .then(async (res) => {
  78. if (!res.ok) throw await res.json();
  79. return res.json();
  80. })
  81. .catch((err) => {
  82. console.log(err);
  83. error = err;
  84. return null;
  85. });
  86. if (error) {
  87. throw error;
  88. }
  89. return res;
  90. };
  91. export const updateModelFilterConfig = async (
  92. token: string,
  93. enabled: boolean,
  94. models: string[]
  95. ) => {
  96. let error = null;
  97. const res = await fetch(`${WEBUI_BASE_URL}/api/config/model/filter`, {
  98. method: 'POST',
  99. headers: {
  100. 'Content-Type': 'application/json',
  101. Authorization: `Bearer ${token}`
  102. },
  103. body: JSON.stringify({
  104. enabled: enabled,
  105. models: models
  106. })
  107. })
  108. .then(async (res) => {
  109. if (!res.ok) throw await res.json();
  110. return res.json();
  111. })
  112. .catch((err) => {
  113. console.log(err);
  114. error = err;
  115. return null;
  116. });
  117. if (error) {
  118. throw error;
  119. }
  120. return res;
  121. };