Skip to content

Commit

Permalink
fix(ltDataAuth): flask-seasurf compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Aug 13, 2024
1 parent c25bf36 commit 0ca3705
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
5 changes: 4 additions & 1 deletion app/api/ltDataAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export function editLocation(title: CommonsFile, coordinates: LatLng[]) {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': xsrfToken() || ''
},
body: JSON.stringify(coordinates.map(({type, lat, lng}) => ({type, lat, lng, pageid})))
body: JSON.stringify({
pageid,
locations: coordinates.map(({type, lat, lng}) => ({type, lat, lng}))
})
},
{
afterFetch(ctx) {
Expand Down
34 changes: 21 additions & 13 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ def user():
LocationType = typing.Literal["Location", "Object location"]


class EditRequest(typing.TypedDict):
class EditLocation(typing.TypedDict):
type: LocationType
lat: int
lng: int


class EditRequest(typing.TypedDict):
locations: list[EditLocation]
pageid: int


Expand All @@ -65,13 +69,17 @@ def edit():
if not mwoauth.get_current_user():
abort(401)

data: list[EditRequest] = request.get_json()
if not data or not all(
"pageid" in d or "type" in d or "lat" in d or "lng" in d for d in data
data: EditRequest = request.get_json()
if (
not data
or "pageid" not in data
or "locations" not in data
or not all("type" in d or "lat" in d or "lng" in d for d in data["locations"])
):
abort(400)

pageid = int(data[0]["pageid"])
pageid = int(data["pageid"])
locations = data["locations"]
app.logger.info("Received request %s", str(data))

r1: QueryResult = mwoauth_request(
Expand All @@ -98,17 +106,17 @@ def edit():
except KeyError:
abort(404)

for d in data:
for location in locations:
wikitext = add_location_to_wikitext(
type=d["type"],
lat=float(d["lat"]),
lng=float(d["lng"]),
type=location["type"],
lat=float(location["lat"]),
lng=float(location["lng"]),
wikitext=wikitext,
)
edit_mediainfo(
type=d["type"],
lat=float(d["lat"]),
lng=float(d["lng"]),
type=location["type"],
lat=float(location["lat"]),
lng=float(location["lng"]),
page=page,
token=token,
)
Expand All @@ -117,7 +125,7 @@ def edit():
format="json",
action="edit",
pageid=str(pageid),
summary=", ".join("{{%s}}" % d["type"] for d in data),
summary=", ".join("{{%s}}" % d["type"] for d in locations),
text=wikitext,
token=token,
)
Expand Down

0 comments on commit 0ca3705

Please sign in to comment.