|
|
@@ -119,7 +119,7 @@ class CloudflareStreamApi {
|
|
|
/**
|
|
|
* 裁剪视频
|
|
|
*/
|
|
|
- async clipVideo(videoId: string, params: {
|
|
|
+ async clipVideo(params: {
|
|
|
clippedFromVideoUID: string
|
|
|
startTimeSeconds: number
|
|
|
endTimeSeconds: number
|
|
|
@@ -139,11 +139,17 @@ class CloudflareStreamApi {
|
|
|
|
|
|
/**
|
|
|
* 使用 TUS 协议上传视频
|
|
|
- * 注意:大文件上传建议使用 tus-js-client 库
|
|
|
+ * 注意:需要先安装 tus-js-client:npm install tus-js-client
|
|
|
*/
|
|
|
async uploadWithTus(file: File, uploadUrl: string, onProgress?: (progress: number) => void): Promise<void> {
|
|
|
- // 动态导入 tus-js-client
|
|
|
- const { Upload } = await import('tus-js-client')
|
|
|
+ // 动态导入 tus-js-client(需要先安装:npm install tus-js-client)
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
+ const tusClient = await import('tus-js-client' as any) as any
|
|
|
+ const Upload = tusClient.Upload || tusClient.default?.Upload
|
|
|
+
|
|
|
+ if (!Upload) {
|
|
|
+ throw new Error('tus-js-client not installed. Run: npm install tus-js-client')
|
|
|
+ }
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const upload = new Upload(file, {
|
|
|
@@ -153,11 +159,11 @@ class CloudflareStreamApi {
|
|
|
filename: file.name,
|
|
|
filetype: file.type
|
|
|
},
|
|
|
- onError: (error) => {
|
|
|
+ onError: (error: Error) => {
|
|
|
console.error('Upload failed:', error)
|
|
|
reject(error)
|
|
|
},
|
|
|
- onProgress: (bytesUploaded, bytesTotal) => {
|
|
|
+ onProgress: (bytesUploaded: number, bytesTotal: number) => {
|
|
|
const percentage = Math.round((bytesUploaded / bytesTotal) * 100)
|
|
|
onProgress?.(percentage)
|
|
|
},
|