image timestamp fix

This commit is contained in:
Shiro-Nek0
2026-02-27 00:16:43 -03:00
parent 600df52b04
commit 4779452acd
2 changed files with 12 additions and 11 deletions

11
app.py
View File

@@ -6,6 +6,7 @@ from flask_socketio import SocketIO, emit
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
from werkzeug.security import generate_password_hash, check_password_hash
import mimetypes
import time
app = Flask(__name__)
app.config['SECRET_KEY'] = 'seki_super_secret_key_99' # Change this if you have actual friends
@@ -250,22 +251,16 @@ def bulk_delete():
def upload_image():
if 'image' not in request.files or 'barcode' not in request.form:
return jsonify({"error": "Missing data"}), 400
file = request.files['image']
barcode = request.form['barcode']
if file.filename == '' or not barcode:
return jsonify({"error": "Invalid data"}), 400
# Detect extension
ext = mimetypes.guess_extension(file.mimetype) or '.jpg'
filename = f"{barcode}{ext}"
filepath = os.path.join(CACHE_DIR, filename)
file.save(filepath)
# Return the relative path for the frontend
return jsonify({"status": "success", "image_url": f"/static/cache/{filename}"}), 200
timestamp = int(time.time())
return jsonify({"status": "success", "image_url": f"/static/cache/{filename}?t={timestamp}"}), 200
if __name__ == '__main__':
init_db()

View File

@@ -603,16 +603,22 @@
updateForm(d.barcode, d.name || '', '', d.image || '', 'Crear: ' + d.barcode);
});
// Replace your existing updateForm function with this one
function updateForm(b, n, p, i, t) {
dismissPrompt();
document.getElementById('form-barcode').value = b;
document.getElementById('form-name').value = n;
document.getElementById('form-price').value = (p !== undefined && p !== null) ? p : '';
// Add a timestamp to the URL if it's a local cache image
let displayImg = i || './static/placeholder.png';
if (displayImg.includes('/static/cache/')) {
displayImg += (displayImg.includes('?') ? '&' : '?') + 't=' + Date.now();
}
document.getElementById('form-image').value = i || '';
document.getElementById('form-title').innerText = t;
// ADD THESE LINES TO UPDATE THE PREVIEW CARD
document.getElementById('display-img').src = i || './static/placeholder.png';
document.getElementById('display-img').src = displayImg;
document.getElementById('display-name').innerText = n || 'Producto Nuevo';
document.getElementById('display-price').innerText = clp.format(p || 0);
document.getElementById('display-barcode').innerText = b;