Cotton code
44 lines · 2.3 KB · RustRaw
//! `developer.lookServedBefore` — COTTON DEV ONLY: this copy's `face_settings` as a server deployed before Look serves//! it, with no `type_face` column, for a walk and a UI test of a face chosen there (the owner's iPhone, 23 Nov 2026://! "choosing a font changes nothing" on a live server not yet deployed with the column). The real Cotton refuses it//! by name. The copy takes its object's definition again at its next pull from a server that has the column.//!//! ```text//! developer.lookServedBefore {} → { served: false }//! ```use serde_json::{json, Value};use crate::handle::CottonHandle;use crate::methods::MethodError;pub fn served_before(handle: &CottonHandle, _request: &Value) -> Result<Value, MethodError> {    if handle.flavor() != cotton_core::flavor::Flavor::Dev {        return Err(MethodError::new("not_dev", "developer.lookServedBefore answers only in Cotton Dev"));    }    let workspace = super::cotton_chat::read(&handle.client(), "developer.lookServedBefore", |ctx| Ok(json!(ctx.workspace_id)))?;    let ws = workspace.as_str().unwrap_or_default().to_string();    handle        .client()        .with_writer(|replica| {            let rows = replica                .driver                .all("SELECT definition FROM cotton_table_definitions WHERE workspace_id = ? AND id = 'face_settings'", &[rusqlite::types::Value::Text(ws.clone())])                .map_err(|e| e.to_string())?;            let Some(row) = rows.first() else { return Ok(()) };            let mut definition: Value = serde_json::from_str(row.text("definition").unwrap_or("null")).map_err(|e| e.to_string())?;            if let Some(columns) = definition["columns"].as_array_mut() {                columns.retain(|c| c["key"] != "type_face");            }            if let Some(clear) = definition["seal"]["clear"].as_array_mut() {                clear.retain(|c| c != "type_face");            }            replica                .driver                .run("UPDATE cotton_table_definitions SET definition = ? WHERE workspace_id = ? AND id = 'face_settings'", &[rusqlite::types::Value::Text(definition.to_string()), rusqlite::types::Value::Text(ws.clone())])                .map(|_| ())                .map_err(|e| e.to_string())        })        .map_err(|e| MethodError::new("unwritable", e.to_string()))?;    Ok(json!({ "served": false }))}