image export like db

This commit is contained in:
2026-03-11 15:59:50 -03:00
parent 78d48db9ea
commit 77fc5920a2
2 changed files with 33 additions and 0 deletions

28
app.py
View File

@@ -10,6 +10,9 @@ import mimetypes
import time
import uuid
from datetime import datetime
import zipfile
import io
# from dotenv import load_dotenv
# load_dotenv()
@@ -532,6 +535,31 @@ def export_db():
return send_file(DB_FILE, as_attachment=True, download_name=f"SekiPOS_Backup_{datetime.now().strftime('%Y%m%d')}.db", mimetype='application/x-sqlite3')
return "Error: Database file not found", 404
@app.route('/export/images')
@login_required
def export_images():
if not os.path.exists(CACHE_DIR) or not os.listdir(CACHE_DIR):
return "No images found to export", 404
# Create an in-memory byte stream to hold the zip data
memory_file = io.BytesIO()
with zipfile.ZipFile(memory_file, 'w', zipfile.ZIP_DEFLATED) as zf:
for root, dirs, files in os.walk(CACHE_DIR):
for file in files:
file_path = os.path.join(root, file)
# Store files using their names only to avoid nesting inside the zip
zf.write(file_path, arcname=file)
memory_file.seek(0)
return send_file(
memory_file,
mimetype='application/zip',
as_attachment=True,
download_name=f"SekiPOS_Images_{datetime.now().strftime('%Y%m%d')}.zip"
)
# @app.route('/process_payment', methods=['POST'])
# @login_required
# def process_payment():