common.ts 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import type { Fetcher } from 'swr'
  2. import { get, post, del, put } from './base'
  3. import type {
  4. CommonResponse, LangGeniusVersionResponse, OauthResponse,
  5. TenantInfoResponse, UserProfileOriginResponse, Member,
  6. AccountIntegrate, Provider, ProviderAzureToken, IWorkspace
  7. } from '@/models/common'
  8. import type {
  9. ValidateOpenAIKeyResponse,
  10. UpdateOpenAIKeyResponse
  11. } from '@/models/app'
  12. export const login: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  13. return post(url, { body }) as Promise<CommonResponse>
  14. }
  15. export const setup: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
  16. return post('/setup', { body }) as Promise<CommonResponse>
  17. }
  18. export const fetchUserProfile: Fetcher<UserProfileOriginResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  19. return get(url, params, { needAllResponseContent: true }) as Promise<UserProfileOriginResponse>
  20. }
  21. export const updateUserProfile: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  22. return post(url, { body }) as Promise<CommonResponse>
  23. }
  24. export const fetchTenantInfo: Fetcher<TenantInfoResponse, { url: string }> = ({ url }) => {
  25. return get(url) as Promise<TenantInfoResponse>
  26. }
  27. export const logout: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  28. return get(url, params) as Promise<CommonResponse>
  29. }
  30. export const fetchLanggeniusVersion: Fetcher<LangGeniusVersionResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  31. return get(url, { params }) as Promise<LangGeniusVersionResponse>
  32. }
  33. export const oauth: Fetcher<OauthResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  34. return get(url, { params }) as Promise<OauthResponse>
  35. }
  36. export const oneMoreStep: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  37. return post(url, { body }) as Promise<CommonResponse>
  38. }
  39. export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  40. return get(url, { params }) as Promise<{ accounts: Member[] | null }>
  41. }
  42. export const fetchProviders: Fetcher<Provider[] | null, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  43. return get(url, { params }) as Promise<Provider[] | null>
  44. }
  45. export const validateProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  46. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  47. }
  48. export const updateProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string | ProviderAzureToken } }> = ({ url, body }) => {
  49. return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
  50. }
  51. export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  52. return get(url, { params }) as Promise<{ data: AccountIntegrate[] | null }>
  53. }
  54. export const inviteMember: Fetcher<CommonResponse & { account: Member }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  55. return post(url, { body }) as Promise<CommonResponse & { account: Member }>
  56. }
  57. export const updateMemberRole: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  58. return put(url, { body }) as Promise<CommonResponse>
  59. }
  60. export const deleteMemberOrCancelInvitation: Fetcher<CommonResponse, { url: string; }> = ({ url }) => {
  61. return del(url) as Promise<CommonResponse>
  62. }
  63. export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => {
  64. return get(`/files/${fileID}/preview`) as Promise<{ content: string }>
  65. }
  66. export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  67. return get(url, { params }) as Promise<{ workspaces: IWorkspace[] }>
  68. }
  69. export const switchWorkspace: Fetcher<CommonResponse & { new_tenant: IWorkspace }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  70. return post(url, { body }) as Promise<CommonResponse & { new_tenant: IWorkspace }>
  71. }