|
@@ -17,10 +17,12 @@ from pathlib import Path
|
|
|
from app.db.session import SessionLocal
|
|
|
import requests
|
|
|
import asyncio
|
|
|
+from discord_webhook import DiscordWebhook
|
|
|
|
|
|
BACKEND_ZIP_STORAGE = Path("/app").joinpath(settings.BACKEND_ZIP_STORAGE)
|
|
|
LOCAL_ZIP_STORAGE = Path("/").joinpath(settings.LOCAL_ZIP_STORAGE)
|
|
|
|
|
|
+Discord_URL = 'https://discord.com/api/webhooks/1348921334335541351/HU6tmFAfVcLdVcZjhy-qaqcbsoAhU_SdgvonujHi4S3HN-Rt9g9J2BIfi2yLslfc0ADb'
|
|
|
LINE_URL = 'https://notify-api.line.me/api/notify'
|
|
|
LINE_TOKEN = 'o8dqdVL2k8aiWO4jy3pawZamBu53bbjoSh2u0GJ7F0j'
|
|
|
|
|
@@ -134,17 +136,16 @@ def upload_plot(
|
|
|
video_data['lang'] = lang
|
|
|
background_tasks.add_task(wait_finish, video_data)
|
|
|
|
|
|
- headers = {
|
|
|
- 'Authorization': 'Bearer ' + LINE_TOKEN
|
|
|
- }
|
|
|
- data = {
|
|
|
- 'message':f'cloud-choozmo-com\n \
|
|
|
- Video\n \
|
|
|
- user: {current_user.id}\n \
|
|
|
- video: {video_data["id"]}\n \
|
|
|
- state: queuing'
|
|
|
- }
|
|
|
- data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
+ message = f'edm-choozmo-com\n \
|
|
|
+ Video\n \
|
|
|
+ user: {video_data["owner_id"]}\n \
|
|
|
+ membership: {video_data["membership_status"]}\n \
|
|
|
+ video: {video_data["id"]}\n \
|
|
|
+ state: start'
|
|
|
+
|
|
|
+ webhook = DiscordWebhook(url=Discord_URL, content=message)
|
|
|
+ response = webhook.execute()
|
|
|
+ print(f"Discord response: {response.status_code}")
|
|
|
return JSONResponse(return_msg, background=background_tasks)
|
|
|
|
|
|
async def wait_finish(video_data:dict):
|
|
@@ -166,47 +167,60 @@ async def wait_finish(video_data:dict):
|
|
|
db.close()
|
|
|
msg_data = f"{video_data['stored_filename']}:STARTED"
|
|
|
await publish(msg_data)
|
|
|
- headers = {
|
|
|
- 'Authorization': 'Bearer ' + LINE_TOKEN
|
|
|
- }
|
|
|
- data = {
|
|
|
- 'message':f'cloud-choozmo-com\n \
|
|
|
- Video\n \
|
|
|
- user: {video_data["owner_id"]}\n \
|
|
|
- membership: {video_data["membership_status"]}\n \
|
|
|
- video: {video_data["id"]}\n \
|
|
|
- state: start'
|
|
|
- }
|
|
|
- data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
+ message = f'edm-choozmo-com\n \
|
|
|
+ Video\n \
|
|
|
+ user: {video_data["owner_id"]}\n \
|
|
|
+ membership: {video_data["membership_status"]}\n \
|
|
|
+ video: {video_data["id"]}\n \
|
|
|
+ state: start'
|
|
|
+
|
|
|
+ webhook = DiscordWebhook(url=Discord_URL, content=message)
|
|
|
+ response = webhook.execute()
|
|
|
+ print(f"Discord response: {response.status_code}")
|
|
|
while True:
|
|
|
await asyncio.sleep(1)
|
|
|
if task.state != "STARTED":
|
|
|
break
|
|
|
|
|
|
if task.state == "SUCCESS":
|
|
|
- db = SessionLocal()
|
|
|
- video = db.query(models.Video).get(video_data['id'])
|
|
|
- user = db.query(models.User).get(video_data['owner_id'])
|
|
|
- video.progress_state = "SUCCESS"
|
|
|
- if time := task.result:
|
|
|
- user.available_time -= int(time) if int(time) <= user.available_time else 0
|
|
|
- video.length = int(time)
|
|
|
- db.commit()
|
|
|
- db.close()
|
|
|
- msg_data = f"{video_data['stored_filename']}:SUCCESS:{int(time)}"
|
|
|
- headers = {
|
|
|
- 'Authorization': 'Bearer ' + LINE_TOKEN
|
|
|
- }
|
|
|
- data = {
|
|
|
- 'message':f'cloud-choozmo-com\n \
|
|
|
+ if (time := task.result) and str(time).isdigit():
|
|
|
+ db = SessionLocal()
|
|
|
+ video = db.query(models.Video).get(video_data['id'])
|
|
|
+ user = db.query(models.User).get(video_data['owner_id'])
|
|
|
+ video.progress_state = "SUCCESS"
|
|
|
+ if time := task.result:
|
|
|
+ user.available_time -= int(time) if int(time) <= user.available_time else 0
|
|
|
+ video.length = int(time)
|
|
|
+ db.commit()
|
|
|
+ db.close()
|
|
|
+ msg_data = f"{video_data['stored_filename']}:SUCCESS:{int(time)}"
|
|
|
+ message = f'edm-choozmo-com\n \
|
|
|
Video\n \
|
|
|
user: {video_data["owner_id"]}\n \
|
|
|
membership: {video_data["membership_status"]}\n \
|
|
|
video: {video_data["id"]}\n \
|
|
|
state: success'
|
|
|
- }
|
|
|
- data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
|
|
|
+ webhook = DiscordWebhook(url=Discord_URL, content=message)
|
|
|
+ response = webhook.execute()
|
|
|
+ print(f"Discord response: {response.status_code}")
|
|
|
+ else:
|
|
|
+ db = SessionLocal()
|
|
|
+ video = db.query(models.Video).get(video_data['id'])
|
|
|
+ video.progress_state = "FAILURE"
|
|
|
+ db.commit()
|
|
|
+ db.close()
|
|
|
+ msg_data = f"{video_data['stored_filename']}:FAILURE"
|
|
|
+
|
|
|
+ message = f'edm-choozmo-com\n \
|
|
|
+ Video\n \
|
|
|
+ user: {video_data["owner_id"]}\n \
|
|
|
+ membership: {video_data["membership_status"]}\n \
|
|
|
+ video: {video_data["id"]}\n \
|
|
|
+ state: failure:{task.result}'
|
|
|
+ webhook = DiscordWebhook(url=Discord_URL, content=message)
|
|
|
+ response = webhook.execute()
|
|
|
+ print(f"Discord response: {response.status_code}")
|
|
|
elif task.state == "FAILURE":
|
|
|
db = SessionLocal()
|
|
|
video = db.query(models.Video).get(video_data['id'])
|
|
@@ -215,18 +229,16 @@ async def wait_finish(video_data:dict):
|
|
|
db.close()
|
|
|
msg_data = f"{video_data['stored_filename']}:FAILURE"
|
|
|
|
|
|
- headers = {
|
|
|
- 'Authorization': 'Bearer ' + LINE_TOKEN
|
|
|
- }
|
|
|
- data = {
|
|
|
- 'message':f'cloud-choozmo-com\n \
|
|
|
- Video\n \
|
|
|
- user: {video_data["owner_id"]}\n \
|
|
|
- membership: {video_data["membership_status"]}\n \
|
|
|
- video: {video_data["id"]}\n \
|
|
|
- state: failure'
|
|
|
- }
|
|
|
- data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
+ message = f'edm-choozmo-com\n \
|
|
|
+ Video\n \
|
|
|
+ user: {video_data["owner_id"]}\n \
|
|
|
+ membership: {video_data["membership_status"]}\n \
|
|
|
+ video: {video_data["id"]}\n \
|
|
|
+ state: failure:{task.result}'
|
|
|
+
|
|
|
+ webhook = DiscordWebhook(url=Discord_URL, content=message)
|
|
|
+ response = webhook.execute()
|
|
|
+ print(f"Discord response: {response.status_code}")
|
|
|
|
|
|
await publish(msg_data)
|
|
|
|