@@ -53,7 +53,6 @@ use common::{
5353 } ,
5454 document:: {
5555 DocumentUpdate ,
56- ParsedDocument ,
5756 CREATION_TIME_FIELD_PATH ,
5857 } ,
5958 errors:: {
@@ -122,6 +121,7 @@ use database::{
122121 Transaction ,
123122 WriteSource ,
124123} ;
124+ use either:: Either ;
125125use errors:: {
126126 ErrorMetadata ,
127127 ErrorMetadataAnyhowExt ,
@@ -1373,39 +1373,32 @@ impl<RT: Runtime> Application<RT> {
13731373 pub async fn get_zip_export (
13741374 & self ,
13751375 identity : Identity ,
1376- snapshot_ts : Timestamp ,
1376+ id : Either < DeveloperDocumentId , Timestamp > ,
13771377 ) -> anyhow:: Result < ( StorageGetStream , String ) > {
1378- let stream = self . get_export_inner ( identity, snapshot_ts) . await ?;
1379- let filename = format ! (
1380- // This should match the format in SnapshotExport.tsx.
1381- "snapshot_{}_{snapshot_ts}.zip" ,
1382- self . instance_name
1383- ) ;
1384- Ok ( ( stream, filename) )
1385- }
1386-
1387- async fn get_export_inner (
1388- & self ,
1389- identity : Identity ,
1390- snapshot_ts : Timestamp ,
1391- ) -> anyhow:: Result < StorageGetStream > {
1392- let object_key = {
1378+ let ( object_key, snapshot_ts) = {
13931379 let mut tx = self . begin ( identity) . await ?;
1394- let export_doc = ExportsModel :: new ( & mut tx)
1395- . completed_export_at_ts ( snapshot_ts)
1396- . await ?;
1397- let export: ParsedDocument < Export > = export_doc
1398- . context ( ErrorMetadata :: not_found (
1399- "ExportNotFound" ,
1400- format ! ( "The requested export {snapshot_ts} was not found" ) ,
1401- ) ) ?
1402- . try_into ( ) ?;
1380+ let export = match id {
1381+ Either :: Left ( id) => ExportsModel :: new ( & mut tx) . get ( id) . await ?,
1382+ Either :: Right ( ts) => {
1383+ ExportsModel :: new ( & mut tx)
1384+ . completed_export_at_ts ( ts)
1385+ . await ?
1386+ } ,
1387+ }
1388+ . context ( ErrorMetadata :: not_found (
1389+ "ExportNotFound" ,
1390+ format ! ( "The requested export {id} was not found" ) ,
1391+ ) ) ?;
14031392 match export. into_value ( ) {
1404- Export :: Completed { zip_object_key, .. } => zip_object_key,
1393+ Export :: Completed {
1394+ zip_object_key,
1395+ start_ts,
1396+ ..
1397+ } => ( zip_object_key, start_ts) ,
14051398 Export :: Failed { .. } | Export :: InProgress { .. } | Export :: Requested { .. } => {
14061399 anyhow:: bail!( ErrorMetadata :: bad_request(
14071400 "ExportNotComplete" ,
1408- format!( "The requested export {snapshot_ts } has not completed" ) ,
1401+ format!( "The requested export {id } has not completed" ) ,
14091402 ) )
14101403 } ,
14111404 }
@@ -1418,7 +1411,13 @@ impl<RT: Runtime> Application<RT> {
14181411 "ExportNotFound" ,
14191412 format ! ( "The requested export {snapshot_ts}/{object_key:?} was not found" ) ,
14201413 ) ) ?;
1421- Ok ( storage_get_stream)
1414+
1415+ let filename = format ! (
1416+ // This should match the format in SnapshotExport.tsx.
1417+ "snapshot_{}_{snapshot_ts}.zip" ,
1418+ self . instance_name
1419+ ) ;
1420+ Ok ( ( storage_get_stream, filename) )
14221421 }
14231422
14241423 /// Returns the cloud export key - fully qualified to the instance.
0 commit comments