#@oauth_required
@csrf_exempt
def uploads(request):
- """ This is the endpoint which uploads can be sent ot - /api/user/<username>/uploads """
+ """ This is the endpoint which uploads can be sent to - /api/user/<username>/uploads """
user = request.matchdict["username"]
requested_user = User.query.filter_by(username=user)
if request.method == "POST":
# Wrap the data in the werkzeug file wrapper
file_data = FileStorage(
- stream=io.BytesIO(request.data),
- filename=request.args.get("qqfile", "unknown.jpg"),
- content_type=request.headers.get("Content-Type", "application/octal-stream")
- )
-
- # Use the same kind of method from mediagoblin/submit/views:submit_start
+ stream=io.BytesIO(request.data),
+ filename=request.args.get("qqfile", "unknown.jpg"),
+ content_type=request.headers.get("Content-Type", "application/octal-stream")
+ )
+
+ # Find media manager
media_type, media_manager = sniff_media(file_data)
entry = new_upload_entry(request.user)
- entry.media_type = unicode(media_type)
- entry.title = unicode(request.args.get("title", "Hello ^_^"))
- entry.description = unicode(request.args.get("description", ""))
- entry.license = None
-
- entry.generate_slug()
-
- queue_file = prepare_queue_task(request.app, entry, file_data.filename)
- with queue_file:
- queue_file.write(request.data)
-
- entry.save()
-
- # run the processing
- feed_url = request.urlgen(
- 'mediagoblin.user_pages.atom_feed',
- qualified=True, user=request.user.username)
-
- run_process_media(entry, feed_url)
- add_comment_subscription(request.user, entry)
-
- return json_response(entry.serialize(request))
+ if hasattr(media_manager, "api_upload_request"):
+ return media_manager.api_upload_request(request, file_data, entry)
+ else:
+ return json_response({"error": "Not yet implemented"}, status=400)
return json_response({"error": "Not yet implemented"}, status=400)
-@oauth_required
+#@oauth_required
@csrf_exempt
def feed(request):
""" Handles the user's outbox - /api/user/<username>/feed """
comment.save()
data = {"verb": "post", "object": comment.serialize(request)}
return json_response(data)
+
elif obj.get("objectType", None) == "image":
# Posting an image to the feed
# NB: This is currently just handing the image back until we have an
error = {"error": "Unknown object type '{0}'.".format(obj.get("objectType", None))}
return json_response(error, status=400)
+
feed_url = request.urlgen(
"mediagoblin.federation.feed",
username=request.user.username,
from mediagoblin.media_types import MediaManagerBase
from mediagoblin.media_types.image.processing import sniff_handler, \
ImageProcessingManager
-
+from mediagoblin.tools.response import json_response
+from mediagoblin.submit.lib import prepare_queue_task, run_process_media
+from mediagoblin.notifications import add_comment_subscription
_log = logging.getLogger(__name__)
except (KeyError, ValueError):
return None
+ @staticmethod
+ def api_upload_request(request, file_data, entry):
+ """ This handles a image upload request """
+ # Use the same kind of method from mediagoblin/submit/views:submit_start
+ entry.media_type = unicode(MEDIA_TYPE)
+ entry.title = unicode(request.args.get("title", file_data.filename))
+ entry.description = unicode(request.args.get("description", ""))
+ entry.license = request.args.get("license", "") # not part of the standard API
+
+ entry.generate_slug()
+
+ queue_file = prepare_queue_task(request.app, entry, file_data.filename)
+ with queue_file:
+ queue_file.write(request.data)
+
+ entry.save()
+
+ feed_url = request.urlgen(
+ 'mediagoblin.user_pages.atom_feed',
+ qualified=True, user=request.user.username)
+
+ run_process_media(entry, feed_url)
+ add_comment_subscription(request.user, entry)
+ return json_response(entry.serialize(request))
def get_media_type_and_manager(ext):
if ext in ACCEPTED_EXTENSIONS: