cloudflare.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Cloudflare Stream API 类型定义
  2. // 视频状态
  3. export type VideoState = 'pendingupload' | 'downloading' | 'queued' | 'inprogress' | 'ready' | 'error'
  4. // 视频信息
  5. export interface CloudflareVideo {
  6. uid: string
  7. creator?: string
  8. thumbnail: string
  9. thumbnailTimestampPct?: number
  10. readyToStream: boolean
  11. readyToStreamAt?: string
  12. status: {
  13. state: VideoState
  14. pctComplete?: string
  15. errorReasonCode?: string
  16. errorReasonText?: string
  17. }
  18. meta: Record<string, any>
  19. created: string
  20. modified: string
  21. scheduledDeletion?: string
  22. size: number
  23. preview: string
  24. allowedOrigins: string[]
  25. requireSignedURLs: boolean
  26. uploaded: string
  27. uploadExpiry?: string
  28. maxSizeBytes?: number
  29. maxDurationSeconds?: number
  30. duration: number
  31. input: {
  32. width: number
  33. height: number
  34. }
  35. playback: {
  36. hls: string
  37. dash: string
  38. }
  39. watermark?: {
  40. uid: string
  41. size: number
  42. height: number
  43. width: number
  44. created: string
  45. downloadedFrom: string
  46. name: string
  47. opacity: number
  48. padding: number
  49. scale: number
  50. position: string
  51. }
  52. clippedFrom?: string
  53. publicDetails?: {
  54. title?: string
  55. share_link?: string
  56. channel_link?: string
  57. logo?: string
  58. }
  59. }
  60. // 直播输入(Live Input)
  61. export interface CloudflareLiveInput {
  62. uid: string
  63. created: string
  64. modified: string
  65. meta: Record<string, any>
  66. deleteRecordingAfterDays?: number
  67. status?: {
  68. current: {
  69. state: 'connected' | 'disconnected'
  70. statusEnteredAt?: string
  71. statusLastChangedAt?: string
  72. }
  73. }
  74. rtmps: {
  75. url: string
  76. streamKey: string
  77. }
  78. rtmpsPlayback?: {
  79. url: string
  80. streamKey: string
  81. }
  82. srt?: {
  83. url: string
  84. streamId: string
  85. passphrase: string
  86. }
  87. srtPlayback?: {
  88. url: string
  89. streamId: string
  90. passphrase: string
  91. }
  92. webRTC?: {
  93. url: string
  94. }
  95. webRTCPlayback?: {
  96. url: string
  97. }
  98. recording?: {
  99. mode: 'off' | 'automatic'
  100. requireSignedURLs?: boolean
  101. allowedOrigins?: string[]
  102. timeoutSeconds?: number
  103. }
  104. }
  105. // 直播输出
  106. export interface CloudflareLiveOutput {
  107. uid: string
  108. url: string
  109. streamKey: string
  110. enabled: boolean
  111. }
  112. // 上传 URL 响应
  113. export interface UploadUrlResponse {
  114. uploadURL: string
  115. uid: string
  116. watermark?: any
  117. }
  118. // 直接上传响应
  119. export interface DirectUploadResponse {
  120. result: {
  121. uploadURL: string
  122. uid: string
  123. }
  124. }
  125. // API 响应包装
  126. export interface CloudflareApiResponse<T> {
  127. result: T
  128. success: boolean
  129. errors: Array<{ code: number; message: string }>
  130. messages: Array<{ code: number; message: string }>
  131. }
  132. // 列表响应
  133. export interface CloudflareListResponse<T> {
  134. result: T[]
  135. success: boolean
  136. errors: Array<{ code: number; message: string }>
  137. messages: Array<{ code: number; message: string }>
  138. result_info?: {
  139. page: number
  140. per_page: number
  141. count: number
  142. total_count: number
  143. }
  144. }
  145. // 签名 URL 参数
  146. export interface SignedUrlParams {
  147. id: string // 视频 ID
  148. exp?: number // 过期时间戳
  149. nbf?: number // 生效时间戳
  150. downloadable?: boolean // 是否可下载
  151. accessRules?: Array<{
  152. type: 'ip.geoip.country' | 'ip.src' | 'any'
  153. country?: string[]
  154. ip?: string[]
  155. action: 'allow' | 'block'
  156. }>
  157. }
  158. // 视频播放信息
  159. export interface VideoPlaybackInfo {
  160. uid: string
  161. preview: string
  162. thumbnail: string
  163. playback: {
  164. hls: string
  165. dash: string
  166. }
  167. iframe: string
  168. }
  169. // 创建直播输入参数
  170. export interface CreateLiveInputParams {
  171. meta?: Record<string, any>
  172. recording?: {
  173. mode: 'off' | 'automatic'
  174. requireSignedURLs?: boolean
  175. allowedOrigins?: string[]
  176. timeoutSeconds?: number
  177. }
  178. deleteRecordingAfterDays?: number
  179. }
  180. // 创建上传 URL 参数
  181. export interface CreateUploadUrlParams {
  182. maxDurationSeconds?: number
  183. expiry?: string
  184. creator?: string
  185. thumbnailTimestampPct?: number
  186. allowedOrigins?: string[]
  187. requireSignedURLs?: boolean
  188. watermark?: { uid: string }
  189. meta?: Record<string, any>
  190. scheduledDeletion?: string
  191. }