Added modifications
This commit is contained in:
@@ -728,6 +728,7 @@ def qb_torrents():
|
||||
"dlspeed": torrent.dlspeed,
|
||||
"upspeed": torrent.upspeed,
|
||||
"eta": torrent.eta,
|
||||
"save_path": torrent.save_path
|
||||
})
|
||||
return jsonify(torrents)
|
||||
except Exception as e:
|
||||
@@ -753,6 +754,10 @@ def qb_action():
|
||||
client.torrents_resume(torrent_hashes=hashes)
|
||||
elif action == 'delete':
|
||||
client.torrents_delete(delete_files=True, torrent_hashes=hashes)
|
||||
elif action == 'force_resume':
|
||||
client.torrents_force_resume(torrent_hashes=hashes)
|
||||
elif action == 'recheck':
|
||||
client.torrents_recheck(torrent_hashes=hashes)
|
||||
else:
|
||||
return jsonify({"error": "Invalid action."}), 400
|
||||
|
||||
@@ -760,5 +765,72 @@ def qb_action():
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/api/create_folder', methods=['POST'])
|
||||
def create_folder():
|
||||
data = request.get_json()
|
||||
path = data.get('path')
|
||||
folder_name = data.get('folder_name')
|
||||
|
||||
if not path or not folder_name:
|
||||
return jsonify({"error": "Path and folder name are required"}), 400
|
||||
|
||||
try:
|
||||
creds = get_smb_credentials(path)
|
||||
# Security check: Ensure destination is within the main VIDEO_PATH
|
||||
common_path = os.path.commonpath([os.path.normpath(VIDEO_PATH), os.path.normpath(path)])
|
||||
if common_path != os.path.normpath(VIDEO_PATH):
|
||||
raise ValueError("Creation path is outside the allowed base directory.")
|
||||
|
||||
new_folder_path = os.path.join(path, folder_name)
|
||||
smbclient.makedirs(new_folder_path, exist_ok=False, **creds)
|
||||
return jsonify({"success": True})
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/api/move_file', methods=['POST'])
|
||||
def move_file():
|
||||
data = request.get_json()
|
||||
source_path = data.get('source_path')
|
||||
dest_path = data.get('dest_path')
|
||||
|
||||
if not source_path or not dest_path:
|
||||
return jsonify({"error": "Source and destination paths are required"}), 400
|
||||
|
||||
try:
|
||||
creds = get_smb_credentials(source_path)
|
||||
# Ensure the destination directory exists
|
||||
if not smbclient.exists(dest_path, **creds):
|
||||
smbclient.makedirs(dest_path, exist_ok=True, **creds)
|
||||
|
||||
# Construct the full destination path including the filename
|
||||
filename = os.path.basename(source_path)
|
||||
full_dest_path = os.path.join(dest_path, filename)
|
||||
|
||||
smbclient.rename(source_path, full_dest_path, **creds)
|
||||
return jsonify({"success": True})
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/api/qb_set_location', methods=['POST'])
|
||||
def qb_set_location():
|
||||
try:
|
||||
client = get_qb_client()
|
||||
if not client:
|
||||
return jsonify({"error": "qBittorrent not configured."}), 400
|
||||
|
||||
data = request.get_json()
|
||||
hashes = data.get('hashes')
|
||||
location = data.get('location')
|
||||
|
||||
if not hashes or not location:
|
||||
return jsonify({"error": "Missing hashes or location."}), 400
|
||||
|
||||
client.torrents_set_location(torrent_hashes=hashes, location=location)
|
||||
return jsonify({"success": True})
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5000, host='0.0.0.0')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user