feat: crete kill-torrent

This commit is contained in:
Zamitto 2024-07-03 12:06:26 -03:00
parent 75c8f69e81
commit 0f5db4f34e
5 changed files with 36 additions and 8 deletions

View file

@ -33,23 +33,28 @@ class Handler(BaseHTTPRequestHandler):
status = downloader.get_download_status()
self.wfile.write(json.dumps(status).encode('utf-8'))
if self.path == "/healthcheck":
elif self.path == "/healthcheck":
self.send_response(200)
self.end_headers()
if self.path == "/process-list":
elif self.path == "/process-list":
if self.headers.get(self.rpc_password_header) != rpc_password:
self.send_response(401)
self.end_headers()
return
process_path = list(set([proc.info["exe"] for proc in psutil.process_iter(['exe'])]))
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(process_path).encode('utf-8'))
def do_POST(self):
global downloader
if self.path == "/action":
if self.headers.get(self.rpc_password_header) != rpc_password:
self.send_response(401)
@ -69,7 +74,10 @@ class Handler(BaseHTTPRequestHandler):
downloader.pause_download(data['game_id'])
elif data['action'] == 'cancel':
downloader.cancel_download(data['game_id'])
elif data['action'] == 'kill-torrent':
downloader.cancel_all_downloads()
downloader = None
self.send_response(200)
self.end_headers()