storage.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // 我的音色库&形象库
  2. import {
  3. bluebookAiAgent,
  4. } from '@/xiaolanbenlib/api/index'
  5. import request from '@/xiaolanbenlib/module/axios.js'
  6. import Taro from '@tarojs/taro'
  7. import {FileTypes} from '@/consts'
  8. export type TAvatarItem = {
  9. avatarId: number,
  10. avatarLogo: string,
  11. avatarUrl: string,
  12. isOriginal: boolean
  13. canDel: boolean
  14. isVideo: boolean
  15. videoSeconds: number
  16. }
  17. // 上传形象--并生成微视频
  18. export type TUploadAvatarResponse = {
  19. data: TAvatarItem[],
  20. message: string, // 任务状态描述 失败原因 ,
  21. status: string, // 任务状态 processing 处理中/ success 处理成功/ process_fail 处理失败/not_found 未找到 ,
  22. userId: string,
  23. taskId: string
  24. }
  25. export const uploadAvatar = (data: {
  26. "aiGenerated": boolean,
  27. "avatarUrl": string,
  28. "description": string
  29. }) => {
  30. return request.post<TUploadAvatarResponse>(`${bluebookAiAgent}api/v1/my/avatar`, data)
  31. }
  32. // 根据指定形象归生成微视频
  33. export const genAvatarVideo = (data: {
  34. "avatarUrl": string,
  35. }) => {
  36. return request.post<TUploadAvatarResponse>(`${bluebookAiAgent}api/v1/my/avatar/4video`, data)
  37. }
  38. // 获取上传形象任务的处理状态
  39. export const getUploadedAvatarStatus = (taskId: string|number) => {
  40. return request.get<TUploadAvatarResponse>(`${bluebookAiAgent}api/v1/my/avatar/task/${taskId}`)
  41. }
  42. // 获取个人形象库
  43. export const fetchMyAvatars = ({pageSize = 20, pageIndex = 1}:{pageSize?: number, pageIndex?: number}) => {
  44. return request.get<{
  45. pageIndex: number
  46. pageSize: number
  47. totalCount: number
  48. data: TAvatarItem[]
  49. }>(`${bluebookAiAgent}api/v1/my/avatars`, {params: {
  50. pageSize,
  51. pageIndex
  52. }})
  53. }
  54. // 删除指定的形象记录
  55. export const deleteAvatar = (avatarId: string|number) => {
  56. return request.delete(`${bluebookAiAgent}api/v1/my/avatar/${avatarId}`)
  57. }
  58. // 用户上传文件--返回{'fileId':'xxxx', 'publicUrl':'xxxx'}
  59. // /blue-aiagent/api/v1/my/upload
  60. export const uploadFilesFromWechat = ()=> {
  61. Taro.chooseMessageFile({
  62. count: 10,
  63. type: "file",
  64. extension: FileTypes.map((f) => `${f}`),
  65. success(res) {
  66. const tempFilePaths = res.tempFiles;
  67. console.log("tempFilePaths", tempFilePaths);
  68. const files = tempFilePaths.map((file) => {
  69. return {
  70. file,
  71. status: 0,
  72. fileProgress: {
  73. progress: 0,
  74. totalBytesSent: 0,
  75. totalBytesExpectedToSend: 0,
  76. },
  77. };
  78. });
  79. // setUploadingList(files);
  80. // setUploadList(files);
  81. console.log(files);
  82. },
  83. });
  84. }
  85. // 前端获取自主上传文件至存贮的安全令牌
  86. export type TUploadSecurityToken = {
  87. "accessKeyId": string,
  88. "accessKeySecret": string,
  89. "expiration": string,
  90. "fullPath": string,
  91. "publicUrl": string,
  92. "securityToken": string,
  93. "statusCode": string
  94. }
  95. export const getUploadSecurityToken = () => {
  96. return request.get<TUploadSecurityToken>(`${bluebookAiAgent}api/v1/my/upload/securityToken`)
  97. }