1
0

vault backup: 2025-12-26 02:09:22
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s

This commit is contained in:
2025-12-26 02:09:22 +01:00
parent 3fddadfe50
commit 50366b9b9c
288 changed files with 58893 additions and 750 deletions

View File

@@ -0,0 +1,48 @@
import json
from django.http import JsonResponse
from django.views.decorators.http import require_http_methods
from django.shortcuts import get_object_or_404
from file.models import File
@require_http_methods(["GET"])
def get_file_content(request, file_id):
"""Get the text content of a specific file."""
file_obj = get_object_or_404(File, id=file_id, user=request.quiz_user)
return JsonResponse({
'id': file_obj.id,
'name': file_obj.name,
'content': file_obj.text
})
@require_http_methods(["POST"])
def save_file_content(request, file_id):
"""Save updated text content to a file."""
file_obj = get_object_or_404(File, id=file_id, user=request.quiz_user)
try:
data = json.loads(request.body)
new_content = data.get('content', '')
file_obj.text = new_content
file_obj.save()
return JsonResponse({'success': True})
except (json.JSONDecodeError, KeyError):
return JsonResponse({'success': False, 'error': 'Invalid data'}, status=400)
from django.http import FileResponse
def serve_pdf_api(request, file_id):
"""Serve the raw PDF file for viewing."""
file_obj = get_object_or_404(File, id=file_id, user=request.quiz_user)
if not file_obj.mime_type == 'application/pdf' or not file_obj.file_content:
return JsonResponse({'error': 'Not a PDF file'}, status=400)
response = FileResponse(
file_obj.file_content.open('rb'),
content_type='application/pdf'
)
# Add CORS headers to allow CDN-hosted PDF.js viewer to fetch the PDF
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Methods'] = 'GET, OPTIONS'
response['Access-Control-Allow-Headers'] = 'Content-Type'
return response