stream.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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<ApiResponse<{
  54. uploadURL: string
  55. uid: string
  56. }>> {
  57. return post('/stream/video/upload-url', params)
  58. }
  59. /**
  60. * 获取视频播放信息
  61. */
  62. export function getVideoPlayback(videoId: string): Promise<ApiResponse<VideoPlaybackInfo>> {
  63. return get(`/stream/video/${videoId}/playback`)
  64. }
  65. // ==================== 直播管理 ====================
  66. /**
  67. * 获取直播输入列表
  68. */
  69. export function listLiveInputs(params?: {
  70. pageNum?: number
  71. pageSize?: number
  72. }): Promise<ApiResponse<{ rows: CloudflareLiveInput[]; total: number }>> {
  73. return get('/stream/live/list', params)
  74. }
  75. /**
  76. * 创建直播输入
  77. */
  78. export function createLiveInput(data?: CreateLiveInputParams): Promise<ApiResponse<CloudflareLiveInput>> {
  79. return post('/stream/live', data)
  80. }
  81. /**
  82. * 获取直播输入详情
  83. */
  84. export function getLiveInput(liveInputId: string): Promise<ApiResponse<CloudflareLiveInput>> {
  85. return get(`/stream/live/${liveInputId}`)
  86. }
  87. /**
  88. * 更新直播输入
  89. */
  90. export function updateLiveInput(liveInputId: string, data: CreateLiveInputParams): Promise<ApiResponse<CloudflareLiveInput>> {
  91. return put(`/stream/live/${liveInputId}`, data)
  92. }
  93. /**
  94. * 删除直播输入
  95. */
  96. export function deleteLiveInput(liveInputId: string): Promise<ApiResponse<null>> {
  97. return del(`/stream/live/${liveInputId}`)
  98. }
  99. /**
  100. * 获取直播播放信息
  101. */
  102. export function getLivePlayback(liveInputId: string): Promise<ApiResponse<VideoPlaybackInfo>> {
  103. return get(`/stream/live/${liveInputId}/playback`)
  104. }
  105. /**
  106. * 获取直播录像列表
  107. */
  108. export function listLiveRecordings(liveInputId: string, params?: {
  109. pageNum?: number
  110. pageSize?: number
  111. }): Promise<ApiResponse<{ rows: CloudflareVideo[]; total: number }>> {
  112. return get(`/stream/live/${liveInputId}/recordings`, params)
  113. }
  114. // ==================== 转推管理 ====================
  115. /**
  116. * 获取转推输出列表
  117. */
  118. export function listLiveOutputs(liveInputId: string): Promise<ApiResponse<any[]>> {
  119. return get(`/stream/live/${liveInputId}/outputs`)
  120. }
  121. /**
  122. * 创建转推输出
  123. */
  124. export function createLiveOutput(liveInputId: string, data: {
  125. url: string
  126. streamKey: string
  127. enabled?: boolean
  128. }): Promise<ApiResponse<any>> {
  129. return post(`/stream/live/${liveInputId}/outputs`, data)
  130. }
  131. /**
  132. * 删除转推输出
  133. */
  134. export function deleteLiveOutput(liveInputId: string, outputId: string): Promise<ApiResponse<null>> {
  135. return del(`/stream/live/${liveInputId}/outputs/${outputId}`)
  136. }