v4.3 fix: serve audio as base64 JSON (gunicorn Range fix), path-aware export, faster project load

This commit is contained in:
Ashim Kumar
2026-06-12 18:40:12 +06:00
parent cc57204aff
commit 0a2f457476
3 changed files with 87 additions and 50 deletions

View File

@@ -222,7 +222,7 @@ def get_project(project_id):
@project_bp.route('/api/projects/<int:project_id>/audio/<int:block_id>', methods=['GET'])
@login_required
def get_block_audio(project_id, block_id):
"""Stream audio for a single block (v4.3: from file, with base64 fallback)."""
"""Return audio as base64 JSON (v4.3: read from file, no send_file/Range)."""
db = get_db()
cursor = db.cursor()
@@ -237,21 +237,23 @@ def get_block_audio(project_id, block_id):
if not row:
return jsonify({'error': 'Block not found'}), 404
# নতুন: ফাইল থেকে সরাসরি stream (Range request সাপোর্ট সহ)
if row['audio_path']:
abs_path = get_safe_abs_path(row['audio_path'])
if abs_path and os.path.exists(abs_path):
return send_file(abs_path, mimetype=f"audio/{row['audio_format'] or 'mp3'}",
conditional=True)
audio_format = clean_str(row['audio_format']) or 'mp3'
# পুরোনো: base64 JSON
# নতুন: ফাইল থেকে পড়ে base64 হিসেবে পাঠাই (gunicorn Range সমস্যা এড়াতে)
if row['audio_path']:
from media_storage import read_file_base64
b64 = read_file_base64(row['audio_path'])
if b64:
return jsonify({'audio_data': b64, 'audio_format': audio_format})
# পুরোনো: DB-তে থাকা base64 (মাইগ্রেট না হওয়া)
if row['audio_data']:
return jsonify({
'audio_data': clean_str(row['audio_data']),
'audio_format': clean_str(row['audio_format']) or 'mp3'
'audio_format': audio_format
})
return jsonify({'audio_data': '', 'audio_format': row['audio_format'] or 'mp3'})
return jsonify({'audio_data': '', 'audio_format': audio_format})
@project_bp.route('/api/projects/<int:project_id>', methods=['PUT'])