mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-12 14:26:54 +00:00
forgot ctrl+z existed
This commit is contained in:
@@ -3,9 +3,8 @@ import os
|
|||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
import time
|
import time
|
||||||
import shutil
|
import threading
|
||||||
import logging
|
import logging
|
||||||
import zipfile
|
|
||||||
from main import get_symbol_address, patch_address, copy_file_to_src, zip_src_files
|
from main import get_symbol_address, patch_address, copy_file_to_src, zip_src_files
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -44,21 +43,8 @@ handler = logger.handlers[0]
|
|||||||
handler.setFormatter(ColoredFormatter('%(asctime)s - %(levelname)s - %(message)s'))
|
handler.setFormatter(ColoredFormatter('%(asctime)s - %(levelname)s - %(message)s'))
|
||||||
|
|
||||||
def save_patch_info(permalink_id, file_path):
|
def save_patch_info(permalink_id, file_path):
|
||||||
patch_info = {
|
# Dummy function to maintain logs
|
||||||
'permalink_id': permalink_id,
|
logger.info(f"Patch info saved for permalink_id: {permalink_id}, file_path: {file_path}")
|
||||||
'file_path': file_path,
|
|
||||||
'timestamp': time.time()
|
|
||||||
}
|
|
||||||
if os.path.exists(PATCHES_JSON):
|
|
||||||
with open(PATCHES_JSON, 'r') as f:
|
|
||||||
patches = json.load(f)
|
|
||||||
else:
|
|
||||||
patches = []
|
|
||||||
|
|
||||||
patches.append(patch_info)
|
|
||||||
|
|
||||||
with open(PATCHES_JSON, 'w') as f:
|
|
||||||
json.dump(patches, f, indent=4)
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
@@ -282,30 +268,22 @@ def patch():
|
|||||||
logger.error(f"Error patching file: {str(e)}")
|
logger.error(f"Error patching file: {str(e)}")
|
||||||
return jsonify({"error": f"Error patching file: {str(e)}"}), 500
|
return jsonify({"error": f"Error patching file: {str(e)}"}), 500
|
||||||
|
|
||||||
# Create a zip file containing the patched .so
|
# Create permalink
|
||||||
try:
|
permalink_id = str(uuid.uuid4())
|
||||||
zip_filename = f"patched_{library_name}.zip"
|
PATCHED_LIBRARIES[permalink_id] = {
|
||||||
zip_path = os.path.join('uploads', zip_filename)
|
'file_path': file_path,
|
||||||
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
'library_name': library_name,
|
||||||
zipf.write(file_path, arcname=library_name)
|
'timestamp': time.time()
|
||||||
except Exception as e:
|
}
|
||||||
logger.error(f"Error creating zip file: {str(e)}")
|
|
||||||
return jsonify({"error": f"Error creating zip file: {str(e)}"}), 500
|
|
||||||
|
|
||||||
# Send the zip file
|
# Save patch info
|
||||||
try:
|
save_patch_info(permalink_id, file_path)
|
||||||
return send_file(
|
|
||||||
zip_path,
|
# Schedule deletion
|
||||||
mimetype='application/zip',
|
threading.Timer(PERMALINK_EXPIRY, delete_expired_permalink, args=[permalink_id]).start()
|
||||||
as_attachment=True,
|
logger.info(f"Permalink {permalink_id} created, will expire in {PERMALINK_EXPIRY} seconds")
|
||||||
download_name=zip_filename
|
|
||||||
)
|
return jsonify({'permalink': f'/download/{permalink_id}'})
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error sending zip file: {str(e)}")
|
|
||||||
return jsonify({"error": f"Error sending zip file: {str(e)}"}), 500
|
|
||||||
finally:
|
|
||||||
os.remove(file_path)
|
|
||||||
os.remove(zip_path)
|
|
||||||
|
|
||||||
@app.route('/api', methods=['POST'])
|
@app.route('/api', methods=['POST'])
|
||||||
def api():
|
def api():
|
||||||
@@ -336,29 +314,37 @@ def api():
|
|||||||
logger.error(f"Error patching file: {str(e)}")
|
logger.error(f"Error patching file: {str(e)}")
|
||||||
return jsonify({"error": f"Error patching file: {str(e)}"}), 500
|
return jsonify({"error": f"Error patching file: {str(e)}"}), 500
|
||||||
|
|
||||||
# Send the patched .so file directly
|
# Log patch info
|
||||||
patched_filename = f"patched_{library_name}"
|
permalink_id = str(uuid.uuid4())
|
||||||
patched_file_path = os.path.join('uploads', patched_filename)
|
save_patch_info(permalink_id, file_path)
|
||||||
shutil.copy(file_path, patched_file_path)
|
|
||||||
|
# Return the patched file directly
|
||||||
|
try:
|
||||||
|
return send_file(file_path, as_attachment=True, attachment_filename=library_name)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error sending file: {str(e)}")
|
||||||
|
return jsonify({"error": f"Error sending file: {str(e)}"}), 500
|
||||||
|
|
||||||
|
@app.route('/download/<permalink_id>', methods=['GET'])
|
||||||
|
def download(permalink_id):
|
||||||
|
if permalink_id not in PATCHED_LIBRARIES:
|
||||||
|
return "Permalink expired or invalid", 404
|
||||||
|
|
||||||
|
file_path = PATCHED_LIBRARIES[permalink_id]['file_path']
|
||||||
|
library_name = PATCHED_LIBRARIES[permalink_id]['library_name']
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
return "File not found", 404
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = make_response(send_file(
|
copy_file_to_src(file_path, library_name)
|
||||||
patched_file_path,
|
zip_src_files()
|
||||||
mimetype='application/octet-stream',
|
|
||||||
as_attachment=True,
|
|
||||||
download_name=patched_filename
|
|
||||||
))
|
|
||||||
os.remove(file_path)
|
|
||||||
os.remove(patched_file_path)
|
|
||||||
return resp
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error sending patched file: {str(e)}")
|
logger.error(f"Error preparing download: {str(e)}")
|
||||||
|
return f"Error preparing download: {str(e)}", 500
|
||||||
|
|
||||||
os.remove(file_path)
|
resp = make_response(send_file('btl2capfix.zip', as_attachment=True))
|
||||||
os.remove(patched_file_path)
|
resp.headers['Content-Disposition'] = f'attachment; filename=btl2capfix.zip'
|
||||||
|
return resp
|
||||||
return jsonify({"error": f"Error sending patched file: {str(e)}"}), 500
|
|
||||||
|
|
||||||
def delete_expired_permalink(permalink_id):
|
def delete_expired_permalink(permalink_id):
|
||||||
if permalink_id in PATCHED_LIBRARIES:
|
if permalink_id in PATCHED_LIBRARIES:
|
||||||
|
|||||||
Reference in New Issue
Block a user