image export like db
This commit is contained in:
28
app.py
28
app.py
@@ -10,6 +10,9 @@ import mimetypes
|
|||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import zipfile
|
||||||
|
import io
|
||||||
|
|
||||||
# from dotenv import load_dotenv
|
# from dotenv import load_dotenv
|
||||||
|
|
||||||
# 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 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
|
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'])
|
# @app.route('/process_payment', methods=['POST'])
|
||||||
# @login_required
|
# @login_required
|
||||||
# def process_payment():
|
# def process_payment():
|
||||||
|
|||||||
@@ -37,6 +37,11 @@
|
|||||||
<i class="bi bi-database-down me-2"></i>Descargar DB
|
<i class="bi bi-database-down me-2"></i>Descargar DB
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item" href="/export/images">
|
||||||
|
<i class="bi bi-images me-2"></i>Descargar Imágenes
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li><hr class="dropdown-divider"></li>
|
<li><hr class="dropdown-divider"></li>
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item text-danger" href="/logout">
|
<a class="dropdown-item text-danger" href="/logout">
|
||||||
|
|||||||
Reference in New Issue
Block a user