- MediaItem gains e621_match_status (unknown/matched/not_found/deleted) and e621_checked_at, backfilled for existing matched items. - Server-side e621 client (apps/library/e621.py) using the user's stored credentials, throttled to 2 req/s, with typed errors. - Matching service: MD5 lookup, manual post linking (flags MD5 mismatches), unlink, metadata refresh, deleted-post detection. - Detail actions POST /api/files/J-x/match/ and /unlink/ (uploader or staff only). - Background library scans: MatchTask + /api/matches/ with missing/all scopes, progress polling, cancel and stale-task reaping; the scan counts toward the footer's Active Workers. Same pass available as manage.py match_e621 for cron. - Library gains not_found/deleted status filters; the detail page adds an e621 match card (check / link by post ID / unlink) and the metadata card warns when a post was deleted on e621.
43 lines
1.5 KiB
Python
43 lines
1.5 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 (downloads and e621 match scans)."""
|
|
from apps.library.models import DownloadTask, MatchTask
|
|
|
|
active = DownloadTask.objects.filter(
|
|
status=DownloadTask.STATUS_DOWNLOADING
|
|
).count() + MatchTask.objects.filter(status=MatchTask.STATUS_RUNNING).count()
|
|
queued = DownloadTask.objects.filter(
|
|
status=DownloadTask.STATUS_PENDING
|
|
).count() + MatchTask.objects.filter(status=MatchTask.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, # e621 latency is measured client-side
|
|
"workers": _worker_counts(),
|
|
}
|
|
payload["server_time_ms"] = round((time.perf_counter() - started) * 1000, 1)
|
|
return Response(payload)
|