-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
69 lines (53 loc) · 1.96 KB
/
server.py
File metadata and controls
69 lines (53 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, jsonify, request
import os
import sys
import monitor
import crop
N8N_DATA_DIR = "/Users/nino/Repository/n8n/data"
app = Flask(__name__)
@app.route('/crop', methods=['POST'])
def trigger_crop():
DEFAULT_CAM = '260:180:0:298'
DEFAULT_SCREEN = '323:442:249:26'
try:
data = request.json
if not data:
return jsonify({"status": "error", "message": "No JSON payload provided"}), 400
folder = data.get('folder')
if not folder:
return jsonify({"status": "error", "message": "Missing 'folder' in payload"}), 400
target_dir = os.path.join(N8N_DATA_DIR, folder)
if not os.path.exists(target_dir):
return jsonify({"status": "error", "message": f"Target directory {target_dir} does not exist"}), 400
crop.process(
target_dir,
data.get('cam_crop', DEFAULT_CAM),
data.get('screen_crop', DEFAULT_SCREEN)
)
return jsonify({
"status": "success",
"message": "Crop triggered in background.",
"root_dir": target_dir
}), 200
except Exception as e:
return jsonify({"status": "error", "message": str(e)}), 500
@app.route('/monitor', methods=['POST'])
def trigger_monitor():
# Calling get_new_video with defaults (update_memory=True) triggers the download logic internal to monitor.py
result = monitor.get_new_video()
if not result:
return jsonify({
"status": "success",
"message": "No new content found."
}), 200
return jsonify({
"status": "success",
"message": "Monitor check completed.",
"result": result
}), 200
@app.route('/health', methods=['GET'])
def health():
return jsonify({"status": "ok"}), 200
if __name__ == '__main__':
# Run on 0.0.0.0 to be accessible if needed, port 5000 default
app.run(debug=True, host='0.0.0.0', port=8000)