Support for the comments endpoint
This commit is contained in:
parent
37f070b067
commit
98596dd072
@ -455,7 +455,9 @@ class MediaEntry(Base, MediaEntryMixin):
|
|||||||
},
|
},
|
||||||
"fullImage":{
|
"fullImage":{
|
||||||
"url": request.host_url + self.original_url[1:],
|
"url": request.host_url + self.original_url[1:],
|
||||||
}
|
},
|
||||||
|
"published": self.created.isoformat(),
|
||||||
|
"updated": self.created.isoformat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if show_comments:
|
if show_comments:
|
||||||
@ -465,7 +467,13 @@ class MediaEntry(Base, MediaEntryMixin):
|
|||||||
# we only want to include replies if there are any.
|
# we only want to include replies if there are any.
|
||||||
context["replies"] = {
|
context["replies"] = {
|
||||||
"totalItems": total,
|
"totalItems": total,
|
||||||
"items": comments
|
"items": comments,
|
||||||
|
"url": request.urlgen(
|
||||||
|
"mediagoblin.federation.object.comments",
|
||||||
|
objectType=self.objectType,
|
||||||
|
uuid=self.slug,
|
||||||
|
qualified=True
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
@ -48,3 +48,8 @@ add_route(
|
|||||||
"/api/<string:objectType>/<string:uuid>",
|
"/api/<string:objectType>/<string:uuid>",
|
||||||
"mediagoblin.federation.views:object"
|
"mediagoblin.federation.views:object"
|
||||||
)
|
)
|
||||||
|
add_route(
|
||||||
|
"mediagoblin.federation.object.comments",
|
||||||
|
"/api/<string:objectType>/<string:uuid>/comments",
|
||||||
|
"mediagoblin.federation.views:object_comments"
|
||||||
|
)
|
||||||
|
@ -39,8 +39,8 @@ def inbox(request):
|
|||||||
""" Handles the user's inbox - /api/user/<username>/inbox """
|
""" Handles the user's inbox - /api/user/<username>/inbox """
|
||||||
raise NotImplemented("Yet to implement looking up user's inbox")
|
raise NotImplemented("Yet to implement looking up user's inbox")
|
||||||
|
|
||||||
@oauth_required
|
#@oauth_required
|
||||||
def object(request):
|
def object(request, raw_obj=False):
|
||||||
""" Lookup for a object type """
|
""" Lookup for a object type """
|
||||||
objectType = request.matchdict["objectType"]
|
objectType = request.matchdict["objectType"]
|
||||||
uuid = request.matchdict["uuid"]
|
uuid = request.matchdict["uuid"]
|
||||||
@ -55,4 +55,26 @@ def object(request):
|
|||||||
error = "Can't find a {0} with ID = {1}".format(objectType, uuid)
|
error = "Can't find a {0} with ID = {1}".format(objectType, uuid)
|
||||||
return json_response({"error": error}, status=404)
|
return json_response({"error": error}, status=404)
|
||||||
|
|
||||||
|
if raw_obj:
|
||||||
|
return media
|
||||||
|
|
||||||
return json_response(media.serialize(request))
|
return json_response(media.serialize(request))
|
||||||
|
|
||||||
|
def object_comments(request):
|
||||||
|
""" Looks up for the comments on a object """
|
||||||
|
media = object(request, raw_obj=True)
|
||||||
|
response = media
|
||||||
|
if isinstance(response, MediaEntry):
|
||||||
|
comments = response.serialize(request)
|
||||||
|
comments = comments.get("replies", {
|
||||||
|
"totalItems": 0,
|
||||||
|
"items": [],
|
||||||
|
"url": request.urlgen(
|
||||||
|
"mediagoblin.federation.object.comments",
|
||||||
|
objectType=media.objectType,
|
||||||
|
uuid=media.slug,
|
||||||
|
qualified=True)
|
||||||
|
})
|
||||||
|
response = json_response(comments)
|
||||||
|
|
||||||
|
return response
|
||||||
|
Loading…
x
Reference in New Issue
Block a user