mirror of
https://github.com/jointakahe/takahe.git
synced 2024-12-22 21:46:27 +00:00
add type to api url path
This commit is contained in:
parent
024b01a144
commit
c41e38e809
7 changed files with 72 additions and 70 deletions
74
api/urls.py
74
api/urls.py
|
@ -32,20 +32,20 @@ urlpatterns = [
|
|||
path("v1/accounts/familiar_followers", accounts.familiar_followers),
|
||||
path("v1/accounts/search", accounts.accounts_search),
|
||||
path("v1/accounts/lookup", accounts.lookup),
|
||||
path("v1/accounts/<id>", accounts.account),
|
||||
path("v1/accounts/<id>/statuses", accounts.account_statuses),
|
||||
path("v1/accounts/<id>/follow", accounts.account_follow),
|
||||
path("v1/accounts/<id>/unfollow", accounts.account_unfollow),
|
||||
path("v1/accounts/<id>/block", accounts.account_block),
|
||||
path("v1/accounts/<id>/unblock", accounts.account_unblock),
|
||||
path("v1/accounts/<id>/mute", accounts.account_mute),
|
||||
path("v1/accounts/<id>/unmute", accounts.account_unmute),
|
||||
path("v1/accounts/<id>/following", accounts.account_following),
|
||||
path("v1/accounts/<id>/followers", accounts.account_followers),
|
||||
path("v1/accounts/<id>/featured_tags", accounts.account_featured_tags),
|
||||
path("v1/accounts/<int:id>", accounts.account),
|
||||
path("v1/accounts/<int:id>/statuses", accounts.account_statuses),
|
||||
path("v1/accounts/<int:id>/follow", accounts.account_follow),
|
||||
path("v1/accounts/<int:id>/unfollow", accounts.account_unfollow),
|
||||
path("v1/accounts/<int:id>/block", accounts.account_block),
|
||||
path("v1/accounts/<int:id>/unblock", accounts.account_unblock),
|
||||
path("v1/accounts/<int:id>/mute", accounts.account_mute),
|
||||
path("v1/accounts/<int:id>/unmute", accounts.account_unmute),
|
||||
path("v1/accounts/<int:id>/following", accounts.account_following),
|
||||
path("v1/accounts/<int:id>/followers", accounts.account_followers),
|
||||
path("v1/accounts/<int:id>/featured_tags", accounts.account_featured_tags),
|
||||
# Announcements
|
||||
path("v1/announcements", announcements.announcement_list),
|
||||
path("v1/announcements/<pk>/dismiss", announcements.announcement_dismiss),
|
||||
path("v1/announcements/<int:pk>/dismiss", announcements.announcement_dismiss),
|
||||
# Apps
|
||||
path("v1/apps", apps.add_app),
|
||||
path("v1/apps/verify_credentials", apps.verify_credentials),
|
||||
|
@ -58,8 +58,10 @@ urlpatterns = [
|
|||
path("v1/filters", filters.list_filters),
|
||||
# Follow requests
|
||||
path("v1/follow_requests", follow_requests.follow_requests),
|
||||
path("v1/follow_requests/<id>/authorize", follow_requests.accept_follow_request),
|
||||
path("v1/follow_requests/<id>/reject", follow_requests.reject_follow_request),
|
||||
path(
|
||||
"v1/follow_requests/<int:id>/authorize", follow_requests.accept_follow_request
|
||||
),
|
||||
path("v1/follow_requests/<int:id>/reject", follow_requests.reject_follow_request),
|
||||
# Instance
|
||||
path("v1/instance", instance.instance_info_v1),
|
||||
path("v1/instance/activity", instance.activity),
|
||||
|
@ -70,24 +72,24 @@ urlpatterns = [
|
|||
# Media
|
||||
path("v1/media", media.upload_media),
|
||||
path("v2/media", media.upload_media),
|
||||
path("v1/media/<id>", methods(get=media.get_media, put=media.update_media)),
|
||||
path("v1/media/<int:id>", methods(get=media.get_media, put=media.update_media)),
|
||||
path(
|
||||
"v1/statuses/<id>",
|
||||
"v1/statuses/<int:id>",
|
||||
methods(
|
||||
get=statuses.status,
|
||||
put=statuses.edit_status,
|
||||
delete=statuses.delete_status,
|
||||
),
|
||||
),
|
||||
path("v1/statuses/<id>/source", statuses.status_source),
|
||||
path("v1/statuses/<int:id>/source", statuses.status_source),
|
||||
# Notifications
|
||||
path("v1/notifications", notifications.notifications),
|
||||
path("v1/notifications/clear", notifications.dismiss_notifications),
|
||||
path("v1/notifications/<id>", notifications.get_notification),
|
||||
path("v1/notifications/<id>/dismiss", notifications.dismiss_notification),
|
||||
path("v1/notifications/<int:id>", notifications.get_notification),
|
||||
path("v1/notifications/<int:id>/dismiss", notifications.dismiss_notification),
|
||||
# Polls
|
||||
path("v1/polls/<id>", polls.get_poll),
|
||||
path("v1/polls/<id>/votes", polls.vote_poll),
|
||||
path("v1/polls/<int:id>", polls.get_poll),
|
||||
path("v1/polls/<int:id>/votes", polls.vote_poll),
|
||||
# Preferences
|
||||
path("v1/preferences", preferences.preferences),
|
||||
# Push
|
||||
|
@ -105,26 +107,26 @@ urlpatterns = [
|
|||
path("v2/search", search.search),
|
||||
# Statuses
|
||||
path("v1/statuses", statuses.post_status),
|
||||
path("v1/statuses/<id>/context", statuses.status_context),
|
||||
path("v1/statuses/<id>/favourite", statuses.favourite_status),
|
||||
path("v1/statuses/<id>/unfavourite", statuses.unfavourite_status),
|
||||
path("v1/statuses/<id>/favourited_by", statuses.favourited_by),
|
||||
path("v1/statuses/<id>/reblog", statuses.reblog_status),
|
||||
path("v1/statuses/<id>/unreblog", statuses.unreblog_status),
|
||||
path("v1/statuses/<id>/reblogged_by", statuses.reblogged_by),
|
||||
path("v1/statuses/<id>/bookmark", statuses.bookmark_status),
|
||||
path("v1/statuses/<id>/unbookmark", statuses.unbookmark_status),
|
||||
path("v1/statuses/<id>/pin", statuses.pin_status),
|
||||
path("v1/statuses/<id>/unpin", statuses.unpin_status),
|
||||
path("v1/statuses/<int:id>/context", statuses.status_context),
|
||||
path("v1/statuses/<int:id>/favourite", statuses.favourite_status),
|
||||
path("v1/statuses/<int:id>/unfavourite", statuses.unfavourite_status),
|
||||
path("v1/statuses/<int:id>/favourited_by", statuses.favourited_by),
|
||||
path("v1/statuses/<int:id>/reblog", statuses.reblog_status),
|
||||
path("v1/statuses/<int:id>/unreblog", statuses.unreblog_status),
|
||||
path("v1/statuses/<int:id>/reblogged_by", statuses.reblogged_by),
|
||||
path("v1/statuses/<int:id>/bookmark", statuses.bookmark_status),
|
||||
path("v1/statuses/<int:id>/unbookmark", statuses.unbookmark_status),
|
||||
path("v1/statuses/<int:id>/pin", statuses.pin_status),
|
||||
path("v1/statuses/<int:id>/unpin", statuses.unpin_status),
|
||||
# Tags
|
||||
path("v1/followed_tags", tags.followed_tags),
|
||||
path("v1/tags/<hashtag>", tags.hashtag),
|
||||
path("v1/tags/<id>/follow", tags.follow),
|
||||
path("v1/tags/<id>/unfollow", tags.unfollow),
|
||||
path("v1/tags/<str:hashtag>", tags.hashtag),
|
||||
path("v1/tags/<str:id>/follow", tags.follow),
|
||||
path("v1/tags/<str:id>/unfollow", tags.unfollow),
|
||||
# Timelines
|
||||
path("v1/timelines/home", timelines.home),
|
||||
path("v1/timelines/public", timelines.public),
|
||||
path("v1/timelines/tag/<hashtag>", timelines.hashtag),
|
||||
path("v1/timelines/tag/<str:hashtag>", timelines.hashtag),
|
||||
path("v1/conversations", timelines.conversations),
|
||||
path("v1/favourites", timelines.favourites),
|
||||
# Trends
|
||||
|
|
|
@ -163,7 +163,7 @@ def lookup(request: HttpRequest, acct: str) -> schemas.Account:
|
|||
|
||||
@scope_required("read:accounts")
|
||||
@api_view.get
|
||||
def account(request, id: str) -> schemas.Account:
|
||||
def account(request, id: int) -> schemas.Account:
|
||||
identity = get_object_or_404(
|
||||
Identity.objects.exclude(restriction=Identity.Restriction.blocked),
|
||||
pk=id,
|
||||
|
@ -175,7 +175,7 @@ def account(request, id: str) -> schemas.Account:
|
|||
@api_view.get
|
||||
def account_statuses(
|
||||
request: HttpRequest,
|
||||
id: str,
|
||||
id: int,
|
||||
exclude_reblogs: bool = False,
|
||||
exclude_replies: bool = False,
|
||||
only_media: bool = False,
|
||||
|
@ -238,7 +238,7 @@ def account_statuses(
|
|||
|
||||
@scope_required("write:follows")
|
||||
@api_view.post
|
||||
def account_follow(request, id: str, reblogs: bool = True) -> schemas.Relationship:
|
||||
def account_follow(request, id: int, reblogs: bool = True) -> schemas.Relationship:
|
||||
identity = get_object_or_404(
|
||||
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
|
||||
)
|
||||
|
@ -249,7 +249,7 @@ def account_follow(request, id: str, reblogs: bool = True) -> schemas.Relationsh
|
|||
|
||||
@scope_required("write:follows")
|
||||
@api_view.post
|
||||
def account_unfollow(request, id: str) -> schemas.Relationship:
|
||||
def account_unfollow(request, id: int) -> schemas.Relationship:
|
||||
identity = get_object_or_404(
|
||||
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
|
||||
)
|
||||
|
@ -260,7 +260,7 @@ def account_unfollow(request, id: str) -> schemas.Relationship:
|
|||
|
||||
@scope_required("write:blocks")
|
||||
@api_view.post
|
||||
def account_block(request, id: str) -> schemas.Relationship:
|
||||
def account_block(request, id: int) -> schemas.Relationship:
|
||||
identity = get_object_or_404(Identity, pk=id)
|
||||
service = IdentityService(request.identity)
|
||||
service.block(identity)
|
||||
|
@ -269,7 +269,7 @@ def account_block(request, id: str) -> schemas.Relationship:
|
|||
|
||||
@scope_required("write:blocks")
|
||||
@api_view.post
|
||||
def account_unblock(request, id: str) -> schemas.Relationship:
|
||||
def account_unblock(request, id: int) -> schemas.Relationship:
|
||||
identity = get_object_or_404(Identity, pk=id)
|
||||
service = IdentityService(request.identity)
|
||||
service.unblock(identity)
|
||||
|
@ -280,7 +280,7 @@ def account_unblock(request, id: str) -> schemas.Relationship:
|
|||
@api_view.post
|
||||
def account_mute(
|
||||
request,
|
||||
id: str,
|
||||
id: int,
|
||||
notifications: QueryOrBody[bool] = True,
|
||||
duration: QueryOrBody[int] = 0,
|
||||
) -> schemas.Relationship:
|
||||
|
@ -296,7 +296,7 @@ def account_mute(
|
|||
|
||||
@scope_required("write:blocks")
|
||||
@api_view.post
|
||||
def account_unmute(request, id: str) -> schemas.Relationship:
|
||||
def account_unmute(request, id: int) -> schemas.Relationship:
|
||||
identity = get_object_or_404(Identity, pk=id)
|
||||
service = IdentityService(request.identity)
|
||||
service.unmute(identity)
|
||||
|
@ -306,7 +306,7 @@ def account_unmute(request, id: str) -> schemas.Relationship:
|
|||
@api_view.get
|
||||
def account_following(
|
||||
request: HttpRequest,
|
||||
id: str,
|
||||
id: int,
|
||||
max_id: str | None = None,
|
||||
since_id: str | None = None,
|
||||
min_id: str | None = None,
|
||||
|
@ -339,7 +339,7 @@ def account_following(
|
|||
@api_view.get
|
||||
def account_followers(
|
||||
request: HttpRequest,
|
||||
id: str,
|
||||
id: int,
|
||||
max_id: str | None = None,
|
||||
since_id: str | None = None,
|
||||
min_id: str | None = None,
|
||||
|
@ -370,6 +370,6 @@ def account_followers(
|
|||
|
||||
|
||||
@api_view.get
|
||||
def account_featured_tags(request: HttpRequest, id: str) -> list[schemas.FeaturedTag]:
|
||||
def account_featured_tags(request: HttpRequest, id: int) -> list[schemas.FeaturedTag]:
|
||||
# Not implemented yet
|
||||
return []
|
||||
|
|
|
@ -18,6 +18,6 @@ def announcement_list(request) -> list[schemas.Announcement]:
|
|||
|
||||
@scope_required("write:notifications")
|
||||
@api_view.post
|
||||
def announcement_dismiss(request, pk: str):
|
||||
def announcement_dismiss(request, pk: int):
|
||||
announcement = get_object_or_404(Announcement, pk=pk)
|
||||
AnnouncementService(request.user).mark_seen(announcement)
|
||||
|
|
|
@ -38,7 +38,7 @@ def follow_requests(
|
|||
@api_view.post
|
||||
def accept_follow_request(
|
||||
request: HttpRequest,
|
||||
id: str | None = None,
|
||||
id: int | None = None,
|
||||
) -> schemas.Relationship:
|
||||
source_identity = get_object_or_404(
|
||||
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
|
||||
|
@ -51,7 +51,7 @@ def accept_follow_request(
|
|||
@api_view.post
|
||||
def reject_follow_request(
|
||||
request: HttpRequest,
|
||||
id: str | None = None,
|
||||
id: int | None = None,
|
||||
) -> schemas.Relationship:
|
||||
source_identity = get_object_or_404(
|
||||
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
|
||||
|
|
|
@ -52,7 +52,7 @@ def upload_media(
|
|||
@api_view.get
|
||||
def get_media(
|
||||
request,
|
||||
id: str,
|
||||
id: int,
|
||||
) -> schemas.MediaAttachment:
|
||||
attachment = get_object_or_404(PostAttachment, pk=id)
|
||||
if attachment.post:
|
||||
|
@ -67,7 +67,7 @@ def get_media(
|
|||
@api_view.put
|
||||
def update_media(
|
||||
request,
|
||||
id: str,
|
||||
id: int,
|
||||
description: QueryOrBody[str] = "",
|
||||
focus: QueryOrBody[str] = "0,0",
|
||||
) -> schemas.MediaAttachment:
|
||||
|
|
|
@ -12,14 +12,14 @@ class PostVoteSchema(Schema):
|
|||
|
||||
@scope_required("read:statuses")
|
||||
@api_view.get
|
||||
def get_poll(request, id: str) -> schemas.Poll:
|
||||
def get_poll(request, id: int) -> schemas.Poll:
|
||||
post = get_object_or_404(Post, pk=id, type=Post.Types.question)
|
||||
return schemas.Poll.from_post(post, identity=request.identity)
|
||||
|
||||
|
||||
@scope_required("write:statuses")
|
||||
@api_view.post
|
||||
def vote_poll(request, id: str, details: PostVoteSchema) -> schemas.Poll:
|
||||
def vote_poll(request, id: int, details: PostVoteSchema) -> schemas.Poll:
|
||||
post = get_object_or_404(Post, pk=id, type=Post.Types.question)
|
||||
PostInteraction.create_votes(post, request.identity, details.choices)
|
||||
post.refresh_from_db()
|
||||
|
|
|
@ -64,7 +64,7 @@ class EditStatusSchema(Schema):
|
|||
media_attributes: list[MediaAttributesSchema] = []
|
||||
|
||||
|
||||
def post_for_id(request: HttpRequest, id: str) -> Post:
|
||||
def post_for_id(request: HttpRequest, id: int) -> Post:
|
||||
"""
|
||||
Common logic to get a Post object for an ID, taking visibility into
|
||||
account.
|
||||
|
@ -118,7 +118,7 @@ def post_status(request, details: PostStatusSchema) -> schemas.Status:
|
|||
|
||||
@scope_required("read:statuses")
|
||||
@api_view.get
|
||||
def status(request, id: str) -> schemas.Status:
|
||||
def status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
interactions = PostInteraction.get_post_interactions([post], request.identity)
|
||||
return schemas.Status.from_post(
|
||||
|
@ -128,7 +128,7 @@ def status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("write:statuses")
|
||||
@api_view.put
|
||||
def edit_status(request, id: str, details: EditStatusSchema) -> schemas.Status:
|
||||
def edit_status(request, id: int, details: EditStatusSchema) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
if post.author != request.identity:
|
||||
raise ApiError(401, "Not the author of this status")
|
||||
|
@ -147,7 +147,7 @@ def edit_status(request, id: str, details: EditStatusSchema) -> schemas.Status:
|
|||
|
||||
@scope_required("write:statuses")
|
||||
@api_view.delete
|
||||
def delete_status(request, id: str) -> schemas.Status:
|
||||
def delete_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
if post.author != request.identity:
|
||||
raise ApiError(401, "Not the author of this status")
|
||||
|
@ -157,14 +157,14 @@ def delete_status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("read:statuses")
|
||||
@api_view.get
|
||||
def status_source(request, id: str) -> schemas.StatusSource:
|
||||
def status_source(request, id: int) -> schemas.StatusSource:
|
||||
post = post_for_id(request, id)
|
||||
return schemas.StatusSource.from_post(post)
|
||||
|
||||
|
||||
@scope_required("read:statuses")
|
||||
@api_view.get
|
||||
def status_context(request, id: str) -> schemas.Context:
|
||||
def status_context(request, id: int) -> schemas.Context:
|
||||
post = post_for_id(request, id)
|
||||
service = PostService(post)
|
||||
ancestors, descendants = service.context(request.identity)
|
||||
|
@ -189,7 +189,7 @@ def status_context(request, id: str) -> schemas.Context:
|
|||
|
||||
@scope_required("write:favourites")
|
||||
@api_view.post
|
||||
def favourite_status(request, id: str) -> schemas.Status:
|
||||
def favourite_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
service = PostService(post)
|
||||
service.like_as(request.identity)
|
||||
|
@ -201,7 +201,7 @@ def favourite_status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("write:favourites")
|
||||
@api_view.post
|
||||
def unfavourite_status(request, id: str) -> schemas.Status:
|
||||
def unfavourite_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
service = PostService(post)
|
||||
service.unlike_as(request.identity)
|
||||
|
@ -214,7 +214,7 @@ def unfavourite_status(request, id: str) -> schemas.Status:
|
|||
@api_view.get
|
||||
def favourited_by(
|
||||
request: HttpRequest,
|
||||
id: str,
|
||||
id: int,
|
||||
max_id: str | None = None,
|
||||
since_id: str | None = None,
|
||||
min_id: str | None = None,
|
||||
|
@ -256,7 +256,7 @@ def favourited_by(
|
|||
@api_view.get
|
||||
def reblogged_by(
|
||||
request: HttpRequest,
|
||||
id: str,
|
||||
id: int,
|
||||
max_id: str | None = None,
|
||||
since_id: str | None = None,
|
||||
min_id: str | None = None,
|
||||
|
@ -297,7 +297,7 @@ def reblogged_by(
|
|||
|
||||
@scope_required("write:favourites")
|
||||
@api_view.post
|
||||
def reblog_status(request, id: str) -> schemas.Status:
|
||||
def reblog_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
service = PostService(post)
|
||||
service.boost_as(request.identity)
|
||||
|
@ -309,7 +309,7 @@ def reblog_status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("write:favourites")
|
||||
@api_view.post
|
||||
def unreblog_status(request, id: str) -> schemas.Status:
|
||||
def unreblog_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
service = PostService(post)
|
||||
service.unboost_as(request.identity)
|
||||
|
@ -321,7 +321,7 @@ def unreblog_status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("write:bookmarks")
|
||||
@api_view.post
|
||||
def bookmark_status(request, id: str) -> schemas.Status:
|
||||
def bookmark_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
request.identity.bookmarks.get_or_create(post=post)
|
||||
interactions = PostInteraction.get_post_interactions([post], request.identity)
|
||||
|
@ -332,7 +332,7 @@ def bookmark_status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("write:bookmarks")
|
||||
@api_view.post
|
||||
def unbookmark_status(request, id: str) -> schemas.Status:
|
||||
def unbookmark_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
request.identity.bookmarks.filter(post=post).delete()
|
||||
interactions = PostInteraction.get_post_interactions([post], request.identity)
|
||||
|
@ -343,7 +343,7 @@ def unbookmark_status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("write:accounts")
|
||||
@api_view.post
|
||||
def pin_status(request, id: str) -> schemas.Status:
|
||||
def pin_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
try:
|
||||
PostService(post).pin_as(request.identity)
|
||||
|
@ -357,7 +357,7 @@ def pin_status(request, id: str) -> schemas.Status:
|
|||
|
||||
@scope_required("write:accounts")
|
||||
@api_view.post
|
||||
def unpin_status(request, id: str) -> schemas.Status:
|
||||
def unpin_status(request, id: int) -> schemas.Status:
|
||||
post = post_for_id(request, id)
|
||||
PostService(post).unpin_as(request.identity)
|
||||
interactions = PostInteraction.get_post_interactions([post], request.identity)
|
||||
|
|
Loading…
Reference in a new issue