mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-06-24 05:35:10 +00:00
Stop fudging the server-side handling instructions for "add spot" into the spot data structure itself, instead break them out into a new area. This is a breaking change to the API so all API endpoints have been bumped to v2.
This commit is contained in:
@@ -25,7 +25,7 @@ RECAPTCHA_VERIFY_URL = "https://www.google.com/recaptcha/api/siteverify"
|
||||
|
||||
|
||||
class APISpotHandler(tornado.web.RequestHandler):
|
||||
"""API request handler for /api/v1/spot (POST)"""
|
||||
"""API request handler for /api/v2/spot (POST)"""
|
||||
|
||||
def __init__(self, application: "Application", request: httputil.HTTPServerRequest, **kwargs: Any):
|
||||
self._spots = None
|
||||
@@ -76,13 +76,15 @@ class APISpotHandler(tornado.web.RequestHandler):
|
||||
# Read in the request body as JSON
|
||||
json_body = tornado.escape.json_decode(post_data)
|
||||
|
||||
# Extract fields relating to how we handle the spot, such as CAPTCHA and upstream submission. Remove these
|
||||
# from the data so they don't accidentally end up in the spot object itself.
|
||||
# todo: Better way of separating these out. Possible without API change or not?
|
||||
submit_upstream = json_body.pop("submit_upstream", False)
|
||||
upstream_provider_name = json_body.pop("upstream_provider", None)
|
||||
upstream_credentials = json_body.pop("upstream_credentials", {})
|
||||
captcha_token = json_body.pop("captcha_token", None)
|
||||
# Extract the "spot" and "handling" sub-objects from the request body
|
||||
spot_data = json_body.get("spot", {})
|
||||
handling = json_body.get("handling", {})
|
||||
|
||||
# Extract individual parameters that say how this spot should be handled by the server
|
||||
submit_upstream = handling.get("submit_upstream", False)
|
||||
upstream_provider_name = handling.get("upstream_provider", None)
|
||||
upstream_credentials = handling.get("upstream_credentials", {})
|
||||
captcha_token = handling.get("captcha_token", None)
|
||||
|
||||
# Verify CAPTCHA if required
|
||||
if RECAPTCHA_SECRET_KEY:
|
||||
@@ -101,8 +103,8 @@ class APISpotHandler(tornado.web.RequestHandler):
|
||||
self.set_header("Content-Type", "application/json")
|
||||
return
|
||||
|
||||
# Convert remaining fields to a Spot object
|
||||
spot = Spot(**json_body)
|
||||
# Convert spot field to a Spot object
|
||||
spot = Spot(**spot_data)
|
||||
|
||||
# Converting to a spot object this way won't have coped with sig_ref objects, so fix that. (Would be nice to
|
||||
# redo this in a functional style)
|
||||
|
||||
Reference in New Issue
Block a user