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
8 changes: 8 additions & 0 deletions pkgs/id/crates/id-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ pub struct ServeArgs {
/// Browsers drop `Secure` cookies over plain HTTP, except on localhost.
#[arg(long, env = "ID_WEB_COOKIE_SECURE")]
pub web_cookie_secure: bool,
/// Serve the program gallery stored in this directory (#10003).
///
/// The web interface answers `/api/gallery/records`,
/// `/api/gallery/bundles/<hash>` and `/api/gallery/search` from the
/// verified bundle files (`<content-hash>.idpb`) in the directory.
/// Every file is verified when the server starts.
#[arg(long, env = "ID_GALLERY_DIR", requires = "web")]
pub gallery_dir: Option<std::path::PathBuf>,
/// Host a multiplayer world over Iroh (and `/ws/world` with `--web`).
#[arg(long, requires = "world_admin_token")]
pub world: bool,
Expand Down
16 changes: 16 additions & 0 deletions pkgs/id/crates/id-cli/src/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,22 @@ fn test_cli_parse_web_cookie_secure() {
}
}

#[test]
fn test_cli_parse_gallery_dir_requires_web() {
match Cli::parse_from(["id", "serve", "--web", "--gallery-dir", "/srv/gallery"]).command {
Some(Command::Serve(args)) => assert_eq!(
args.gallery_dir.as_deref(),
Some(std::path::Path::new("/srv/gallery"))
),
_ => panic!("Expected Serve command"),
}
match Cli::parse_from(["id", "serve", "--web"]).command {
Some(Command::Serve(args)) => assert!(args.gallery_dir.is_none()),
_ => panic!("Expected Serve command"),
}
assert!(Cli::try_parse_from(["id", "serve", "--gallery-dir", "/srv/gallery"]).is_err());
}

#[test]
fn test_cli_parse_world_boot_window() {
let cli = Cli::parse_from([
Expand Down
29 changes: 29 additions & 0 deletions pkgs/id/crates/id-cli/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ pub struct ServeOptions {
pub web_token: Option<String>,
/// Mark the directory explorer's session cookies `Secure` (HTTPS in front).
pub web_cookie_secure: bool,
/// Serve the program gallery stored in this directory (#10003).
pub gallery_dir: Option<std::path::PathBuf>,
/// Host a multiplayer world (durable unless `ephemeral`).
pub world: bool,
/// Admin secret required to mint world guest capabilities.
Expand Down Expand Up @@ -1108,6 +1110,7 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
port_explicit,
web_token,
web_cookie_secure,
gallery_dir,
world,
world_admin_token,
world_module,
Expand Down Expand Up @@ -1152,6 +1155,8 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
rebuild with `--features web` to serve it"
);
}
#[cfg(not(feature = "web"))]
let _ = &gallery_dir;
validate_world_options(
world,
world_admin_token.as_deref(),
Expand Down Expand Up @@ -1982,6 +1987,29 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
});
minter
};
// #10003: the program gallery's read surface, from verified
// bundle files in --gallery-dir. A file that no longer verifies
// stops the start rather than being served or skipped.
let gallery = match &gallery_dir {
Some(dir) => {
let registry = id_worlds::program_registry::Registry::open_dir(
dir,
id_worlds::program_registry::AdmitAll,
)
.map_err(|error| {
anyhow::anyhow!("open the gallery in {}: {error}", dir.display())
})?;
status!(
"gallery: {} program bundles from {}",
registry.len(),
dir.display()
);
Some(std::sync::Arc::new(std::sync::RwLock::new(
id_worlds::program_gallery::Gallery::new(registry),
)))
}
None => None,
};
let (web_routers, surface) = id_web::web_routers_with_surface(
store_handle.clone(),
Some(peer_discovery.clone()),
Expand All @@ -1998,6 +2026,7 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
seitan_state,
Some(endpoint.clone()),
Some(std::sync::Arc::clone(&transport_ad_minter)),
gallery,
)
.await?;
publication_surface = Some(surface);
Expand Down
Loading