setup controller
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
import requests
|
||||
@@ -83,6 +84,34 @@ def get_platform():
|
||||
def get_cursor_position():
|
||||
return pyautogui.position().x, pyautogui.position().y
|
||||
|
||||
@app.route("/setup/download_file", methods=['POST'])
|
||||
def download_file():
|
||||
data = request.json
|
||||
url = data.get('url', None)
|
||||
path = data.get('path', None)
|
||||
|
||||
if not url or not path:
|
||||
return "Path or URL not supplied!", 400
|
||||
|
||||
path = Path(path)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
max_retries = 3
|
||||
for i in range(max_retries):
|
||||
try:
|
||||
response = requests.get(url, stream=True)
|
||||
response.raise_for_status()
|
||||
|
||||
with open(path, 'wb') as f:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
if chunk:
|
||||
f.write(chunk)
|
||||
return "File downloaded successfully"
|
||||
|
||||
except requests.RequestException as e:
|
||||
print(f"Failed to download {url}. Retrying... ({max_retries - i - 1} attempts left)")
|
||||
|
||||
return f"Failed to download {url}. No retries left. Error: {e}", 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host="0.0.0.0")
|
||||
|
||||
Reference in New Issue
Block a user