rename trending apis

This commit is contained in:
mein Name 2025-02-04 12:26:48 -05:00 committed by Henri Dickson
parent 281d1f8bf2
commit 1a97e5b7ef
3 changed files with 47 additions and 17 deletions

View file

@ -141,7 +141,7 @@ def fetch_item(request, url: str):
response={200: list[Gallery]},
summary="Trending items in catalog",
auth=None,
tags=["catalog"],
tags=["trending"],
deprecated=True,
)
def trending_items(request):
@ -167,66 +167,66 @@ def _get_trending(name):
@api.get(
"/catalog/trending/book/",
"/trending/book/",
response={200: list[ItemSchema]},
summary="Trending books in catalog",
auth=None,
tags=["catalog"],
tags=["trending"],
)
def trending_book(request):
return _get_trending("trending_book")
@api.get(
"/catalog/trending/movie/",
"/trending/movie/",
response={200: list[ItemSchema]},
summary="Trending movies in catalog",
auth=None,
tags=["catalog"],
tags=["trending"],
)
def trending_movie(request):
return _get_trending("trending_movie")
@api.get(
"/catalog/trending/tv/",
"/trending/tv/",
response={200: list[ItemSchema]},
summary="Trending tv in catalog",
auth=None,
tags=["catalog"],
tags=["trending"],
)
def trending_tv(request):
return _get_trending("trending_tv")
@api.get(
"/catalog/trending/music/",
"/trending/music/",
response={200: list[ItemSchema]},
summary="Trending music in catalog",
auth=None,
tags=["catalog"],
tags=["trending"],
)
def trending_music(request):
return _get_trending("trending_music")
@api.get(
"/catalog/trending/game/",
"/trending/game/",
response={200: list[ItemSchema]},
summary="Trending games in catalog",
auth=None,
tags=["catalog"],
tags=["trending"],
)
def trending_game(request):
return _get_trending("trending_game")
@api.get(
"/catalog/trending/podcast/",
"/trending/podcast/",
response={200: list[ItemSchema]},
summary="Trending podcasts in catalog",
auth=None,
tags=["catalog"],
tags=["trending"],
)
def trending_podcast(request):
return _get_trending("trending_podcast")

View file

@ -197,11 +197,11 @@ def collection_delete_item(request, collection_uuid: str, item_uuid: str):
@api.get(
"/catalog/trending/collection/",
"/trending/collection/",
response={200: list[CollectionSchema]},
summary="Trending collection in catalog",
summary="Trending collections",
auth=None,
tags=["catalog"],
tags=["trending"],
)
@decorate_view(cache_page(600))
def trending_collection(request):

View file

@ -1432,7 +1432,7 @@ class Post(models.Model):
"sensitive": self.sensitive,
"spoiler_text": self.summary or "",
"media_attachments": [
# attachment.to_mastodon_json() for attachment in self.attachments.all()
attachment.to_mastodon_json() for attachment in self.attachments.all()
],
"mentions": [
mention.to_mastodon_mention_json() for mention in self.mentions.all()
@ -1647,6 +1647,36 @@ class PostAttachment(models.Model):
return self.file.name.rsplit("/", 1)[-1]
return f"attachment ({self.mimetype})"
def to_mastodon_json(self):
type_ = "unknown"
if self.is_image():
type_ = "image"
elif self.is_video():
type_ = "video"
value = {
"id": str(self.pk),
"type": type_,
"url": self.full_url().absolute,
"preview_url": self.thumbnail_url().absolute,
"remote_url": None,
"meta": {
"focus": {
"x": self.focal_x or 0,
"y": self.focal_y or 0,
},
},
"description": self.name,
"blurhash": self.blurhash,
}
if self.width and self.height:
value["meta"]["original"] = {
"width": self.width,
"height": self.height,
"size": f"{self.width}x{self.height}",
"aspect": self.width / self.height,
}
return value
class EmojiQuerySet(models.QuerySet):
def usable(self, domain: Domain | None = None):