recall.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import client from './client'
  2. import type {
  3. AIUnderstandingVO,
  4. ArticleBasicVO,
  5. CommonResponse,
  6. DeconstructPointsVO,
  7. DeconstructQueryParam,
  8. DeconstructResultVO,
  9. DeconstructSubmitParam,
  10. MatchByArticleIdParam,
  11. MatchByMaterialIdParam,
  12. MatchByTextParam,
  13. MatchByVideoIdParam,
  14. MaterialBasicVO,
  15. RecallResultVO,
  16. VideoBasicVO,
  17. } from './types'
  18. const EMPTY_RESULT: RecallResultVO = {
  19. items: [],
  20. videoCount: 0,
  21. materialCount: 0,
  22. articleCount: 0,
  23. total: 0,
  24. }
  25. /**
  26. * 后端 MATERIAL 模态下 id 为 null,materialId(图片 md5)才是实际主键。
  27. * 前端组件统一用 item.id 做 rowKey/筛选/展示,这里在数据入口处把 materialId 回填到 id。
  28. */
  29. function normalizeRecallResult(data: RecallResultVO | null | undefined): RecallResultVO {
  30. if (!data) return EMPTY_RESULT
  31. const items = data.items.map((it) => {
  32. if (it.id == null && it.materialId) return { ...it, id: it.materialId }
  33. if (it.id == null && it.articleId) return { ...it, id: it.articleId }
  34. return it
  35. })
  36. return { ...data, items }
  37. }
  38. /** Tab1: 获取视频基础详情 */
  39. export async function getVideoDetail(videoId: string): Promise<VideoBasicVO | null> {
  40. const resp = await client.get<CommonResponse<VideoBasicVO | null>>(
  41. '/recallTest/videoDetail',
  42. { params: { videoId } },
  43. )
  44. return resp.data?.data ?? null
  45. }
  46. /** Tab2: 文本召回 */
  47. export async function matchByText(param: MatchByTextParam): Promise<RecallResultVO> {
  48. const resp = await client.post<CommonResponse<RecallResultVO>>(
  49. '/recallTest/matchByText',
  50. param,
  51. )
  52. return normalizeRecallResult(resp.data?.data)
  53. }
  54. /** Tab1: 通过视频ID召回相似 */
  55. export async function matchByVideoId(param: MatchByVideoIdParam): Promise<RecallResultVO> {
  56. const resp = await client.post<CommonResponse<RecallResultVO>>(
  57. '/recallTest/matchByVideoId',
  58. param,
  59. )
  60. return normalizeRecallResult(resp.data?.data)
  61. }
  62. /** Tab3: 获取素材基础信息 (图片URL等, 用于预览) */
  63. export async function getMaterialDetail(materialId: string): Promise<MaterialBasicVO | null> {
  64. const resp = await client.get<CommonResponse<MaterialBasicVO | null>>(
  65. '/recallTest/materialDetail',
  66. { params: { materialId } },
  67. )
  68. return resp.data?.data ?? null
  69. }
  70. /** Tab3: 通过素材ID召回相似 */
  71. export async function matchByMaterialId(param: MatchByMaterialIdParam): Promise<RecallResultVO> {
  72. const resp = await client.post<CommonResponse<RecallResultVO>>(
  73. '/recallTest/matchByMaterialId',
  74. param,
  75. )
  76. return normalizeRecallResult(resp.data?.data)
  77. }
  78. /** Tab4: 获取长文基础信息 */
  79. export async function getArticleDetail(articleId: string): Promise<ArticleBasicVO | null> {
  80. const resp = await client.get<CommonResponse<ArticleBasicVO | null>>(
  81. '/recallTest/articleDetail',
  82. { params: { articleId } },
  83. )
  84. return resp.data?.data ?? null
  85. }
  86. /** Tab4: 通过长文ID召回相似 */
  87. export async function matchByArticleId(param: MatchByArticleIdParam): Promise<RecallResultVO> {
  88. const resp = await client.post<CommonResponse<RecallResultVO>>(
  89. '/recallTest/matchByArticleId',
  90. param,
  91. )
  92. return normalizeRecallResult(resp.data?.data)
  93. }
  94. /** Tab1: 视频/素材的解构层级 */
  95. export async function getDeconstructPoints(videoId: string): Promise<DeconstructPointsVO | null> {
  96. const resp = await client.get<CommonResponse<DeconstructPointsVO | null>>(
  97. '/recallTest/deconstructPoints',
  98. { params: { videoId } },
  99. )
  100. return resp.data?.data ?? null
  101. }
  102. /** Tab1: AI理解结果 (未就绪时返回 null) */
  103. export async function getAiUnderstanding(videoId: string): Promise<AIUnderstandingVO | null> {
  104. const resp = await client.get<CommonResponse<AIUnderstandingVO | null>>(
  105. '/recallTest/aiUnderstanding',
  106. { params: { videoId } },
  107. )
  108. return resp.data?.data ?? null
  109. }
  110. /** 召回维度字典: configCode -> 中文标签 */
  111. export async function getAllConfigCodes(): Promise<Record<string, string>> {
  112. const resp = await client.get<CommonResponse<Record<string, string>>>(
  113. '/videoSearch/getAllConfigCodes',
  114. )
  115. return resp.data?.data ?? {}
  116. }
  117. /** Tab3: 提交素材解构任务 - 返回 taskId */
  118. export async function submitDeconstruct(param: DeconstructSubmitParam): Promise<string> {
  119. const resp = await client.post<CommonResponse<string>>(
  120. '/videoSearch/deconstruct',
  121. param,
  122. )
  123. return resp.data?.data ?? ''
  124. }
  125. /** Tab3: 查询解构结果 (轮询用; 走精简接口, 后端直接返回 topic + highValuePoints) */
  126. export async function getDeconstructResult(
  127. param: DeconstructQueryParam,
  128. ): Promise<DeconstructResultVO | null> {
  129. const resp = await client.post<CommonResponse<DeconstructResultVO | null>>(
  130. '/videoSearch/getDeconstructResultMini',
  131. param,
  132. )
  133. return resp.data?.data ?? null
  134. }