Files
J621/backend/apps/core/views.py
T
JakeBreath 6962e483fc Async Download to Library with progress; Download to client
Backend:
- DownloadTask model + background thread runner: streams the file with
  progress (%, bytes, speed) and a cancel flag, then indexes it, names it
  J-<id>.<ext> and applies the e621 metadata
- DownloadTaskViewSet (create/retrieve/cancel) replaces the synchronous
  endpoint; the status footer's worker counts now reflect download jobs
- Client download proxy (/api/online/file/) streams an e621 original to
  the browser with Content-Disposition: attachment, restricted to the
  configured e621 CDN hosts so it cannot be used as an open proxy

Frontend:
- Online detail: progress bar with percentage, transferred size, speed
  and cancel while downloading; success links to the new J-ID
- New 'Download to client' button available to everyone (guests too)
2026-09-17 12:06:15 -05:00

43 lines
1.3 KiB
Python

import time
from django.conf import settings
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from .system_info import get_os_info
def _worker_counts():
"""Active/queued background jobs (download tasks for now)."""
from apps.library.models import DownloadTask
active = DownloadTask.objects.filter(
status=DownloadTask.STATUS_DOWNLOADING
).count()
queued = DownloadTask.objects.filter(
status=DownloadTask.STATUS_PENDING
).count()
return {"active": active, "queued": queued}
class StatusView(APIView):
"""Runtime status used by the SPA shell (storage line, status pill, footer)."""
permission_classes = [AllowAny]
def get(self, request):
started = getattr(request, "start_time", time.perf_counter())
payload = {
"app": "J621",
"env": settings.APP_ENV,
"git_hash": settings.GIT_COMMIT_HASH,
"version": settings.APP_VERSION,
"os": get_os_info(),
"watched_folder": settings.WATCHED_FOLDER,
"e621_time_ms": None, # no e621 calls in the backend yet
"workers": _worker_counts(),
}
payload["server_time_ms"] = round((time.perf_counter() - started) * 1000, 1)
return Response(payload)