Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow empty cid in pin model #22

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ impl From<gevulot::Pin> for Pin {
fn from(proto: gevulot::Pin) -> Self {
let mut spec: PinSpec = proto.spec.unwrap().into();
spec.cid = proto
.metadata
.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(),
Expand Down Expand Up @@ -156,7 +156,7 @@ impl From<gevulot::Pin> for Pin {

#[derive(Serialize, Deserialize, Debug)]
pub struct PinSpec {
pub cid: String,
pub cid: Option<String>,
pub bytes: i64,
pub time: i64,
pub redundancy: i64,
Expand All @@ -167,7 +167,7 @@ pub struct PinSpec {
impl From<gevulot::PinSpec> 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,
Expand All @@ -182,6 +182,7 @@ pub struct PinStatus {
pub assigned_workers: Vec<String>,
#[serde(rename = "workerAcks")]
pub worker_acks: Vec<PinAck>,
pub cid: Option<String>,
}

impl From<gevulot::PinStatus> for PinStatus {
Expand All @@ -196,6 +197,7 @@ impl From<gevulot::PinStatus> for PinStatus {
block_height: a.block_height as i64,
})
.collect(),
cid: Some(proto.cid),
}
}
}
Expand Down