π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make client package optional, add ApiConfig::new
Manav Rathidd28a2bb9572
diff --git a/rust/crates/core/examples/ping.rs b/rust/crates/core/examples/ping.rsindex 64c3d0b847..4664e6db15 100644--- a/rust/crates/core/examples/ping.rs+++ b/rust/crates/core/examples/ping.rs@@ -12,13 +12,7 @@ async fn main() {let api = Api::new(Http::new().expect("failed to build HTTP client"),- ApiConfig {- origin,- client_package: "io.ente.example".into(),- client_version: None,- user_agent: None,- auth: None,- },+ ApiConfig::new(origin),);match api.ping().await {diff --git a/rust/crates/core/src/http.rs b/rust/crates/core/src/http.rsindex d53e3635ed..5ab94bae87 100644--- a/rust/crates/core/src/http.rs+++ b/rust/crates/core/src/http.rs@@ -219,7 +219,7 @@ pub struct ApiConfig {/// The Ente API origin: scheme, host, and port, e.g. `https://api.ente.com`.pub origin: String,/// The client package, sent as `X-Client-Package` (e.g. `io.ente.photos`).- pub client_package: String,+ pub client_package: Option<String>,/// The client version, sent as `X-Client-Version`.pub client_version: Option<String>,/// The user agent to send.@@ -228,6 +228,19 @@ pub struct ApiConfig {pub auth: Option<Auth>,}+impl ApiConfig {+ /// Config with only the origin set.+ pub fn new(origin: String) -> Self {+ Self {+ origin,+ client_package: None,+ client_version: None,+ user_agent: None,+ auth: None,+ }+ }+}+/// An Ente API client, bound to a single origin.////// Requests take a path relative to that origin and automatically carry the Ente@@ -235,7 +248,7 @@ pub struct ApiConfig {pub struct Api {http: Http,origin: String,- client_package: String,+ client_package: Option<String>,client_version: Option<String>,user_agent: Option<String>,auth: RwLock<Option<Auth>>,@@ -308,7 +321,9 @@ impl Api {// reqwest hits the same parse failure, and reports it at send time.Err(_) => self.http.client.request(method, self.origin.as_str()),};- builder = builder.header(CLIENT_PACKAGE, &self.client_package);+ if let Some(client_package) = &self.client_package {+ builder = builder.header(CLIENT_PACKAGE, client_package);+ }if let Some(version) = &self.client_version {builder = builder.header(CLIENT_VERSION, version);}@@ -458,11 +473,10 @@ mod tests {Api::new(Http::new().unwrap(),ApiConfig {- origin: server.url(),- client_package: "io.ente.test".into(),+ client_package: Some("io.ente.test".into()),client_version: Some("1.0".into()),- user_agent: None,auth,+ ..ApiConfig::new(server.url())},)}@@ -705,16 +719,7 @@ mod tests {#[tokio::test]async fn malformed_origin_fails_at_send() {- let api = Api::new(- Http::new().unwrap(),- ApiConfig {- origin: "not a url".into(),- client_package: "io.ente.test".into(),- client_version: None,- user_agent: None,- auth: None,- },- );+ let api = Api::new(Http::new().unwrap(), ApiConfig::new("not a url".into()));let err = api.get("/ping").send().await.unwrap_err();assert!(matches!(err, Error::Network(_)));}@@ -730,13 +735,7 @@ mod tests {let api = Api::new(Http::new().unwrap(),- ApiConfig {- origin: format!("{}/", server.url()),- client_package: "io.ente.test".into(),- client_version: None,- user_agent: None,- auth: None,- },+ ApiConfig::new(format!("{}/", server.url())),);api.ping().await.unwrap();