1
1
use serde:: { Deserialize , Serialize } ;
2
2
use sha1_smol:: Digest ;
3
+ use std:: collections:: HashMap ;
3
4
4
5
use super :: ChunkedFileState ;
5
6
@@ -13,16 +14,85 @@ pub struct ChunkedArtifactRequest<'a> {
13
14
pub version : Option < & ' a str > ,
14
15
#[ serde( skip_serializing_if = "Option::is_none" ) ]
15
16
pub dist : Option < & ' a str > ,
17
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
18
+ pub filename : Option < String > ,
19
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
20
+ pub project_id : Option < String > ,
16
21
}
17
22
18
23
#[ derive( Debug , Deserialize ) ]
19
24
#[ serde( rename_all = "camelCase" ) ]
20
- pub struct AssembleArtifactsResponse {
25
+ pub struct ChunkedArtifactResponse {
21
26
pub state : ChunkedFileState ,
22
27
pub missing_chunks : Vec < Digest > ,
23
28
pub detail : Option < String > ,
24
29
}
25
30
31
+ #[ derive( Debug , Serialize ) ]
32
+ #[ serde( transparent) ]
33
+ pub struct AssembleArtifactsRequest < ' a > ( HashMap < Digest , ChunkedArtifactRequest < ' a > > ) ;
34
+
35
+ impl < ' a , T > FromIterator < T > for AssembleArtifactsRequest < ' a >
36
+ where
37
+ T : Into < ChunkedArtifactRequest < ' a > > ,
38
+ {
39
+ fn from_iter < I > ( iter : I ) -> Self
40
+ where
41
+ I : IntoIterator < Item = T > ,
42
+ {
43
+ Self (
44
+ iter. into_iter ( )
45
+ . map ( |obj| obj. into ( ) )
46
+ . map ( |r| ( r. checksum , r) )
47
+ . collect ( ) ,
48
+ )
49
+ }
50
+ }
51
+
52
+ pub type AssembleArtifactsResponse = ChunkedArtifactResponse ;
53
+
54
+ #[ derive( Debug , Serialize ) ]
55
+ pub struct ChunkedPreprodArtifactRequest < ' a > {
56
+ pub checksum : Digest ,
57
+ pub chunks : & ' a [ Digest ] ,
58
+ // Optional metadata fields that the server supports
59
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
60
+ pub build_version : Option < & ' a str > ,
61
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
62
+ pub build_number : Option < i32 > ,
63
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
64
+ pub build_configuration : Option < & ' a str > ,
65
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
66
+ pub date_built : Option < & ' a str > ,
67
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
68
+ pub extras : Option < serde_json:: Value > ,
69
+ }
70
+
71
+ impl < ' a > ChunkedPreprodArtifactRequest < ' a > {
72
+ /// Create a new ChunkedPreprodArtifactRequest with the required fields.
73
+ pub fn new ( checksum : Digest , chunks : & ' a [ Digest ] ) -> Self {
74
+ Self {
75
+ checksum,
76
+ chunks,
77
+ build_version : None ,
78
+ build_number : None ,
79
+ build_configuration : None ,
80
+ date_built : None ,
81
+ extras : None ,
82
+ }
83
+ }
84
+ }
85
+
86
+ #[ derive( Debug , Deserialize ) ]
87
+ #[ serde( rename_all = "camelCase" ) ]
88
+ pub struct ChunkedPreprodArtifactResponse {
89
+ pub state : ChunkedFileState ,
90
+ pub missing_chunks : Vec < Digest > ,
91
+ pub detail : Option < String > ,
92
+ }
93
+
94
+ pub type AssemblePreprodArtifactsResponse = HashMap < Digest , ChunkedPreprodArtifactResponse > ;
95
+
26
96
fn version_is_empty ( version : & Option < & str > ) -> bool {
27
97
match version {
28
98
Some ( v) => v. is_empty ( ) ,
0 commit comments