您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

use-common.ts 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { get, post } from './base'
  2. import type {
  3. FileUploadConfigResponse,
  4. StructuredOutputRulesRequestBody,
  5. StructuredOutputRulesResponse,
  6. } from '@/models/common'
  7. import { useMutation, useQuery } from '@tanstack/react-query'
  8. const NAME_SPACE = 'common'
  9. export const useFileUploadConfig = () => {
  10. return useQuery<FileUploadConfigResponse>({
  11. queryKey: [NAME_SPACE, 'file-upload-config'],
  12. queryFn: () => get<FileUploadConfigResponse>('/files/upload'),
  13. })
  14. }
  15. export const useGenerateStructuredOutputRules = () => {
  16. return useMutation({
  17. mutationKey: [NAME_SPACE, 'generate-structured-output-rules'],
  18. mutationFn: (body: StructuredOutputRulesRequestBody) => {
  19. return post<StructuredOutputRulesResponse>(
  20. '/rule-structured-output-generate',
  21. { body },
  22. )
  23. },
  24. })
  25. }
  26. export type MailSendResponse = { data: string, result: string }
  27. export const useSendMail = () => {
  28. return useMutation({
  29. mutationKey: [NAME_SPACE, 'mail-send'],
  30. mutationFn: (body: { email: string, language: string }) => {
  31. return post<MailSendResponse>('/email-register/send-email', { body })
  32. },
  33. })
  34. }
  35. export type MailValidityResponse = { is_valid: boolean, token: string }
  36. export const useMailValidity = () => {
  37. return useMutation({
  38. mutationKey: [NAME_SPACE, 'mail-validity'],
  39. mutationFn: (body: { email: string, code: string, token: string }) => {
  40. return post<MailValidityResponse>('/email-register/validity', { body })
  41. },
  42. })
  43. }
  44. export type MailRegisterResponse = { result: string, data: { access_token: string, refresh_token: string } }
  45. export const useMailRegister = () => {
  46. return useMutation({
  47. mutationKey: [NAME_SPACE, 'mail-register'],
  48. mutationFn: (body: { token: string, new_password: string, password_confirm: string }) => {
  49. return post<MailRegisterResponse>('/email-register', { body })
  50. },
  51. })
  52. }