forked from 00dani/lemoncurry
34 lines
894 B
Python
34 lines
894 B
Python
import json
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.http import require_http_methods
|
|
|
|
from lemonauth import tokens
|
|
|
|
from .create import create
|
|
from .delete import delete
|
|
from .query import query
|
|
|
|
actions = {
|
|
'create': create,
|
|
'delete': delete,
|
|
}
|
|
|
|
|
|
@csrf_exempt
|
|
@require_http_methods(['GET', 'HEAD', 'POST'])
|
|
def micropub(request):
|
|
token = tokens.auth(request)
|
|
if hasattr(token, 'content'):
|
|
return token
|
|
request.token = token
|
|
if request.method in ('GET', 'HEAD'):
|
|
return query(request)
|
|
|
|
action = request.POST.get('action', 'create')
|
|
if request.content_type == 'application/json':
|
|
request.json = json.load(request)
|
|
action = request.json.get('action', 'create')
|
|
if action in actions:
|
|
return actions[action](request)
|
|
return error.bad_req('unknown action: {}'.format(action))
|