refactor: move business logic out of presentation — ReadAssetFile, checksum, auth checks, MetadataValue conversions
This commit is contained in:
@@ -62,3 +62,34 @@ impl Default for StructuredData {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&MetadataValue> for serde_json::Value {
|
||||
fn from(val: &MetadataValue) -> Self {
|
||||
match val {
|
||||
MetadataValue::String(s) => serde_json::Value::String(s.clone()),
|
||||
MetadataValue::Integer(i) => serde_json::json!(*i),
|
||||
MetadataValue::Float(f) => serde_json::json!(*f),
|
||||
MetadataValue::Boolean(b) => serde_json::Value::Bool(*b),
|
||||
MetadataValue::Null => serde_json::Value::Null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Value> for MetadataValue {
|
||||
fn from(val: serde_json::Value) -> Self {
|
||||
match val {
|
||||
serde_json::Value::String(s) => MetadataValue::String(s),
|
||||
serde_json::Value::Number(n) => {
|
||||
if let Some(i) = n.as_i64() {
|
||||
MetadataValue::Integer(i)
|
||||
} else if let Some(f) = n.as_f64() {
|
||||
MetadataValue::Float(f)
|
||||
} else {
|
||||
MetadataValue::Null
|
||||
}
|
||||
}
|
||||
serde_json::Value::Bool(b) => MetadataValue::Boolean(b),
|
||||
_ => MetadataValue::Null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user