Repository navigation
fix(project): a file received from the internet reaches only the internet #2845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e64a91a
3676c24
a1509fb
f308453
9e21be5
baae9d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4669,8 +4669,15 @@ fn add_layer_file(s: &mut Session, path: &str) -> CmdResult { | |
| add_layer_text(s, &text) | ||
| } | ||
|
|
||
| /// Adds a layer from a layer file's JSON. | ||
| /// Adds a layer from a layer file's JSON, read from the user's own disk or given by the user. | ||
| pub(crate) fn add_layer_text(s: &mut Session, text: &str) -> CmdResult { | ||
| let reach = s.file_reach(&Value::Null); | ||
| add_layer_text_within(s, text, reach) | ||
| } | ||
|
|
||
| /// [`add_layer_text`] for a layer file whose addresses reach no wider than `reach` | ||
| /// ([`Session::file_reach`]). | ||
| pub(crate) fn add_layer_text_within(s: &mut Session, text: &str, reach: crate::render::rustgis_tiles::address::Reach) -> CmdResult { | ||
| crate::project::check_format(text, "layer file")?; | ||
| let mut layer: rustgis_map::Layer = serde_json::from_str(text).map_err(|e| format!("not a RustGIS layer file: {e}"))?; | ||
| if layer.dataset.source.as_deref().is_some_and(|source| source.starts_with("geolibre-pending:")) { | ||
|
|
@@ -4685,6 +4692,9 @@ pub(crate) fn add_layer_text(s: &mut Session, text: &str) -> CmdResult { | |
| // A binding in a file is no authority to use a login here. | ||
| crate::s3_connections::clear_bindings(layer.addresses_mut()); | ||
| crate::project::clear_login_bindings(layer.addresses_mut()); | ||
| // Before anything it names is read (the repair below reads it). | ||
| let named = crate::received::hold(layer.addresses_mut(), reach); | ||
| named.say(s, &format!("the layer file '{}'", layer.name)); | ||
| // A fresh id and a unique name in this map; the rest goes through project repair. | ||
| let base = layer.name.clone(); | ||
| let mut i = 1; | ||
|
|
@@ -6870,12 +6880,21 @@ fn add_download(s: &mut Session, p: &Value) -> CmdResult { | |
| let bounds = if service { super::service::bounds_of(p.get("bounds"))? } else { None }; | ||
| let i = s.downloaded.iter().position(|(d, _)| *d == id).ok_or("no such download (it was dropped when another project opened)")?; | ||
| let (_, bytes) = s.downloaded.remove(i); | ||
| let read_at = s.downloaded_reach.iter().position(|(d, _)| *d == id).map(|i| s.downloaded_reach.remove(i).1); | ||
| if p.get("geolibreProject").and_then(Value::as_bool) == Some(true) { | ||
| if bytes.len() > rustgis_map::geolibre::MAX_TEXT { | ||
| return Err("GeoLibre project exceeds 64 MiB".into()); | ||
| } | ||
| let text = String::from_utf8(bytes).map_err(|_| "GeoLibre project must be UTF-8 JSON")?; | ||
| return s.run_part("project.importGeolibre", &json!({"text":text})); | ||
| // Received from where it was read: what it names reaches no wider ([`Session::file_reach`]). | ||
| // The app says where its download connected ([`Session::download_read_at`]; the browser's | ||
| // fetch, by its address's name); one that doesn't say reaches only the internet. | ||
| use crate::render::rustgis_tiles::{address::Reach, cache}; | ||
| let reach = read_at.unwrap_or(Reach::Public).min(cache::ceiling_for(&url)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The browser does call |
||
| let was = s.receiving(Some(reach)); | ||
| let r = s.run_part("project.importGeolibre", &json!({"text":text})); | ||
| s.receiving(was); | ||
| return r; | ||
| } | ||
| if p.get("geolibreLayer").is_some() { | ||
| let name = if b(p, "geolibreZarr") == Some(true) { "zarr.tif".into() } else { url_file_name(&url, &bytes)? }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.