Cotton code
22 lines · 1.3 KB · RustRaw
//! The Bin's databases: the ones this device holds marked removed.use crate::{handle::CottonHandle, methods::MethodError};use serde_json::{json, Value};/// `databases.delete` / `databases.restore`: the creator's act ran on the/// serving Mac, and this device signs no request to one.pub fn act(_handle: &CottonHandle, request: &Value, _restore: bool) -> Result<Value, MethodError> {    request        .get("databaseId")        .and_then(Value::as_str)        .filter(|id| !id.is_empty())        .ok_or_else(|| MethodError::new("database_required", "databaseId is required"))?;    Err(MethodError::new("device_required", "This device has no identity"))}pub(crate) fn records(    client: &crate::shell::client::ClientController,) -> Result<Vec<Value>, String> {    Ok(client.binned_databases()?.into_iter().filter_map(|row| {        let id=row["databaseId"].as_str()?;        Some(json!({"id":format!("database:{id}"),"table":"bin","data":{"title":row["name"],"table":"database","kind":"database","database_id":id,"creator_name":row["creator_name"],"removed_by":row["removed_by"],"can_restore":row["can_restore"],"trashed_at":row["deletedAt"],"binned_at":row["deletedAt"],"kept_until":row["deletedAt"].as_str().and_then(cotton_store::database_bin::kept_until),"state":"database_binned"},"deleted_at":null}))    }).collect())}