|
@@ -165,7 +165,9 @@ async def user_profile(token: str = Depends(oauth2_scheme)):
|
|
|
|
|
|
user_id = get_user_id(token)
|
|
|
user_obj = first(db.query('SELECT * FROM users where id ="'+str(user_id)+'"'))
|
|
|
-
|
|
|
+ if user_obj['invite_code'] is None:
|
|
|
+ util.user.init_invite_code(user_id)
|
|
|
+ user_obj = first(db.query('SELECT * FROM users where id ="'+str(user_id)+'"'))
|
|
|
if user_obj is None:
|
|
|
raise HTTPException(
|
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
@@ -180,8 +182,11 @@ async def user_profile(token: str = Depends(oauth2_scheme)):
|
|
|
statement = 'SELECT * FROM history_input WHERE user_id='+str(user_obj['id'])+' ORDER BY timestamp DESC LIMIT 50'
|
|
|
for row in db.query(statement):
|
|
|
video_info_list.append({'id':row['id'],'title':row['name'],'duration':row['duration'],'url':row['link'],'time_stamp':row['timestamp'].strftime("%m/%d/%Y, %H:%M:%S")})
|
|
|
- dic_return = {'user_info':{'id':user_id,'userName':user_obj['username'],'email':user_obj['email'],'video_num':video_num,'total_sec':total_sec,'left_sec':user_obj['left_time']},'video_info':video_info_list}
|
|
|
+ dic_return = {'user_info':{'id':user_id,'userName':user_obj['username'],'email':user_obj['email']
|
|
|
+ ,'video_num':video_num,'total_sec':total_sec,'left_sec':user_obj['left_time'],'invite_code':user_obj['invite_code']}
|
|
|
+ ,'video_info':video_info_list}
|
|
|
str_return = json.dumps(dic_return)
|
|
|
+
|
|
|
return str_return
|
|
|
|
|
|
@app.post('/edit_profile')
|
|
@@ -281,12 +286,41 @@ async def register(request: util.models.register_req):
|
|
|
if type(id) is int:
|
|
|
code = str(time.time()).replace('.','')
|
|
|
db['register_veri_code'].insert({'code':code,'user_id':id})
|
|
|
- mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, request.email)
|
|
|
+ try:
|
|
|
+ mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, request.email)
|
|
|
+ return {'msg':{'eng':'Register success! Please check your mailbox to verify your email','zh':'註冊成功! 請至信箱收取驗證信'}}
|
|
|
+ except:
|
|
|
+ return {'msg':{'eng':'Invalid email address','zh':'無法寄送認證信!'}}
|
|
|
+ else :
|
|
|
+ return {'msg':{'eng':'error','zh':'error'}}
|
|
|
+ else:
|
|
|
+ return {'msg':{'eng':user_obj['username']+' is duplicated user name try another','zh':user_obj['username']+'重複,請更改'}}
|
|
|
+
|
|
|
+@app.post("/register_by_invite")
|
|
|
+async def register_by_invite(request: util.models.register_invite_req):
|
|
|
+ db_check()
|
|
|
+ user_obj = first(db.query('SELECT * FROM users where username ="'+str(request.username)+'"'))
|
|
|
+
|
|
|
+ if user_obj == None:
|
|
|
+ invcode = request.invite_code
|
|
|
+ sha = hashlib.sha256()
|
|
|
+ sha.update(str(time.time()).replace('.','').encode())
|
|
|
+ request.invite_code = sha.hexdigest()
|
|
|
+ id = user_register(request)
|
|
|
+ result = util.user.add_to_basic_role(id)
|
|
|
+ if type(id) is int:
|
|
|
+ code = str(time.time()).replace('.','')
|
|
|
+ db['register_veri_code'].insert({'code':code,'user_id':id})
|
|
|
+ try:
|
|
|
+ mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, request.email)
|
|
|
+ except:
|
|
|
+ return {'msg':{'eng':'Invalid email address','zh':'無法寄送認證信!'}}
|
|
|
+ util.user.add_time_by_invite(invcode)
|
|
|
return {'msg':{'eng':'Register success! Please login at previous page','zh':'註冊成功! 請回到上頁登入帳號'}}
|
|
|
else :
|
|
|
return {'msg':{'eng':'error','zh':'error'}}
|
|
|
else:
|
|
|
- return {'msg':{'eng':user.username+' is duplicated user name try another','zh':user.username+'重複,請更改'}}
|
|
|
+ return {'msg':{'eng':user_obj['username']+' is duplicated user name try another','zh':user_obj['username']+'重複,請更改'}}
|
|
|
|
|
|
@app.get('/logout')
|
|
|
def logout(request: Request, Authorize: AuthJWT = Depends()):
|
|
@@ -574,6 +608,43 @@ async def make_anchor_video_noAuth(req:util.models.request):
|
|
|
else:
|
|
|
return {'msg':{'eng':'Processing video requires a few minutes, please wait for notification','zh':'影片處理需要數分鐘,請等待通知'}}
|
|
|
return {'msg':'ok'}
|
|
|
+
|
|
|
+@app.post("/make_anchor_video_noAuth2" , response_class=JSONResponse)
|
|
|
+async def make_anchor_video_noAuth2(req:util.models.request):
|
|
|
+ db_check()
|
|
|
+ if len(req.image_urls) != len(req.text_content):
|
|
|
+ return {'msg':{'eng':'number of subtitles and images(videos) should be the same','zh':'副標題數量、圖片(影片)數量以及台詞數量必須一致'}}
|
|
|
+ for idx in range(len(req.image_urls)):
|
|
|
+ if 'http' not in req.image_urls[idx]:
|
|
|
+ req.image_urls[idx] = 'http://'+req.image_urls[idx]
|
|
|
+ if req.multiLang==0:
|
|
|
+ for txt in req.text_content:
|
|
|
+ if re.search('[a-zA-Z]', txt) !=None:
|
|
|
+ print('語言錯誤')
|
|
|
+ return {'msg':{'eng':'English is not allowed in subtitles','zh':'輸入字串不能包含英文字!'}}
|
|
|
+ if re.search(',', txt) !=None:
|
|
|
+ print('包含非法符號')
|
|
|
+ return {'msg':{'eng':'symbol "," is not allowede','zh':'輸入不能含有","符號'}}
|
|
|
+ name_hash = str(time.time()).replace('.','')
|
|
|
+ for imgu in req.image_urls:
|
|
|
+ try:
|
|
|
+ if get_url_type(imgu) =='video/mp4':
|
|
|
+ r=requests.get(imgu)
|
|
|
+ else:
|
|
|
+ im = Image.open(requests.get(imgu, stream=True).raw)
|
|
|
+ im= im.convert("RGB")
|
|
|
+ except:
|
|
|
+ return {'msg':{'eng':req.imgurl+'cant be proccessed','zh':"無法辨別圖片網址"+req.imgurl}}
|
|
|
+
|
|
|
+ video_id = save_history(req,name_hash,-1)
|
|
|
+ x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,video_id,-1))
|
|
|
+ x.start()
|
|
|
+
|
|
|
+ if first(db.query('SELECT COUNT(1) FROM video_queue'))['COUNT(1)'] >= 3:
|
|
|
+ return {'msg':{'eng':'There are many videos have been processing, please wait.','zh':'目前有多部影片處理中,煩請耐心等候'}}
|
|
|
+ else:
|
|
|
+ return {'msg':{'eng':'Processing video requires a few minutes, please wait for notification','zh':'影片處理需要數分鐘,請等待通知'}}
|
|
|
+ return {'msg':'ok'}
|
|
|
|
|
|
@app.post("/make_anchor_video_eng")
|
|
|
async def make_anchor_video_eng(req:util.models.request_eng,token: str = Depends(oauth2_scheme)):
|
|
@@ -939,10 +1010,15 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
|
|
|
shutil.copy(tmp_video_dir+top1['name_hash']+'.mp4',video_dest+top1['name_hash']+'.mp4')
|
|
|
os.remove(tmp_video_dir+top1['name_hash']+'.mp4')
|
|
|
vid_duration = VideoFileClip(video_dest+top1['name_hash']+'.mp4').duration
|
|
|
- user_obj = first(db.query('SELECT * FROM users where id ="'+str(user_id)+'"'))
|
|
|
- line_token = user_obj['line_token'] # aa
|
|
|
- left_time = user_obj['left_time']
|
|
|
- email = user_obj['email']
|
|
|
+ line_token=''
|
|
|
+ left_time=10000
|
|
|
+ email=''
|
|
|
+ if user_id!=-1:
|
|
|
+ user_obj = first(db.query('SELECT * FROM users where id ="'+str(user_id)+'"'))
|
|
|
+ line_token = user_obj['line_token'] # aa
|
|
|
+ left_time = user_obj['left_time']
|
|
|
+ email = user_obj['email']
|
|
|
+
|
|
|
print('left_time is '+str(left_time))
|
|
|
db.query('UPDATE history_input SET duration ='+str(vid_duration)+' WHERE id='+str(video_id)+';')
|
|
|
if left_time is None:
|
|
@@ -956,7 +1032,8 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
|
|
|
#notify_line_user(msg, line_token)
|
|
|
else:
|
|
|
left_time = left_time - vid_duration
|
|
|
- db.query('UPDATE users SET left_time ='+str(left_time)+' WHERE id='+str(user_id)+';')
|
|
|
+ if user_id != -1:
|
|
|
+ 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)
|
|
|
except Exception as e:
|