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

@@ -194,7 +194,7 @@ def get_published_book(project_id):
@public_bp.route('/api/public/books/<int:project_id>/audio/<int:block_id>', methods=['GET'])
def get_public_block_audio(project_id, block_id):
"""Stream audio file for a published book block (v4.3)."""
"""Return audio as base64 JSON for a published book block (v4.3)."""
db = get_db()
cursor = db.cursor()
@@ -214,16 +214,18 @@ def get_public_block_audio(project_id, block_id):
if not row:
return jsonify({'error': 'Block not found'}), 404
audio_format = clean_str(row['audio_format']) or 'mp3'
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)
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})
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})