@@ -4,7 +4,7 @@ use color_eyre::eyre::Result;
44use figment:: { Figment , providers:: Env } ;
55use serde:: Deserialize ;
66
7- use crate :: { cache:: Cache , database:: Database , handlers:: TaskRabbit , storage:: Storage } ;
7+ use crate :: { cache:: Cache , database:: Database , handlers:: TaskRabbit , ipfs :: IPFSModule , storage:: Storage } ;
88
99pub type State = Arc < AppState > ;
1010
@@ -15,6 +15,7 @@ pub struct AppState {
1515 pub storage : Storage ,
1616 pub cache : Cache ,
1717 pub rabbit : Option < TaskRabbit > ,
18+ pub ipfs : Option < IPFSModule > ,
1819}
1920
2021#[ derive( Deserialize , Debug ) ]
@@ -26,6 +27,7 @@ pub struct AppConfig {
2627 pub s3_car : Option < S3CarConfig > ,
2728 pub github_app : Option < GithubAppConfig > ,
2829 pub amqp : Option < AMQPConfig > ,
30+ pub ipfs : Option < IPFSConfig > ,
2931}
3032
3133#[ derive( Deserialize , Debug ) ]
@@ -79,6 +81,12 @@ pub struct GithubAppConfig {
7981 pub client_secret : String ,
8082}
8183
84+ #[ derive( Deserialize , Debug ) ]
85+ pub struct IPFSConfig {
86+ pub cluster_url : String ,
87+ pub public_cluster_url : String ,
88+ }
89+
8290impl AppState {
8391 pub async fn new ( ) -> Result < Self > {
8492 // let config = Config::builder()
@@ -100,6 +108,8 @@ impl AppState {
100108 . map ( |key| format ! ( "github_app.{}" , key. as_str( ) . to_lowercase( ) ) . into ( ) ) )
101109 . merge ( Env :: prefixed ( "AMQP_" )
102110 . map ( |key| format ! ( "amqp.{}" , key. as_str( ) . to_lowercase( ) ) . into ( ) ) )
111+ . merge ( Env :: prefixed ( "IPFS_" )
112+ . map ( |key| format ! ( "ipfs.{}" , key. as_str( ) . to_lowercase( ) ) . into ( ) ) )
103113 . extract :: < AppConfig > ( )
104114 . expect ( "Failed to load AppConfig configuration" ) ;
105115
@@ -115,12 +125,19 @@ impl AppState {
115125 None
116126 } ;
117127
128+ let ipfs = if let Some ( ipfs) = & config. ipfs {
129+ Some ( IPFSModule :: new ( ipfs. cluster_url . clone ( ) , ipfs. public_cluster_url . clone ( ) ) )
130+ } else {
131+ None
132+ } ;
133+
118134 Ok ( Self {
119135 config,
120136 database,
121137 storage,
122138 cache,
123139 rabbit,
140+ ipfs,
124141 } )
125142 }
126143}
0 commit comments