"/api/user/<string:username>/inbox",
"mediagoblin.federation.views:inbox"
)
+
+# object endpoints
+add_route(
+ "mediagoblin.federation.object",
+ "/api/<string:objectType>/<string:uuid>",
+ "mediagoblin.federation.views:object"
+ )
from mediagoblin.decorators import oauth_required
-from mediagoblin.db.models import User
+from mediagoblin.db.models import User, MediaEntry
from mediagoblin.tools.response import json_response
@oauth_required
@oauth_required
def inbox(request):
""" Handles the user's inbox - /api/user/<username>/inbox """
- pass
-
raise NotImplemented("Yet to implement looking up user's inbox")
+
+def image_object(request, media):
+ """ Return image object - /api/image/<uuid> """
+ author = media.get_uploader
+ url = request.urlgen(
+ "mediagoblin.user_pages.media_home",
+ user=author.username,
+ media=media.slug,
+ qualified=True
+ )
+
+ context = {
+ "author": author.serialize(request),
+ "displayName": media.title,
+ "objectType": "image",
+ "url": url,
+ }
+
+ return json_response(context)
+
+@oauth_required
+def object(request):
+ """ Lookup for a object type """
+ objectType = request.matchdict["objectType"]
+ uuid = request.matchdict["uuid"]
+ if objectType not in ["image"]:
+ error = "Unknown type: {0}".format(objectType)
+ # not sure why this is 404, maybe ask evan. Maybe 400?
+ return json_response({"error": error}, status=404)
+
+ media = MediaEntry.query.filter_by(uuid=uuid).first()
+ if media is None:
+ # no media found with that uuid
+ error = "Can't find a {0} with ID = {1}".format(objectType, uuid)
+ return json_response({"error": error}, status=404)
+
+ if objectType == "image":
+ return image_object(request, media)