Эх сурвалжийг харах

保存又拍云到公司服务器

Michael Wang 6 жил өмнө
parent
commit
b98739ac4b

+ 26 - 29
src/components/FaceRecognition/FaceRecognition.vue

@@ -93,10 +93,8 @@ export default {
         const examRecordDataId = this.$route.params.examRecordDataId;
         const captureBlob = await this.getSnapShot();
         // console.log(captureBlob.size);
-        const [fileName, captureFilePath] = await this.uploadToServer(
-          captureBlob
-        );
-        await this.faceCompare(fileName, captureFilePath, examRecordDataId);
+        const captureFilePath = await this.uploadToServer(captureBlob);
+        await this.faceCompare(captureFilePath, examRecordDataId);
       } catch (error) {
         // FIXME: more processing
         console.log("定时抓拍流程失败");
@@ -133,7 +131,7 @@ export default {
         this.msg = "拍照中...";
         const captureBlob = await this.getSnapShot();
         this.msg = "上传照片中...";
-        const [, captureFilePath] = await this.uploadToServer(captureBlob);
+        const captureFilePath = await this.uploadToServer(captureBlob);
         this.msg = "人脸比对中...";
         await this.faceCompareSync(captureFilePath);
       } catch (error) {
@@ -164,38 +162,38 @@ export default {
         var context = canvas.getContext("2d");
         context.drawImage(video, 0, 0, 220, 165);
 
-        canvas.toBlob(resolve);
+        canvas.toBlob(resolve, "image/jpeg", 0.95);
         video.play();
       });
     },
     async uploadToServer(captureBlob) {
-      //保存抓拍照片到又拍云
-      var fileName = new Date().getTime() + ".jpg";
-      var fileUrl = "/capture_photo/" + this.user.userId + "/" + fileName;
+      //保存抓拍照片到服务器
+      // var fileName = new Date().getTime() + ".png";
+      // var fileUrl = "/api/exchange/inner/upyun/put/capturePhoto/" + fileName;
+      var fileUrl = "/api/exchange/inner/upyun/put/capturePhoto/jpg";
+      let resultUrl;
       try {
-        await this.$upyunhttp.put(fileUrl, captureBlob, {
+        const res = await this.$http.put(fileUrl, captureBlob, {
           headers: {
-            "Content-Type": "image/jpeg"
+            "Content-Type": "image/jpg"
           }
         });
+        resultUrl = res.data;
       } catch (e) {
         console.log(e);
-        this.$Message.error("保存抓拍照片到又拍云失败!");
-        throw "保存抓拍照片到又拍云失败!";
+        this.$Message.error("保存抓拍照片到服务器失败!");
+        throw "保存抓拍照片到服务器失败!";
       }
 
-      let UPYUN_URL;
-      try {
-        UPYUN_URL = (await this.$http.get("/api/ecs_oe_student_face/upyun"))
-          .data.downloadPrefix;
-      } catch (error) {
-        this.$Message.error("获取又拍云下载前缀失败!");
-        throw "获取又拍云下载前缀失败!";
-      }
-      return [
-        fileName,
-        UPYUN_URL + "/capture_photo/" + this.user.userId + "/" + fileName
-      ];
+      // let UPYUN_URL;
+      // try {
+      //   UPYUN_URL = (await this.$http.get("/api/ecs_oe_student_face/upyun"))
+      //     .data.downloadPrefix;
+      // } catch (error) {
+      //   this.$Message.error("获取照片下载前缀失败!");
+      //   throw "获取照片下载前缀失败!";
+      // }
+      return resultUrl;
     },
     async faceCompareSync(captureFilePath) {
       try {
@@ -216,16 +214,15 @@ export default {
         throw "同步照片比较失败!";
       }
     },
-    async faceCompare(fileName, captureFilePath, examRecordDataId) {
+    async faceCompare(captureFilePath, examRecordDataId) {
       try {
-        await this.$http.post(
+        const res = await this.$http.post(
           "/api/ecs_oe_student_face/examCaptureQueue/uploadExamCapture?fileUrl=" +
             captureFilePath +
-            "&fileName=" +
-            fileName +
             "&examRecordDataId=" +
             examRecordDataId
         );
+        const fileName = res.data;
         try {
           await this.showSnapResult(fileName, examRecordDataId);
         } catch (error) {

+ 44 - 44
src/utils/axios.js

@@ -105,58 +105,58 @@ qmInstance.get = cachingGet(qmInstance.get, [
 ]);
 loadProgressBar(qmInstance);
 
-const upyunInstance = axios.create({});
-// FIXME: axios bug. wait 0.19 release. https://github.com/axios/axios/issues/385
-upyunInstance.defaults.headers.common = {};
-// upyunInstance.defaults.headers.common["Authorization"] = UPYUN_HEADER_AUTH;
+// const upyunInstance = axios.create({});
+// // FIXME: axios bug. wait 0.19 release. https://github.com/axios/axios/issues/385
+// upyunInstance.defaults.headers.common = {};
+// // upyunInstance.defaults.headers.common["Authorization"] = UPYUN_HEADER_AUTH;
 
-let __upyunAuth = null;
-let __upyunBucketUrl = null;
-upyunInstance.interceptors.request.use(
-  config => {
-    if (__upyunAuth) {
-      config.baseURL = __upyunBucketUrl;
-      config.headers.common["Authorization"] = __upyunAuth;
-      return config;
-    } else {
-      return qmInstance
-        .get("/api/ecs_oe_student_face/upyun")
-        .then(res => {
-          __upyunBucketUrl = res.data.bucketUrl;
-          config.baseURL = __upyunBucketUrl;
-          const authorization =
-            "Basic " +
-            btoa(atob(res.data.upyunOperator) + ":" + atob(res.data.upyunCred));
-          __upyunAuth = authorization;
-          config.headers.common["Authorization"] = __upyunAuth;
-          return config;
-        })
-        .catch(err => {
-          console.log(err);
-        });
-    }
-  },
-  error => {
-    Message.error({
-      content: error,
-      duration: 10,
-      closable: true
-    });
-    return Promise.resolve(error);
-  }
-);
+// let __upyunAuth = null;
+// let __upyunBucketUrl = null;
+// upyunInstance.interceptors.request.use(
+//   config => {
+//     if (__upyunAuth) {
+//       config.baseURL = __upyunBucketUrl;
+//       config.headers.common["Authorization"] = __upyunAuth;
+//       return config;
+//     } else {
+//       return qmInstance
+//         .get("/api/ecs_oe_student_face/upyun")
+//         .then(res => {
+//           __upyunBucketUrl = res.data.bucketUrl;
+//           config.baseURL = __upyunBucketUrl;
+//           const authorization =
+//             "Basic " +
+//             btoa(atob(res.data.upyunOperator) + ":" + atob(res.data.upyunCred));
+//           __upyunAuth = authorization;
+//           config.headers.common["Authorization"] = __upyunAuth;
+//           return config;
+//         })
+//         .catch(err => {
+//           console.log(err);
+//         });
+//     }
+//   },
+//   error => {
+//     Message.error({
+//       content: error,
+//       duration: 10,
+//       closable: true
+//     });
+//     return Promise.resolve(error);
+//   }
+// );
 
-loadProgressBar(upyunInstance);
+// loadProgressBar(upyunInstance);
 
 Vue.prototype.$http = qmInstance;
-Vue.prototype.$upyunhttp = upyunInstance;
+// Vue.prototype.$upyunhttp = upyunInstance;
 export default {
   install: function(Vue) {
     Object.defineProperty(Vue.prototype, "$http", {
       value: qmInstance
     });
-    Object.defineProperty(Vue.prototype, "$upyunhttp", {
-      value: upyunInstance
-    });
+    // Object.defineProperty(Vue.prototype, "$upyunhttp", {
+    //   value: upyunInstance
+    // });
   }
 };