Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Exempt API v1 from CSRF and format transcripts with user templates
Murtaza Nasir1ec19614487d
diff --git a/src/api/api_v1.py b/src/api/api_v1.pyindex 07208dbf..ae952025 100644--- a/src/api/api_v1.py+++ b/src/api/api_v1.py@@ -27,6 +27,7 @@ from src.models import Recording, User, Tag, RecordingTag, Speaker, Eventfrom src.models.processing_job import ProcessingJobfrom src.models.token_usage import TokenUsagefrom src.services.token_tracking import TokenTracker+from src.file_exporter import format_transcription_with_template# Create blueprint with /api/v1 prefixapi_v1_bp = Blueprint('api_v1', __name__, url_prefix='/api/v1')@@ -639,7 +640,10 @@ def get_recording(recording_id):# Include large text fields based on paramsif format_type != 'minimal':if 'transcription' in include_fields:- response['transcription'] = recording.transcription+ # Format transcription using user's default template+ response['transcription'] = format_transcription_with_template(+ recording.transcription, current_user+ ) if recording.transcription else Noneif 'summary' in include_fields:response['summary'] = recording.summaryif 'notes' in include_fields:@@ -688,22 +692,12 @@ def get_transcript(recording_id):})elif format_type == 'text':- try:- segments = json.loads(recording.transcription)- text_lines = []- for seg in segments:- speaker = seg.get('speaker', 'Unknown')- text = seg.get('sentence') or seg.get('text', '')- text_lines.append(f"{speaker}: {text}")- return jsonify({- 'format': 'text',- 'content': '\n\n'.join(text_lines)- })- except (json.JSONDecodeError, TypeError):- return jsonify({- 'format': 'text',- 'content': recording.transcription- })+ # Use user's default template for text format+ formatted = format_transcription_with_template(recording.transcription, current_user)+ return jsonify({+ 'format': 'text',+ 'content': formatted+ })elif format_type in ['srt', 'vtt']:try:diff --git a/src/app.py b/src/app.pyindex f35fe5d9..9bdc9c36 100644--- a/src/app.py+++ b/src/app.py@@ -588,6 +588,7 @@ app.register_blueprint(events_bp)app.register_blueprint(system_bp)app.register_blueprint(push_bp)app.register_blueprint(api_v1_bp)+csrf.exempt(api_v1_bp) # API v1 uses token auth, not CSRF# File monitor and scheduler initialization functions below