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,31 @@
from django.http import JsonResponse
from django.views.decorators.http import require_http_methods
from file.models import File
@require_http_methods(["GET"])
def get_file_tree(request):
"""Return the hierarchical file tree for the user."""
files = File.objects.filter(user=request.quiz_user).select_related('parent').order_by('name')
# Create a mapping of id -> item
item_map = {}
for f in files:
item_map[f.id] = {
'id': f.id,
'name': f.name,
'path': f.path,
'type': 'folder' if f.mime_type == 'application/x-folder' else 'file',
'mime_type': f.mime_type,
'children': [],
'content': f.text if f.mime_type.startswith('text/') else None
}
root_items = []
for f in files:
item = item_map[f.id]
if f.parent_id:
if f.parent_id in item_map:
item_map[f.parent_id]['children'].append(item)
else:
root_items.append(item)
return JsonResponse(root_items, safe=False)