فهرست منبع

Merge branch 'fix/lll_rollback' of FanYanPeng/EAIFrontend into host-nju

LiuLuLin 1 سال پیش
والد
کامیت
3504d74438
2فایلهای تغییر یافته به همراه12 افزوده شده و 108 حذف شده
  1. 0 81
      src/apis/file.ts
  2. 12 27
      src/views/AiSpeakingPage/SpeakingPage.vue

+ 0 - 81
src/apis/file.ts

@@ -1,7 +1,5 @@
 
 
-import { ElMessage } from 'element-plus';
 import axiosInstance from "@/apis/axios.config";
 import axiosInstance from "@/apis/axios.config";
-import SparkMD5 from 'spark-md5'
 
 
 const FILE_PREFIX = "/api/file"
 const FILE_PREFIX = "/api/file"
 
 
@@ -15,87 +13,8 @@ const fileApis = {
             },
             },
             timeout:300000 // 添加超时时间等待
             timeout:300000 // 添加超时时间等待
         });
         });
-    },
-    async uploadChunkFile(file, userId, assignmentId, duration) {
-        const chunkCount = Math.ceil(file.size / chunk_size)
-        // 创建文件hash
-        const md5 = await createFileMd5(file)
-        // 创建文件分片
-        const chunkList = createChunkFileList(file)
-        // 创建分片对象
-        const chunkListObj = createChunksFileObj(chunkList, file, md5, chunkCount)
-        const promises =  uploadChunkFile(chunkListObj, userId, assignmentId, duration)
-        await Promise.all(promises)
     }
     }
-
-   
-}
-
-
-const createFileMd5 = (file) =>{
-    const reader = new FileReader()
-    return new Promise((resolve, reject) => {
-        reader.onload = (e) =>{
-            const md5 = SparkMD5.ArrayBuffer.hash(e.target.result)
-            resolve(md5)
-        }
-        reader.onerror = (error) => {
-            reject(error)
-        }
-        reader.readAsArrayBuffer(file)
-    })
-
-}
-const chunk_size = 5 * 1024 * 1024
- // 创建文件分片
- const createChunkFileList = (file) => {
-    let current = 0
-    const chunkList = []
-    while(current < file.size){
-        chunkList.push(file.slice(current, Math.min(current + chunk_size, file.size)))
-        current += chunk_size
-    }
-    return chunkList
 }
 }
 
 
-const createChunksFileObj = (chunkList, file, md5, chunkCount) => {
-    return chunkList.map(((chunk, index) => {
-        return {
-            file: chunk,
-            hash: md5,
-            name: file.name,
-            index:index,
-            chunkCount
-        }
-    }))
-    
-}
-
-const uploadChunkFile = (chunkListObj, userId, assignmentId, duration) => {
-
-    return chunkListObj.map(async(chunk) =>{
-        try{
-            const formData = new FormData();
-            formData.append("file", chunk.file)
-            formData.append("fileName", chunk.name)
-            formData.append('fileMd5', chunk.hash)
-            formData.append('chunkCount', chunk.chunkCount)
-            formData.append('currentIndex', chunk.index)
-            formData.append('userId', userId)
-            formData.append('assignmentId', assignmentId)
-            formData.append('duration', duration)
-            return  axiosInstance.post(`${FILE_PREFIX}/large`, formData, {
-                headers: {
-                    'Content-Type': 'multipart/form-data'
-                }
-            });
-            
-        } catch (error) {
-            return Promise.reject(error)
-        }
-    })
-}
-
-
 
 
 export default fileApis
 export default fileApis

+ 12 - 27
src/views/AiSpeakingPage/SpeakingPage.vue

@@ -704,38 +704,23 @@ const saveHomework = async () => {
         const videoBlob = new Blob([...recordedChunks.value], { type: "video/webm" });
         const videoBlob = new Blob([...recordedChunks.value], { type: "video/webm" });
         const fileName = `user_${userId}_${assignmentId}_${Date.now()}`;
         const fileName = `user_${userId}_${assignmentId}_${Date.now()}`;
         let renameFile =new File([videoBlob], fileName +'.webm', { type: 'video/webm' })
         let renameFile =new File([videoBlob], fileName +'.webm', { type: 'video/webm' })
-        try{
-          fileApis.uploadChunkFile(renameFile, userId, assignmentId, duration)
-            .then(res => {
-                recordedChunks.value = [];
-                isHomeworkSaved.value = true;
-                hasHomeworkSaved.value = true;
-                isHomeworkStarted.value = false;
-                ElMessage.success("视频片段暂存成功");
-                loadingInstance.close();
-            })
+
+        try {
+          doubaoApis
+          .saveSigment(userId, assignmentId,renameFile, duration)
+          .then(res =>{
+            recordedChunks.value = [];
+            isHomeworkSaved.value = true;
+            hasHomeworkSaved.value = true;
+            isHomeworkStarted.value = false;
+            ElMessage.success("视频片段暂存成功");
+            loadingInstance.close();
+          })
         } catch (error) {
         } catch (error) {
           console.error("视频片段上传失败:", error);
           console.error("视频片段上传失败:", error);
           ElMessage.error("视频片段上传失败");
           ElMessage.error("视频片段上传失败");
           loadingInstance.close();
           loadingInstance.close();
         }
         }
-
-        // try {
-        //   doubaoApis
-        //   .saveSigment(userId, assignmentId,renameFile, duration)
-        //   .then(res =>{
-        //     recordedChunks.value = [];
-        //     isHomeworkSaved.value = true;
-        //     hasHomeworkSaved.value = true;
-        //     isHomeworkStarted.value = false;
-        //     ElMessage.success("视频片段暂存成功");
-        //     loadingInstance.close();
-        //   })
-        // } catch (error) {
-        //   console.error("视频片段上传失败:", error);
-        //   ElMessage.error("视频片段上传失败");
-        //   loadingInstance.close();
-        // }
       };
       };
     } else {
     } else {
       ElMessage.error('状态出错啦')
       ElMessage.error('状态出错啦')