Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1190,10 +1190,11 @@ object DataClient {
val slot = if (kind.startsWith("3d")) listOf(hubName, tid, kind, path).joinToString("|") else ""
val begun = if (kind.isNotEmpty()) withContext(Dispatchers.Main) { plots.begin(slot) } else null
val kept = begun?.kept.orEmpty(); val serial = begun?.serial ?: 0
val keptChunks = if (has("keptChunks") && (kind == "board" || kind == "schematic" || kind == "gerbers" || kind == "split")) {
val sendKeptChunks = has("keptChunks") && (kind == "board" || kind == "schematic" || kind == "gerbers" || kind == "split")
val keptChunks = if (sendKeptChunks) {
withContext(Dispatchers.Main) { plots.keptChunkHashes() }
} else emptyList()
val r = try { call("viewer.watch", JSONObject().put("thread", tid).put("kind", kind).apply { if (path.isNotEmpty()) put("path", path); if (kept.isNotEmpty()) put("kept", kept); if (keptChunks.isNotEmpty()) put("keptChunks", JSONArray(keptChunks)); if (board.isNotEmpty()) put("board", board); if (tree.isNotEmpty()) put("tree", tree) }) }
val r = try { call("viewer.watch", JSONObject().put("thread", tid).put("kind", kind).apply { if (path.isNotEmpty()) put("path", path); if (kept.isNotEmpty()) put("kept", kept); if (sendKeptChunks) put("keptChunks", JSONArray(keptChunks)); if (board.isNotEmpty()) put("board", board); if (tree.isNotEmpty()) put("tree", tree) }) }
catch (e: Exception) { if (kind.isNotEmpty()) withContext(Dispatchers.Main) { plots.failed(serial) }; throw e }
if (kind.isEmpty()) return
val keys = r.optJSONArray("keys")?.let { a -> (0 until a.length()).map { a.getString(it) } }.orEmpty()
Expand Down
3 changes: 1 addition & 2 deletions mobile/ios/Backplane/DataViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ extension DataClient {
var serial = 0
if !kind.isEmpty { let b = plots.begin(slot); serial = b.serial; if !b.kept.isEmpty { p["kept"] = b.kept } }
if has("keptChunks") && (kind == "board" || kind == "schematic" || kind == "gerbers" || kind == "split") {
let kc = plots.keptChunkHashes()
if !kc.isEmpty { p["keptChunks"] = kc }
p["keptChunks"] = plots.keptChunkHashes()
}
do {
let r: DWatch = try await call("viewer.watch", p)
Expand Down
4 changes: 1 addition & 3 deletions native/gpui/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,7 @@ async fn session(config:&Config,commands:&mut mpsc::Receiver<Command>,queued:&mu
dock_watch = None;
if request["p"]["force"] != true && request["p"].get("keptChunks").is_none() {
let hashes = crate::screens::plot::kept_chunk_hashes();
if !hashes.is_empty() {
if let Some(obj) = request["p"].as_object_mut() { obj.insert("keptChunks".into(), json!(hashes)); }
}
if let Some(obj) = request["p"].as_object_mut() { obj.insert("keptChunks".into(), json!(hashes)); }
}
}
v.outgoing.insert(rpc_id,method=="view.action"&&is_post(&m));v.rpc_names.insert(rpc_id,m.clone());
Expand Down
2 changes: 1 addition & 1 deletion native/host/src/kicad/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Plots {
let (mesh, parts_at) = had.iter().position(|h| h.0 == ky).map(|i| { let h = had.swap_remove(i); (h.1, h.2) }).unwrap_or_default();
let held_already = fold && st.subs.get(&client).is_some_and(|v| v.iter().any(|s| s.key == ky));
let room = st.subs.get(&client).map_or(0, |v| v.len()) < MAX_WATCH_SOURCES;
let (kc, wch) = if force { (Default::default(), false) } else { match st.client_kept_chunks.get(&client) { Some(s) => (s.clone(), true), None => (Default::default(), false) } };
let (kc, wch) = if force { (Default::default(), false) } else { (st.client_kept_chunks.get(&client).cloned().unwrap_or_default(), true) };
if !held_already && (!fold || room) { st.subs.entry(client).or_default().push(Sub { key: ky.clone(), held: if carries { carry.0.clone() } else { vec![] }, mesh, fresh: true, base: if carries { carry.1.clone() } else { String::new() }, kept: if !force && solid_kind(k) && (kept.0.is_empty() || kept.0 == ky) { kept.1 } else { 0 }, kept_chunks: kc, with_chunk_hashes: wch, parts_at }); }
else if !held_already { continue }
let s = st.srcs.entry(ky.clone()).or_insert_with(|| Src { kind: k, root: root.to_string(), file: f.clone(), ..Default::default() });
Expand Down
33 changes: 30 additions & 3 deletions native/host/src/net/webingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ mod tests {
// a share a native client may open, of a file the browser may not reach: the browser gets the intersection
let far = crate::files::share::create(&hub, "t1", &serde_json::json!({"path": home.join("far-files/L/x.zip").to_string_lossy()})).await.unwrap();
assert!(ask(far["link"].as_str().unwrap().to_string(), c.clone()).await.0.starts_with("HTTP/1.1 403"), "a share opens to a browser only within the browser's roots");
// /blob/<sha256>: unpaired -> 401; paired -> 200 with ETag + immutable private cache; If-None-Match -> 304
hub.register_http(std::sync::Arc::new(crate::files::blob::BlobHttp));
let sha = crate::files::blob::register_bytes(&home, proj.join("mfg/bom.csv"), "text/csv", b"a,b\n");
let blob_route = format!("/blob/{sha}");
assert!(ask(blob_route.clone(), String::new()).await.0.starts_with("HTTP/1.1 401"), "unpaired /blob must be 401");
let (bh, bb) = ask(blob_route.clone(), c.clone()).await;
assert!(bh.starts_with("HTTP/1.1 200") && bb == b"a,b\n", "paired /blob: {bh}");
assert!(bh.contains("Cache-Control: private, max-age=31536000, immutable"), "immutable private cache: {bh}");
assert!(bh.contains("Cross-Origin-Resource-Policy: same-origin"), "corp header: {bh}");
let blob_etag = bh.lines().find_map(|l| l.strip_prefix("ETag: ").map(str::trim).map(str::to_string)).expect("ETag on /blob");
let (bh304, bb304) = ask(blob_route.clone(), format!("{c}If-None-Match: {blob_etag}\r\n")).await;
assert!(bh304.starts_with("HTTP/1.1 304") && bb304.is_empty(), "304 on /blob: {bh304}");

let tag = ask(bom.clone(), c.clone()).await.0.lines().find_map(|l| l.strip_prefix("ETag: ").map(str::to_string)).unwrap();
let device = reg.list()["devices"].as_array().unwrap().iter().find(|d| d["kind"] == "browser").unwrap()["id"].as_str().unwrap().to_string();
assert_eq!(reg.revoke(&device)["ok"], true);
Expand Down Expand Up @@ -503,14 +516,27 @@ where S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send {
} else {
crate::api::HttpReply::text("404 Not Found", "Unavailable")
};
// Only carry the content disposition from the underlying resource.
let mut headers = SECURITY_HEADERS.to_owned();
// Only carry the content disposition (and ETag for immutable /blob/ assets) from the underlying resource.
let is_blob = req.route().starts_with("/blob/");
let mut headers = if is_blob && matches!(result.status, "200 OK" | "304 Not Modified") {
SECURITY_HEADERS.replacen(
"Cache-Control: private, no-store\r\n",
"Cache-Control: private, max-age=31536000, immutable\r\n",
1,
)
} else {
SECURITY_HEADERS.to_owned()
};
for line in result.extra.lines() {
if line.to_ascii_lowercase().starts_with("content-disposition:") {
let lower = line.to_ascii_lowercase();
if lower.starts_with("content-disposition:") || (is_blob && lower.starts_with("etag:")) {
headers.push_str(line.trim_end());
headers.push_str("\r\n");
}
}
if is_blob {
headers.push_str("Cross-Origin-Resource-Policy: same-origin\r\n");
}
if result.ctype.eq_ignore_ascii_case("image/svg+xml") {
headers.push_str("Content-Disposition: attachment\r\n");
}
Expand Down Expand Up @@ -572,6 +598,7 @@ fn is_browser_ws_target(target: &str) -> bool {

fn is_protected_asset(path: &str) -> bool {
matches!(path, "/files/get" | "/message-image") ||
path.strip_prefix("/blob/").is_some_and(|h| h.len() == 64 && h.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f'))) ||
path.strip_prefix("/bots/").and_then(|p| p.strip_suffix("/screen.jpg"))
.is_some_and(|id| !id.is_empty() && id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_'))
}
Expand Down
2 changes: 1 addition & 1 deletion web/dist/assets/app.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions web/dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 1,
"totalAssetGzipBytes": 176221,
"totalAssetGzipBytes": 176216,
"styleTokensSha256": "a4fed1b1c7bc676acc328907343eb5dcf87e426383d05617c632e48c0c3f2b80",
"i18nKeys": [
"agy.signout",
Expand Down Expand Up @@ -223,7 +223,7 @@
"web/src/viewers/solid3d.ts": "9e82abfe611d41917e70d315cc86047f5a9f99e6cb4df051cdec117078026e21",
"web/src/viewers/terminal-state.ts": "316d9c82b63c9d7a73aa3063957b3a2b578ff2ca735a6f32cf290a92cf10ddc2",
"web/src/viewers/terminal.ts": "dead59ace15647f726f5d7c4dad0a430fa63c82481c4399f40d17f01e5805099",
"web/src/viewers/viewer-pane.ts": "f4981d838e2b2dd12281681ed7e8d854136bf58808d394353150d20e26a4684b",
"web/src/viewers/viewer-pane.ts": "0021e2ac702c7b4960f685d822b6f3cf4728589b4cca54498556695de7ddb1eb",
"web/src/viewers/viewer-tools.ts": "7db4587ad1410cf21364b1121454e0520fd515c82b63916d31a5fdc1443615b4",
"web/src/voice.ts": "f401f1d5bd1685c7d7270fc02a8ff16f54bde7ae98aee21b4e802f0357063345",
"web/src/ws.ts": "58d6701077833fd5713854427245d9ad35d23a042e35df581a490c36bfd36e90",
Expand All @@ -238,9 +238,9 @@
},
"outputs": {
"assets/app.js": {
"bytes": 262037,
"gzipBytes": 74997,
"sha256": "303dd9435d4345a553d3fa24d777d3e802e3e413c81a6ba5f8bbb60f085cd24b"
"bytes": 262027,
"gzipBytes": 74992,
"sha256": "13ea90a87cb19f0f5264f57112ad64acfac5e8e300a0d47783e692b4cfb0e905"
},
"assets/favicon-light.svg": {
"bytes": 1207,
Expand Down
2 changes: 1 addition & 1 deletion web/src/viewers/viewer-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ export function mountViewerPane(container: HTMLElement, api: ViewerHostApi): {
const kept = solid3d.keptToken();
if (kept) params.kept = kept;
}
if ((page === "board" || page === "schematic" || page === "gerbers") && !force && api.hub.hasFeature("keptChunks") && chunkCache.size > 0) {
if ((page === "board" || page === "schematic" || page === "gerbers") && !force && api.hub.hasFeature("keptChunks")) {
params.keptChunks = Array.from(chunkCache.keys());
}
}
Expand Down
Loading