Browse Source

fix upload file

ming 3 years ago
parent
commit
6da745f108
2 changed files with 6 additions and 3 deletions
  1. 4 0
      api/main.py
  2. 2 3
      api/static/script_msg.js

+ 4 - 0
api/main.py

@@ -126,6 +126,8 @@ async def create_upload_file(file: UploadFile = File(...)):
 
 
 @app.post("/make_anchor_video_v2")
 @app.post("/make_anchor_video_v2")
 async def make_anchor_video_v2(req:request):
 async def make_anchor_video_v2(req:request):
+    if len(req.image_urls) != len(req.text_content):
+        return {'msg':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}
     for idx in range(len(req.image_urls)):
     for idx in range(len(req.image_urls)):
         if 'http' not in req.image_urls[idx]:
         if 'http' not in req.image_urls[idx]:
             req.image_urls[idx] = 'http://'+req.image_urls[idx]
             req.image_urls[idx] = 'http://'+req.image_urls[idx]
@@ -150,6 +152,8 @@ async def make_anchor_video_v2(req:request):
 
 
 @app.post("/make_anchor_video_eng")
 @app.post("/make_anchor_video_eng")
 async def make_anchor_video_eng(req:request_eng):
 async def make_anchor_video_eng(req:request_eng):
+    if len(req.image_urls) != len(req.sub_titles) or len(req.sub_titles) != len(req.text_content):
+        return {'msg':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}
     for idx in range(len(req.image_urls)):
     for idx in range(len(req.image_urls)):
         if 'http' not in req.image_urls[idx]:
         if 'http' not in req.image_urls[idx]:
             req.image_urls[idx] = 'http://'+req.image_urls[idx]
             req.image_urls[idx] = 'http://'+req.image_urls[idx]

+ 2 - 3
api/static/script_msg.js

@@ -44,9 +44,7 @@ function openavatarModel() {
   avatarModal.show();
   avatarModal.show();
 }
 }
 
 
-$('.img_uploader').on('change', prepareUpload);
-
-// Grab the files and set them to our variable
+$('input[type=file]').on('change', prepareUpload);
 function prepareUpload(event) {
 function prepareUpload(event) {
   files = event.target.files;
   files = event.target.files;
   var data = new FormData();
   var data = new FormData();
@@ -322,6 +320,7 @@ function renderimgBlock(i) {
         imguploadlabel.classList.add('upload-btn');
         imguploadlabel.classList.add('upload-btn');
         imguploadlabel.textContent = '上傳檔案';
         imguploadlabel.textContent = '上傳檔案';
         imgInputs.appendChild(imguploadlabel);
         imgInputs.appendChild(imguploadlabel);
+        $('input[type=file]').on('change', prepareUpload);
 }
 }