From b2e332f458a1a7ecb174bedc8051df8f609be52b Mon Sep 17 00:00:00 2001 From: Tino Rusch Date: Thu, 28 Nov 2024 12:49:46 +0100 Subject: [PATCH 1/2] allow empty cid in pin model --- src/models.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/models.rs b/src/models.rs index a0d39bf..28f9b4e 100644 --- a/src/models.rs +++ b/src/models.rs @@ -109,11 +109,10 @@ pub struct Pin { impl From for Pin { fn from(proto: gevulot::Pin) -> Self { let mut spec: PinSpec = proto.spec.unwrap().into(); - spec.cid = proto - .metadata + spec.cid = proto.status .as_ref() - .map(|m| m.id.clone()) - .unwrap_or_default(); + .map(|s| s.cid.clone()) + .or_else(|| proto.metadata.as_ref().map(|m| m.id.clone())); Pin { kind: "Pin".to_string(), version: "v0".to_string(), @@ -156,7 +155,7 @@ impl From for Pin { #[derive(Serialize, Deserialize, Debug)] pub struct PinSpec { - pub cid: String, + pub cid: Option, pub bytes: i64, pub time: i64, pub redundancy: i64, @@ -167,7 +166,7 @@ pub struct PinSpec { impl From for PinSpec { fn from(proto: gevulot::PinSpec) -> Self { PinSpec { - cid: "".to_string(), + cid: None, bytes: proto.bytes as i64, time: proto.time as i64, redundancy: proto.redundancy as i64, @@ -182,6 +181,7 @@ pub struct PinStatus { pub assigned_workers: Vec, #[serde(rename = "workerAcks")] pub worker_acks: Vec, + pub cid: Option, } impl From for PinStatus { @@ -196,6 +196,7 @@ impl From for PinStatus { block_height: a.block_height as i64, }) .collect(), + cid: Some(proto.cid) } } } From 1326f48be6ab12d8169c4b279fe342a246b37cae Mon Sep 17 00:00:00 2001 From: Tino Rusch Date: Thu, 28 Nov 2024 12:53:38 +0100 Subject: [PATCH 2/2] cargo fmt --- src/models.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/models.rs b/src/models.rs index 28f9b4e..afe38bc 100644 --- a/src/models.rs +++ b/src/models.rs @@ -109,7 +109,8 @@ pub struct Pin { impl From for Pin { fn from(proto: gevulot::Pin) -> Self { let mut spec: PinSpec = proto.spec.unwrap().into(); - spec.cid = proto.status + spec.cid = proto + .status .as_ref() .map(|s| s.cid.clone()) .or_else(|| proto.metadata.as_ref().map(|m| m.id.clone())); @@ -196,7 +197,7 @@ impl From for PinStatus { block_height: a.block_height as i64, }) .collect(), - cid: Some(proto.cid) + cid: Some(proto.cid), } } }