Mercurial > lbo > hg > geohub
changeset 116:32dd1f4174e9
geohub: Introduce datesecret parameter
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Thu, 31 Dec 2020 19:45:15 +0100 |
parents | f9827ab0f35b |
children | 8b7202c3f945 |
files | src/main.rs |
diffstat | 1 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.rs Thu Dec 31 19:42:37 2020 +0100 +++ b/src/main.rs Thu Dec 31 19:45:15 2020 +0100 @@ -178,7 +178,7 @@ /// time is like 2020-11-30T20:12:36.444Z (ISO 8601). By default, server time is set. /// secret can be used to protect points. #[rocket::post( - "/geo/<name>/log?<lat>&<longitude>&<time>&<s>&<ele>&<secret>&<accuracy>&<unit>", + "/geo/<name>/log?<lat>&<longitude>&<time>&<s>&<ele>&<secret>&<accuracy>&<unit>&<datesecret>", data = "<note>" )] fn log( @@ -193,6 +193,7 @@ ele: Option<f64>, accuracy: Option<f64>, unit: Option<String>, + datesecret: Option<bool>, note: rocket::data::Data, ) -> http::GeoHubResponder { // Check that secret and client name are legal. @@ -202,22 +203,24 @@ .into(), ); } + let mut ts = chrono::Utc::now(); + if let Some(time) = time { + ts = util::flexible_timestamp_parse(time).unwrap_or(ts); + } + let secret = if let Some(secret) = secret { if secret.is_empty() { None } else { Some(secret) } + } else if let Some(true) = datesecret { + Some(format!("{}", ts.date().format("%Y%m%d"))) } else { secret }; let db = db::DBQuery(&db.0); - let mut ts = chrono::Utc::now(); - if let Some(time) = time { - ts = util::flexible_timestamp_parse(time).unwrap_or(ts); - } - // Length-limit notes. let note = match http::read_data(note, 4096) { Ok(n) => { @@ -259,12 +262,13 @@ } /// Ingest GeoJSON. -#[rocket::post("/geo/<name>/logjson?<secret>", data = "<body>")] +#[rocket::post("/geo/<name>/logjson?<secret>&<datesecret>", data = "<body>")] fn log_json( db: db::DBConn, notify_manager: rocket::State<notifier::NotifyManager>, name: String, secret: Option<String>, + datesecret: Option<bool>, body: rocket_contrib::json::Json<types::LogLocations>, ) -> http::GeoHubResponder { // Check that secret and client name are legal. @@ -280,6 +284,9 @@ } else { Some(secret) } + } else if let Some(true) = datesecret { + let ts = chrono::Utc::now(); + Some(format!("{}", ts.date().format("%Y%m%d"))) } else { secret };