lsc 3 months ago
parent
commit
2a1934caa2
1 changed files with 51 additions and 2 deletions
  1. 51 2
      src/components/pages/pptEasy/addCourse.vue

+ 51 - 2
src/components/pages/pptEasy/addCourse.vue

@@ -2451,6 +2451,7 @@ import CodeEditor from "../components/CodeEditor";
 import InteractiveToolDialog from "./dialog/InteractiveToolDialog.vue";
 import VideoUploadDialog from "./dialog/VideoUploadDialog.vue";
 import BilibiliSearchDialog from "./dialog/BilibiliSearchDialog.vue";
+import { v4 as uuidv4 } from "uuid";
 var OpenCC = require("opencc-js");
 let converter = OpenCC.Converter({
   from: "hk",
@@ -4654,6 +4655,51 @@ export default {
         this.$forceUpdate();
       }
     },
+    // 上传文件
+    async uploadFile2(file, pptid) {
+      try {
+        let uuid = uuidv4();
+        let formData = new FormData();
+        const timestamp = Date.now();
+        const finalExtension = file.name.split(".").pop().toLowerCase();
+        const baseName = file.name.slice(0, -(finalExtension.length + 1));
+        formData.append(
+          "file",
+          new File([file], `${baseName}${timestamp}.${finalExtension}`)
+        );
+        formData.append("collection_ids", JSON.stringify([]));
+        formData.append("id", uuid);
+        formData.append("metadata", JSON.stringify({ title: file.name }));
+        formData.append("ingestion_mode", "fast");
+        formData.append("run_with_orchestration", "true");
+        // 确保formData是正确的格式
+        // this.$store.state.fileApi + "upload"
+
+        // 同步知识库
+        await this.ajax.post(
+          "https://r2rserver.cocorobo.cn/v3/documents",
+          formData,
+          {
+            headers: {
+              "Content-Type": "multipart/form-data",
+            },
+          }
+        );
+        let ptype = "1"; // 根据实际业务定义类型
+        let fileid = uuid; // 如果需要唯一fileid可以和pptid保持一致或按需更改
+        await this.ajax.post(this.$store.state.api + "addPPTFile", [{
+          pptid: pptid,
+          ptype: ptype,
+          fileid: fileid,
+          classid: "",
+          task: "",
+          tool: ""
+        }]);
+      } catch (err) {
+        console.error(err);
+        throw err;
+      }
+    },
     async addWork() {
       if(this.$refs.pptIframeRef.contentWindow.window.pptLoading !== 2)return this.$message.info("ppt正在加载中,请稍等")
       if(this.uploadWorkLoading)return;
@@ -4662,10 +4708,11 @@ export default {
 
       // 用_pptData生成json文件,并生成File对象
       const pptJsonStr = JSON.stringify(_pptData, null, 2);
-      const pptJsonFile = new File([pptJsonStr], "pptData.json", { type: "application/json" });
+      const pptJsonFile = new File([pptJsonStr], this.courseName+".json", { type: "application/json" });
       // 你可以根据需要将pptJsonFile上传或保存
 
       let _url = await this.uploadFile(pptJsonFile);
+
       console.log(_url)
       this.pptCourseJson.pptData = _url;
 
@@ -4722,6 +4769,7 @@ export default {
           this.courseUserid = this.userid;
           this.islogin = true;
           this.steps = 4;
+          this.uploadFile2(pptJsonFile, this.courseId);
           this.addOp3(
             "1",
             "",
@@ -4812,10 +4860,11 @@ export default {
 
       // 用_pptData生成json文件,并生成File对象
       const pptJsonStr = JSON.stringify(_pptData, null, 2);
-      const pptJsonFile = new File([pptJsonStr], "pptData.json", { type: "application/json" });
+      const pptJsonFile = new File([pptJsonStr], this.courseName + ".json", { type: "application/json" });
       // 你可以根据需要将pptJsonFile上传或保存
       console.log(_url)
       let _url = await this.uploadFile(pptJsonFile);
+      this.uploadFile2(pptJsonFile, this.cid);
 
       this.pptCourseJson.pptData = _url;