Browse Source

add error message

ming 3 years ago
parent
commit
73a2ae55e8
2 changed files with 20 additions and 11 deletions
  1. 3 3
      api/main.py
  2. 17 8
      api/static/script_util.js

+ 3 - 3
api/main.py

@@ -324,7 +324,7 @@ async def make_anchor_video(req:models.request,token: str = Depends(oauth2_schem
     save_history(req,name_hash,user_id)
     x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,user_id))
     x.start()
-    return {"msg":"製作影片需要時間,請您耐心等候,成果會傳送至LINE群組中"} 
+    return "ok" 
 
 @app.post("/make_anchor_video_eng")
 async def make_anchor_video_eng(req:models.request_eng):
@@ -604,8 +604,8 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,use
             else:
                 left_time = left_time - vid_duration
                 db.query('UPDATE users SET left_time ='+str(left_time)+' WHERE id='+str(user_id)+';')
-                #notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
-                notify_line_user(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4", line_token)
+                notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
+                #notify_line_user(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4", line_token)
         except Exception as e:
             logging.error(traceback.format_exc())
             print('video generation error')

+ 17 - 8
api/static/script_util.js

@@ -160,18 +160,27 @@ $("#sendBTN").click(function () {
   xhr.setRequestHeader("Authorization","Bearer "+jwt_token)
   xhr.setRequestHeader("Content-Type", "application/json");
   xhr.onreadystatechange = function () {
-    if (xhr.readyState === 4) {
-      Swal.fire({
-        title: "資料已送出",
-        icon: 'success',
-        text: '資料已傳送,請耐心等候',
-        confirmButtonColor: '#3085d6',
-      });
-    }
+    
   };
   var data = renderXHR_data(dataOBJ)
   console.log(data)
   result = xhr.send(objstr);
+  if  (result !='ok') {
+    Swal.fire({
+      title: "資料已送出",
+      icon: 'success',
+      text: '資料已傳送,請耐心等候',
+      confirmButtonColor: '#3085d6',
+    });
+  }
+  else{
+    Swal.fire({
+      title: '發生錯誤',
+      icon: 'success',
+      text: result.msg,
+      confirmButtonColor: '#3085d6',
+    });
+  }
 });
 
 const slide_button = document.querySelector('#send_slide');