@@ -16,13 +16,14 @@ use axum::{
1616 Router ,
1717} ;
1818use futures:: StreamExt ;
19- use std:: path:: PathBuf ;
2019use std:: sync:: Arc ;
20+ use std:: { collections:: HashMap , path:: PathBuf } ;
2121use tempfile:: NamedTempFile ;
2222use tokio:: io:: AsyncWriteExt ;
2323use url:: Url ;
2424use warg_api:: v1:: package:: {
25- ContentSource , PackageError , PackageRecord , PackageRecordState , PublishRecordRequest ,
25+ ContentSource , MissingContent , PackageError , PackageRecord , PackageRecordState ,
26+ PublishRecordRequest , UploadEndpoint ,
2627} ;
2728use warg_crypto:: hash:: { AnyHash , Sha256 } ;
2829use warg_protocol:: {
@@ -91,6 +92,25 @@ impl Config {
9192 . unwrap ( )
9293 . to_string ( )
9394 }
95+
96+ fn build_missing_content < ' a > (
97+ & self ,
98+ missing_digests : impl IntoIterator < Item = & ' a AnyHash > ,
99+ ) -> HashMap < AnyHash , MissingContent > {
100+ missing_digests
101+ . into_iter ( )
102+ . map ( |digest| {
103+ (
104+ digest. clone ( ) ,
105+ MissingContent {
106+ upload : vec ! [ UploadEndpoint :: HttpPost {
107+ url: self . content_url( digest) ,
108+ } ] ,
109+ } ,
110+ )
111+ } )
112+ . collect ( )
113+ }
94114}
95115
96116struct PackageApiError ( PackageError ) ;
@@ -231,13 +251,12 @@ async fn publish_record(
231251 ) ) ;
232252 }
233253
254+ let missing_content = config. build_missing_content ( missing) ;
234255 Ok ( (
235256 StatusCode :: ACCEPTED ,
236257 Json ( PackageRecord {
237258 id : record_id,
238- state : PackageRecordState :: Sourcing {
239- missing_content : missing. into_iter ( ) . cloned ( ) . collect ( ) ,
240- } ,
259+ state : PackageRecordState :: Sourcing { missing_content } ,
241260 } ) ,
242261 ) )
243262}
@@ -254,12 +273,13 @@ async fn get_record(
254273 . await ?;
255274
256275 match record. status {
257- RecordStatus :: MissingContent ( missing) => Ok ( Json ( PackageRecord {
258- id : record_id,
259- state : PackageRecordState :: Sourcing {
260- missing_content : missing,
261- } ,
262- } ) ) ,
276+ RecordStatus :: MissingContent ( missing) => {
277+ let missing_content = config. build_missing_content ( & missing) ;
278+ Ok ( Json ( PackageRecord {
279+ id : record_id,
280+ state : PackageRecordState :: Sourcing { missing_content } ,
281+ } ) )
282+ }
263283 // Validated is considered still processing until included in a checkpoint
264284 RecordStatus :: Pending | RecordStatus :: Validated => Ok ( Json ( PackageRecord {
265285 id : record_id,
@@ -275,11 +295,11 @@ async fn get_record(
275295 . as_ref ( )
276296 . contents ( )
277297 . into_iter ( )
278- . map ( |d | {
298+ . map ( |digest | {
279299 (
280- d . clone ( ) ,
300+ digest . clone ( ) ,
281301 vec ! [ ContentSource :: Http {
282- url: config. content_url( d ) ,
302+ url: config. content_url( digest ) ,
283303 } ] ,
284304 )
285305 } )
@@ -363,7 +383,7 @@ async fn upload_content(
363383 {
364384 config
365385 . core_service
366- . submit_package_record ( log_id, record_id. clone ( ) )
386+ . submit_package_record ( log_id, record_id)
367387 . await ;
368388 }
369389
0 commit comments