Keep e621 metadata on downloaded posts; clear up account roles
Roles: - JakeBreathild is now staff + superuser (the real account); the 'jake' smoke-test account was demoted to a regular user - /me exposes is_superuser and the account page shows an admin badge e621 metadata: - MediaItem gains e621_post_id and e621_data (trimmed post payload: tags by category, rating, score, favourites, comments, sources, description, pools, relationships, file info, uploader) - Download to Library accepts the post payload from the SPA and stores it; the item's custom rating is seeded from the e621 rating when empty - Library detail shows an e621 metadata card: link to the in-app post, score/favourites/comments, taxonomy-coloured tags, DText description, sources and pools; grid cards get an e621 badge and fall back to the e621 rating for their colour (display_rating) - Guest visibility now also considers e621 tags, so downloaded explicit content is hidden from anonymous visitors
This commit is contained in:
@@ -223,6 +223,7 @@ class DownloadToLibraryView(APIView):
|
||||
url = str(request.data.get("url") or "").strip()
|
||||
post_id = request.data.get("post_id")
|
||||
filename = str(request.data.get("filename") or "").strip()
|
||||
post_payload = request.data.get("post")
|
||||
if not url.startswith(("http://", "https://")):
|
||||
return Response(
|
||||
{"detail": "A valid file URL is required."},
|
||||
@@ -244,9 +245,26 @@ class DownloadToLibraryView(APIView):
|
||||
{"detail": f"Download failed: {exc}"},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
update_fields = []
|
||||
if item.uploaded_by_id is None:
|
||||
item.uploaded_by = request.user
|
||||
item.save(update_fields=["uploaded_by", "updated_at"])
|
||||
update_fields.append("uploaded_by")
|
||||
|
||||
trimmed = services.trim_e621_post(post_payload)
|
||||
if trimmed is not None:
|
||||
if trimmed.get("id") is not None:
|
||||
item.e621_post_id = int(trimmed["id"])
|
||||
elif post_id and str(post_id).isdigit():
|
||||
item.e621_post_id = int(post_id)
|
||||
item.e621_data = trimmed
|
||||
update_fields += ["e621_post_id", "e621_data"]
|
||||
if not item.rating and trimmed.get("rating") in {"s", "q", "e"}:
|
||||
item.rating = trimmed["rating"]
|
||||
update_fields.append("rating")
|
||||
|
||||
if update_fields:
|
||||
item.save(update_fields=update_fields + ["updated_at"])
|
||||
return Response(
|
||||
MediaItemSerializer(item, context={"request": request}).data,
|
||||
status=status.HTTP_201_CREATED,
|
||||
|
||||
Reference in New Issue
Block a user