Add open_file function in server
This commit is contained in:
@@ -9,7 +9,6 @@ import pyautogui
|
|||||||
from PIL import ImageGrab, Image
|
from PIL import ImageGrab, Image
|
||||||
from flask import Flask, request, jsonify, send_file
|
from flask import Flask, request, jsonify, send_file
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
pyautogui.PAUSE = 0
|
pyautogui.PAUSE = 0
|
||||||
@@ -84,6 +83,7 @@ def get_platform():
|
|||||||
def get_cursor_position():
|
def get_cursor_position():
|
||||||
return pyautogui.position().x, pyautogui.position().y
|
return pyautogui.position().x, pyautogui.position().y
|
||||||
|
|
||||||
|
|
||||||
@app.route("/setup/download_file", methods=['POST'])
|
@app.route("/setup/download_file", methods=['POST'])
|
||||||
def download_file():
|
def download_file():
|
||||||
data = request.json
|
data = request.json
|
||||||
@@ -113,5 +113,26 @@ def download_file():
|
|||||||
|
|
||||||
return f"Failed to download {url}. No retries left. Error: {e}", 500
|
return f"Failed to download {url}. No retries left. Error: {e}", 500
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/setup/open_file", methods=['POST'])
|
||||||
|
def open_file():
|
||||||
|
data = request.json
|
||||||
|
path = data.get('path', None)
|
||||||
|
|
||||||
|
if not path:
|
||||||
|
return "Path not supplied!", 400
|
||||||
|
|
||||||
|
path = Path(path)
|
||||||
|
|
||||||
|
if not path.exists():
|
||||||
|
return f"File not found: {path}", 404
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.startfile(path)
|
||||||
|
return "File opened successfully"
|
||||||
|
except Exception as e:
|
||||||
|
return f"Failed to open {path}. Error: {e}", 500
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, host="0.0.0.0")
|
app.run(debug=True, host="0.0.0.0")
|
||||||
|
|||||||
Reference in New Issue
Block a user