2018-07-02 01:08:13 -04:00
|
|
|
import json
|
|
|
|
|
2018-01-28 18:28:46 -05:00
|
|
|
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
|
2018-07-02 01:08:13 -04:00
|
|
|
from .delete import delete
|
2018-01-28 18:28:46 -05:00
|
|
|
from .query import query
|
|
|
|
|
2018-07-02 01:08:13 -04:00
|
|
|
actions = {
|
2023-08-10 02:52:37 -04:00
|
|
|
"create": create,
|
|
|
|
"delete": delete,
|
2018-07-02 01:08:13 -04:00
|
|
|
}
|
|
|
|
|
2018-01-28 18:28:46 -05:00
|
|
|
|
|
|
|
@csrf_exempt
|
2023-08-10 02:52:37 -04:00
|
|
|
@require_http_methods(["GET", "HEAD", "POST"])
|
2018-01-28 18:28:46 -05:00
|
|
|
def micropub(request):
|
2018-07-02 19:51:51 -04:00
|
|
|
request.token = tokens.auth(request)
|
2023-08-10 02:52:37 -04:00
|
|
|
if request.method in ("GET", "HEAD"):
|
2018-01-28 18:28:46 -05:00
|
|
|
return query(request)
|
2018-07-02 01:08:13 -04:00
|
|
|
|
2023-08-10 02:52:37 -04:00
|
|
|
action = request.POST.get("action", "create")
|
|
|
|
if request.content_type == "application/json":
|
2018-07-02 01:08:13 -04:00
|
|
|
request.json = json.load(request)
|
2023-08-10 02:52:37 -04:00
|
|
|
action = request.json.get("action", "create")
|
2018-07-02 20:03:35 -04:00
|
|
|
if action not in actions:
|
2023-08-10 02:52:37 -04:00
|
|
|
raise error.bad_req("unknown action: {}".format(action))
|
2018-07-02 20:03:35 -04:00
|
|
|
return actions[action](request)
|