@@ -13,6 +13,8 @@ use std::{collections::HashMap, io::Write, str::FromStr};
1313use tokio:: { io:: AsyncReadExt , net:: TcpListener , runtime:: Handle } ;
1414use tracing:: metadata:: Level ;
1515
16+ const DEFAULT_COLLECTION_ID : & str = "default-collection-id" ;
17+
1618/// stacrs: A command-line interface for the SpatioTemporal Asset Catalog (STAC)
1719#[ derive( Debug , Parser ) ]
1820pub struct Stacrs {
@@ -349,7 +351,7 @@ impl Stacrs {
349351 if let Some ( collection) = item. collection . clone ( ) {
350352 items. entry ( collection) . or_default ( ) . push ( item) ;
351353 } else {
352- return Err ( anyhow ! ( "item without a collection: {item:?}" ) ) ;
354+ items . entry ( String :: new ( ) ) . or_default ( ) . push ( item ) ;
353355 }
354356 }
355357 }
@@ -561,7 +563,17 @@ async fn load_and_serve(
561563 }
562564 }
563565 if create_collections {
564- for ( collection_id, items) in items {
566+ for ( mut collection_id, mut items) in items {
567+ if collection_id. is_empty ( ) {
568+ if backend. collection ( DEFAULT_COLLECTION_ID ) . await ?. is_some ( ) {
569+ return Err ( anyhow ! ( "cannot auto-create collections, a collection already exists with id={DEFAULT_COLLECTION_ID}" ) ) ;
570+ } else {
571+ collection_id = DEFAULT_COLLECTION_ID . to_string ( ) ;
572+ }
573+ }
574+ for item in & mut items {
575+ item. collection = Some ( collection_id. to_string ( ) ) ;
576+ }
565577 let collection = Collection :: from_id_and_items ( collection_id, & items) ;
566578 backend. add_collection ( collection) . await ?;
567579 backend. add_items ( items) . await ?;
0 commit comments