feat: Add torrent and SMB file deletion with confirmation and batch delete

This commit is contained in:
david
2026-08-17 10:26:07 -04:00
parent 504d3ef620
commit 057800f0b2
2 changed files with 339 additions and 8 deletions
+102 -3
View File
@@ -583,22 +583,25 @@ class RobustProxyHandler(http.server.SimpleHTTPRequestHandler):
else:
super().do_GET()
def do_POST(self):
# Database Cache Save APIs
# Database Cache Save/Delete APIs
if self.path == '/api/db/save':
self.handle_db_save()
elif self.path == '/api/db/batch-save':
self.handle_db_batch_save()
elif self.path == '/api/db/delete':
self.handle_db_delete()
# Stash Lookup APIs
elif self.path == '/api/stash/lookup':
self.handle_stash_lookup()
elif self.path == '/api/stash/batch-lookup':
self.handle_stash_batch_lookup()
# SMB API Moves
# SMB API Moves & Deletes
elif self.path == '/api/smb/move':
self.handle_smb_move()
elif self.path == '/api/smb/batch-move':
self.handle_smb_batch_move()
elif self.path == '/api/smb/delete':
self.handle_smb_delete()
elif self.path.startswith('/qb-proxy/'):
self.proxy_qb_request('POST')
elif self.path.startswith('/anthropic-proxy/'):
@@ -783,6 +786,43 @@ class RobustProxyHandler(http.server.SimpleHTTPRequestHandler):
self.end_headers()
self.wfile.write(json.dumps({"error": f"Failed batch saving to DB: {str(e)}"}).encode('utf-8'))
def handle_db_delete(self):
content_length = int(self.headers.get('Content-Length', 0))
post_data = self.rfile.read(content_length)
try:
payload = json.loads(post_data.decode('utf-8'))
item_key = payload.get('item_key')
item_keys = payload.get('item_keys', [])
if item_key and item_key not in item_keys:
item_keys.append(item_key)
if not item_keys:
self.send_response(400)
self.send_header('Content-Type', 'application/json')
self.send_cors_headers()
self.end_headers()
self.wfile.write(json.dumps({"error": "Missing item_key or item_keys"}).encode('utf-8'))
return
conn = get_db_connection()
cursor = conn.cursor()
for key in item_keys:
cursor.execute("DELETE FROM performer_analysis_cache WHERE item_key = ? OR name = ?", (key, key))
conn.commit()
conn.close()
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.send_cors_headers()
self.end_headers()
self.wfile.write(json.dumps({"success": True, "deleted_keys": item_keys}).encode('utf-8'))
except Exception as e:
self.send_response(500)
self.send_header('Content-Type', 'application/json')
self.send_cors_headers()
self.end_headers()
self.wfile.write(json.dumps({"error": f"Failed deleting from DB: {str(e)}"}).encode('utf-8'))
# ==================== Video Streaming Handlers (Range 206) ====================
def handle_stream_video(self):
head_only = False
@@ -1217,6 +1257,65 @@ class RobustProxyHandler(http.server.SimpleHTTPRequestHandler):
self.end_headers()
self.wfile.write(json.dumps({"error": f"Batch move failed: {str(e)}"}).encode('utf-8'))
def handle_smb_delete(self):
content_length = int(self.headers.get('Content-Length', 0))
post_data = self.rfile.read(content_length)
try:
payload = json.loads(post_data.decode('utf-8'))
path = payload.get('path')
paths = payload.get('paths', [])
if path and path not in paths:
paths.append(path)
if not paths:
self.send_response(400)
self.send_header('Content-Type', 'application/json')
self.send_cors_headers()
self.end_headers()
self.wfile.write(json.dumps({"error": "Missing path or paths"}).encode('utf-8'))
return
deleted = []
errors = []
conn = get_db_connection()
cursor = conn.cursor()
for p in paths:
try:
resolved = resolve_stream_video_path(p) or p
if os.path.exists(resolved):
if os.path.isdir(resolved):
shutil.rmtree(resolved)
else:
os.remove(resolved)
deleted.append(p)
cursor.execute("DELETE FROM performer_analysis_cache WHERE item_key = ? OR name = ?", (p, os.path.basename(p)))
else:
errors.append(f"File not found: {p}")
except Exception as del_err:
errors.append(f"Failed deleting {p}: {str(del_err)}")
conn.commit()
conn.close()
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.send_cors_headers()
self.end_headers()
self.wfile.write(json.dumps({
"success": len(deleted) > 0,
"deleted": deleted,
"deleted_count": len(deleted),
"errors": errors
}).encode('utf-8'))
except Exception as e:
self.send_response(500)
self.send_header('Content-Type', 'application/json')
self.send_cors_headers()
self.end_headers()
self.wfile.write(json.dumps({"error": f"Delete request failed: {str(e)}"}).encode('utf-8'))
# ==================== External API Proxies ====================
def proxy_external_api(self, upstream_base, proxy_prefix, method='POST'):
upstream_base = upstream_base.rstrip('/')