Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

use-common.ts 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { get, post } from './base'
  2. import type {
  3. FileUploadConfigResponse,
  4. Member,
  5. StructuredOutputRulesRequestBody,
  6. StructuredOutputRulesResponse,
  7. } from '@/models/common'
  8. import { useMutation, useQuery } from '@tanstack/react-query'
  9. import type { FileTypesRes } from './datasets'
  10. const NAME_SPACE = 'common'
  11. export const useFileUploadConfig = () => {
  12. return useQuery<FileUploadConfigResponse>({
  13. queryKey: [NAME_SPACE, 'file-upload-config'],
  14. queryFn: () => get<FileUploadConfigResponse>('/files/upload'),
  15. })
  16. }
  17. export const useGenerateStructuredOutputRules = () => {
  18. return useMutation({
  19. mutationKey: [NAME_SPACE, 'generate-structured-output-rules'],
  20. mutationFn: (body: StructuredOutputRulesRequestBody) => {
  21. return post<StructuredOutputRulesResponse>(
  22. '/rule-structured-output-generate',
  23. { body },
  24. )
  25. },
  26. })
  27. }
  28. export type MailSendResponse = { data: string, result: string }
  29. export const useSendMail = () => {
  30. return useMutation({
  31. mutationKey: [NAME_SPACE, 'mail-send'],
  32. mutationFn: (body: { email: string, language: string }) => {
  33. return post<MailSendResponse>('/email-register/send-email', { body })
  34. },
  35. })
  36. }
  37. export type MailValidityResponse = { is_valid: boolean, token: string }
  38. export const useMailValidity = () => {
  39. return useMutation({
  40. mutationKey: [NAME_SPACE, 'mail-validity'],
  41. mutationFn: (body: { email: string, code: string, token: string }) => {
  42. return post<MailValidityResponse>('/email-register/validity', { body })
  43. },
  44. })
  45. }
  46. export type MailRegisterResponse = { result: string, data: { access_token: string, refresh_token: string } }
  47. export const useMailRegister = () => {
  48. return useMutation({
  49. mutationKey: [NAME_SPACE, 'mail-register'],
  50. mutationFn: (body: { token: string, new_password: string, password_confirm: string }) => {
  51. return post<MailRegisterResponse>('/email-register', { body })
  52. },
  53. })
  54. }
  55. export const useFileSupportTypes = () => {
  56. return useQuery<FileTypesRes>({
  57. queryKey: [NAME_SPACE, 'file-types'],
  58. queryFn: () => get<FileTypesRes>('/files/support-type'),
  59. })
  60. }
  61. type MemberResponse = {
  62. accounts: Member[] | null
  63. }
  64. export const useMembers = () => {
  65. return useQuery<MemberResponse>({
  66. queryKey: [NAME_SPACE, 'members'],
  67. queryFn: (params: Record<string, any>) => get<MemberResponse>('/workspaces/current/members', {
  68. params,
  69. }),
  70. })
  71. }
  72. type FilePreviewResponse = {
  73. content: string
  74. }
  75. export const useFilePreview = (fileID: string) => {
  76. return useQuery<FilePreviewResponse>({
  77. queryKey: [NAME_SPACE, 'file-preview', fileID],
  78. queryFn: () => get<FilePreviewResponse>(`/files/${fileID}/preview`),
  79. enabled: !!fileID,
  80. })
  81. }
  82. export type SchemaTypeDefinition = {
  83. name: string
  84. schema: {
  85. properties: Record<string, any>
  86. }
  87. }
  88. export const useSchemaTypeDefinitions = () => {
  89. return useQuery<SchemaTypeDefinition[]>({
  90. queryKey: [NAME_SPACE, 'schema-type-definitions'],
  91. queryFn: () => get<SchemaTypeDefinition[]>('/spec/schema-definitions'),
  92. })
  93. }