From ba15a0e23b3383211652accbd2ef8beac51abec4 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Wed, 10 Apr 2024 13:35:24 +0200 Subject: [PATCH] fix: url param decoding --- README.md | 22 ++++++++++++------ app/lib/server_requests/fetch_relation.dart | 4 ++-- server/main.py | 8 +++++-- .../get_measurements.cpython-311.pyc | Bin 4837 -> 4837 bytes .../lake_relations/mjo\303\270a_centers.txt" | 0 .../lake_relations/mj\303\270sa.geojson" | 0 .../lake_relations/mj\303\270sa_div.json" | 0 7 files changed, 23 insertions(+), 11 deletions(-) rename server/map_handler/lake_relations/mjosa_centers.txt => "server/map_handler/lake_relations/mjo\303\270a_centers.txt" (100%) rename server/map_handler/lake_relations/mjosa.geojson => "server/map_handler/lake_relations/mj\303\270sa.geojson" (100%) rename server/map_handler/lake_relations/mjosa_div.json => "server/map_handler/lake_relations/mj\303\270sa_div.json" (100%) diff --git a/README.md b/README.md index 0708f0ae..b4b4c99a 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,19 @@ # PROG2900 ## Dependencies -### Python + +## Endpoints +``` +\ +\update_map +\get_relation +\add_new_lake?lake=name +``` + +### Server To run the server... -### Dart & Flutter +### Application ### Database @@ -14,8 +23,8 @@ binary in a folder and note its path. Add the path to your system environment va manage the SQLite database. ## Adding new lakes -The current server only contains the data for a single lake, Mjøsa. To add more lakes -go to https://overpass-turbo.eu/. Once you have navigated to Overpass API, enter +To add a new lake to the system, go to https://overpass-turbo.eu/. +Once you have navigated to Overpass API, enter the Overpass query below in the left field, but swap 'lakeName' out with the name of the lake you want to add. Once the query has been adjusted, press the 'Run' button. @@ -44,11 +53,10 @@ IceMap/server/lake_relations. Once you have added the file, run map division... The result will be two new files named lakeName_centers.txt and lakeName_div.json. The original lakeName.geojson file should also remain in the system. Additionally, the file named all_lake_names.json should be updated to contain the newly added lake name. - + -## Endpoints -## Bugs +## Known bugs ## Developers diff --git a/app/lib/server_requests/fetch_relation.dart b/app/lib/server_requests/fetch_relation.dart index 999ec52e..875f3a31 100644 --- a/app/lib/server_requests/fetch_relation.dart +++ b/app/lib/server_requests/fetch_relation.dart @@ -15,10 +15,10 @@ Future<Uint8List> fetchRelation() async { (X509Certificate cert, String host, int port) => true; // Execute request to to get_relation endpoint - var parameterValue = 'Mjosa'; // NB temp hardcoded, should use selectedLake directly in url param + var parameterValue = 'Mjøsa'; // NB temp hardcoded, should use selectedLake directly in url param //var request = await client.getUrl(Uri.parse('${serverURI}get_relation')); var request = await client.getUrl(Uri.parse('${serverURI}get_relation?lake=' - '${Uri.encodeComponent(parameterValue)}')); + '${Uri.encodeFull(parameterValue)}')); var response = await request.close(); // Close response body at end of function diff --git a/server/main.py b/server/main.py index 0da46fc0..092cb643 100644 --- a/server/main.py +++ b/server/main.py @@ -2,7 +2,7 @@ import ssl import json import sqlite3 from flask import Flask -from urllib.parse import urlparse, parse_qs +from urllib.parse import urlparse, parse_qs, unquote from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT from http.server import HTTPServer, BaseHTTPRequestHandler @@ -62,7 +62,11 @@ class IceHTTP(BaseHTTPRequestHandler): elif self.path.startswith('/get_relation'): parsed_path = urlparse(self.path) query_params = parse_qs(parsed_path.query) - get_divided_map(self, 'Mjosa') # NB temp hardcoded value + + lake_name_param = query_params.get('lake', [''])[0] + lake_name = unquote(lake_name_param) # Decode url param + + get_divided_map(self, lake_name) elif self.path.startswith('/add_new_lake'): parsed_path = urlparse(self.path) query_params = parse_qs(parsed_path.query) diff --git a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc index 66ee2b79758cd097b69411fe7d8ffb43b9979f32..b375f54cdcedc8721cc48f56cd6d406bab183dd4 100644 GIT binary patch delta 19 ZcmaE=`c#!`IWI340}v#YZ{)fy1OPeZ1#18R delta 19 ZcmaE=`c#!`IWI340}yydZsfWx1OPa>1vCHv diff --git a/server/map_handler/lake_relations/mjosa_centers.txt "b/server/map_handler/lake_relations/mjo\303\270a_centers.txt" similarity index 100% rename from server/map_handler/lake_relations/mjosa_centers.txt rename to "server/map_handler/lake_relations/mjo\303\270a_centers.txt" diff --git a/server/map_handler/lake_relations/mjosa.geojson "b/server/map_handler/lake_relations/mj\303\270sa.geojson" similarity index 100% rename from server/map_handler/lake_relations/mjosa.geojson rename to "server/map_handler/lake_relations/mj\303\270sa.geojson" diff --git a/server/map_handler/lake_relations/mjosa_div.json "b/server/map_handler/lake_relations/mj\303\270sa_div.json" similarity index 100% rename from server/map_handler/lake_relations/mjosa_div.json rename to "server/map_handler/lake_relations/mj\303\270sa_div.json" -- GitLab