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
1 change: 1 addition & 0 deletions pkgs/id/WEB.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Three DaisyUI terminal-inspired themes with `#000000` black backgrounds. Switch
| `/api/new` | POST | Create new file |
| `/api/rename` | POST | Rename file (with optional archive) |
| `/api/copy` | POST | Copy file to new name |
| `/api/files/send` | POST | Send file to another server (server-side transfer, #5346) |
| `/api/download` | POST | Download file content |
| `/api/delete` | POST | Soft-delete file |
| `/api/restore` | POST | Restore deleted file (404 if missing, 409 if not deleted) |
Expand Down
1 change: 1 addition & 0 deletions pkgs/id/crates/id-cli/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,7 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
surfaces,
Some(groups_log.clone()),
seitan_state,
Some(endpoint.clone()),
)
.await?;
publication_surface = Some(surface);
Expand Down
1 change: 1 addition & 0 deletions pkgs/id/crates/id-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ id-groups = { path = "../id-groups", default-features = false }
id-store = { path = "../id-store", default-features = false }
id-sync = { path = "../id-sync", default-features = false }
id-worlds = { path = "../id-worlds", default-features = false }
iroh = "1"
iroh-base = "1"
iroh-blobs = "0.103"
redb = "=4.3.0"
Expand Down
21 changes: 20 additions & 1 deletion pkgs/id/crates/id-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ impl PublicationMounts {
pub struct AppState {
/// The blob store for accessing files.
pub store: Store,
/// This node's own iroh endpoint, when the serving process wired one
/// in (#5346): the server-to-server transfer behind the web send
/// route (`POST /api/files/send`) runs with this endpoint's identity,
/// exactly like the meta protocol's `Send` handler (#5345). `None`
/// for states built outside `id serve` (tests, embedded surfaces) —
/// the send route then answers 503 rather than inventing an identity.
pub transfer_endpoint: Option<iroh::endpoint::Endpoint>,
/// State for collaborative editing sessions.
pub collab: Arc<CollabState>,
/// Asset URLs (with cache-busting hashes).
Expand Down Expand Up @@ -460,6 +467,7 @@ impl AppState {
) -> anyhow::Result<Self> {
Ok(Self {
store,
transfer_endpoint: None,
collab: Arc::new(CollabState::new()),
assets: load_asset_urls(),
peers,
Expand All @@ -484,6 +492,14 @@ impl AppState {
seitan: SeitanState::default(),
})
}

/// Wire the serving node's own endpoint in as the transfer identity
/// for the web send route (#5346). `id serve` passes its endpoint
/// through [`web_routers_with_surface`]; see
/// [`AppState::transfer_endpoint`].
pub fn set_transfer_endpoint(&mut self, endpoint: Option<iroh::endpoint::Endpoint>) {
self.transfer_endpoint = endpoint;
}
}

/// Load asset URLs from the embedded manifest.
Expand Down Expand Up @@ -658,6 +674,7 @@ pub async fn web_routers(
surfaces,
groups_log,
seitan,
None,
)
.await?;
Ok(routers)
Expand Down Expand Up @@ -736,8 +753,9 @@ pub async fn web_routers_with_surface(
surfaces: Vec<Option<String>>,
groups_log: Option<std::path::PathBuf>,
seitan: SeitanState,
transfer_endpoint: Option<iroh::endpoint::Endpoint>,
) -> anyhow::Result<(Vec<Router>, WebSurfaceFactory)> {
let state = match local_events {
let mut state = match local_events {
Some(events) => {
AppState::with_local_events(
store,
Expand All @@ -762,6 +780,7 @@ pub async fn web_routers_with_surface(
.await?
}
};
state.set_transfer_endpoint(transfer_endpoint);
let surface = WebSurfaceFactory {
state: state.clone(),
world: world.clone(),
Expand Down
46 changes: 46 additions & 0 deletions pkgs/id/crates/id-web/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ fn create_router_inner(state: AppState) -> Router {
.route("/api/new", post(new_file_handler))
.route("/api/rename", post(rename_handler))
.route("/api/copy", post(copy_handler))
// Server-to-server send (#5346): the browser carries only file
// references; this node's server performs the transfer itself.
.route("/api/files/send", post(send_file_handler))
.route("/api/download", post(download_handler))
.route("/api/delete", post(delete_handler))
.route("/api/restore", post(restore_handler))
Expand Down Expand Up @@ -2007,6 +2010,49 @@ struct CopyResponse {
hash: String,
}

/// Request body for sending a stored file to another server (#5346).
///
/// The browser carries only references — the file name here, the
/// destination's node ID there — never file bytes: this server performs
/// the transfer itself, with its own identity, through the shared
/// transfer module from #5345 ([`id_sync::transfer::send_file`]).
#[derive(Debug, Deserialize)]
struct SendFileRequest {
/// Name of the stored file on this server.
name: String,
/// Destination server's node ID (64 hex characters), as exposed by
/// the peers surface.
dest: String,
/// Name to register on the destination. Defaults to `name`.
dest_name: Option<String>,
/// Whether an existing, different destination file may be archived
/// and replaced. Conflicts refuse by default, as in CLI/REPL.
#[serde(default)]
replace: bool,
}

/// Response from sending a file to another server (#5346).
///
/// Returned only after the destination has confirmed blob completion
/// and name registration (the transfer module's receipt), so a 200 is
/// never a send that did not land.
#[derive(Debug, Serialize)]
struct SendFileResponse {
/// Name of the file on this (source) server.
name: String,
/// Name registered on the destination.
dest_name: String,
/// Destination server's node ID.
dest: String,
/// Content hash that was transferred.
hash: String,
/// The destination already had the name pointing at this hash;
/// nothing was pushed (a retry of the same send is safe).
already_present: bool,
/// An existing, different destination file was archived and replaced.
replaced: bool,
}

/// Request body for downloading editor content.
#[derive(Debug, Deserialize)]
struct DownloadRequest {
Expand Down
Loading