stream.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * 视频流管理 API(通过后端代理)
  3. *
  4. * 推荐使用这个封装,通过后端代理调用 Cloudflare API
  5. * 避免在前端暴露 API Token
  6. */
  7. import { get, post, put, del } from '@/utils/request'
  8. import type { ApiResponse } from '@/types'
  9. import type {
  10. CloudflareVideo,
  11. CloudflareLiveInput,
  12. CreateLiveInputParams,
  13. CreateUploadUrlParams,
  14. VideoPlaybackInfo
  15. } from '@/types/cloudflare'
  16. // ==================== 视频管理 ====================
  17. /**
  18. * 获取视频列表
  19. */
  20. export function listVideos(params?: {
  21. pageNum?: number
  22. pageSize?: number
  23. search?: string
  24. status?: string
  25. }): Promise<ApiResponse<{ rows: CloudflareVideo[]; total: number }>> {
  26. return get('/stream/video/list', params)
  27. }
  28. /**
  29. * 获取视频详情
  30. */
  31. export function getVideo(videoId: string): Promise<ApiResponse<CloudflareVideo>> {
  32. return get(`/stream/video/${videoId}`)
  33. }
  34. /**
  35. * 删除视频
  36. */
  37. export function deleteVideo(videoId: string): Promise<ApiResponse<null>> {
  38. return del(`/stream/video/${videoId}`)
  39. }
  40. /**
  41. * 从 URL 导入视频
  42. */
  43. export function importVideoFromUrl(data: {
  44. url: string
  45. name?: string
  46. meta?: Record<string, any>
  47. }): Promise<ApiResponse<CloudflareVideo>> {
  48. return post('/stream/video/import', data)
  49. }
  50. /**
  51. * 获取上传 URL
  52. */
  53. export function getUploadUrl(params?: CreateUploadUrlParams): Promise<
  54. ApiResponse<{
  55. uploadURL: string
  56. uid: string
  57. }>
  58. > {
  59. return post('/stream/video/upload-url', params)
  60. }
  61. /**
  62. * 获取视频播放信息
  63. */
  64. export function getVideoPlayback(videoId: string): Promise<ApiResponse<VideoPlaybackInfo>> {
  65. return get(`/stream/video/${videoId}/playback`)
  66. }
  67. // ==================== 直播管理 ====================
  68. /**
  69. * 获取直播输入列表
  70. */
  71. export function listLiveInputs(params?: {
  72. pageNum?: number
  73. pageSize?: number
  74. }): Promise<ApiResponse<{ rows: CloudflareLiveInput[]; total: number }>> {
  75. return get('/stream/live/list', params)
  76. }
  77. /**
  78. * 创建直播输入
  79. */
  80. export function createLiveInput(data?: CreateLiveInputParams): Promise<ApiResponse<CloudflareLiveInput>> {
  81. return post('/stream/live', data)
  82. }
  83. /**
  84. * 获取直播输入详情
  85. */
  86. export function getLiveInput(liveInputId: string): Promise<ApiResponse<CloudflareLiveInput>> {
  87. return get(`/stream/live/${liveInputId}`)
  88. }
  89. /**
  90. * 更新直播输入
  91. */
  92. export function updateLiveInput(
  93. liveInputId: string,
  94. data: CreateLiveInputParams
  95. ): Promise<ApiResponse<CloudflareLiveInput>> {
  96. return put(`/stream/live/${liveInputId}`, data)
  97. }
  98. /**
  99. * 删除直播输入
  100. */
  101. export function deleteLiveInput(liveInputId: string): Promise<ApiResponse<null>> {
  102. return del(`/stream/live/${liveInputId}`)
  103. }
  104. /**
  105. * 获取直播播放信息
  106. */
  107. export function getLivePlayback(liveInputId: string): Promise<ApiResponse<VideoPlaybackInfo>> {
  108. return get(`/stream/live/${liveInputId}/playback`)
  109. }
  110. /**
  111. * 获取直播录像列表
  112. */
  113. export function listLiveRecordings(
  114. liveInputId: string,
  115. params?: {
  116. pageNum?: number
  117. pageSize?: number
  118. }
  119. ): Promise<ApiResponse<{ rows: CloudflareVideo[]; total: number }>> {
  120. return get(`/stream/live/${liveInputId}/recordings`, params)
  121. }
  122. // ==================== 转推管理 ====================
  123. /**
  124. * 获取转推输出列表
  125. */
  126. export function listLiveOutputs(liveInputId: string): Promise<ApiResponse<any[]>> {
  127. return get(`/stream/live/${liveInputId}/outputs`)
  128. }
  129. /**
  130. * 创建转推输出
  131. */
  132. export function createLiveOutput(
  133. liveInputId: string,
  134. data: {
  135. url: string
  136. streamKey: string
  137. enabled?: boolean
  138. }
  139. ): Promise<ApiResponse<any>> {
  140. return post(`/stream/live/${liveInputId}/outputs`, data)
  141. }
  142. /**
  143. * 删除转推输出
  144. */
  145. export function deleteLiveOutput(liveInputId: string, outputId: string): Promise<ApiResponse<null>> {
  146. return del(`/stream/live/${liveInputId}/outputs/${outputId}`)
  147. }