style(sidecar): apply rustfmt
Format the sidecar source with `cargo fmt` so the new `cargo fmt --check` CI gate passes on the first run. No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0114TpmrNW4wNXsHq5CR72jQ
This commit is contained in:
@@ -142,7 +142,10 @@ fn persist_token(path: &str, token: &str) -> anyhow::Result<()> {
|
|||||||
let text = fs::read_to_string(path)?;
|
let text = fs::read_to_string(path)?;
|
||||||
let line = format!("auth_token = \"{token}\"");
|
let line = format!("auth_token = \"{token}\"");
|
||||||
|
|
||||||
if text.lines().any(|l| l.trim_start().starts_with("auth_token")) {
|
if text
|
||||||
|
.lines()
|
||||||
|
.any(|l| l.trim_start().starts_with("auth_token"))
|
||||||
|
{
|
||||||
let out: String = text
|
let out: String = text
|
||||||
.lines()
|
.lines()
|
||||||
.map(|l| {
|
.map(|l| {
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
// Persist, then broadcast. `pong` and `ws.hello` are ephemeral chatter, not history.
|
// Persist, then broadcast. `pong` and `ws.hello` are ephemeral chatter, not history.
|
||||||
if ev.kind != "pong" {
|
if ev.kind != "pong" {
|
||||||
let t = ev.value.get("t").and_then(|v| v.as_i64()).unwrap_or_else(now_ms);
|
let t = ev
|
||||||
|
.value
|
||||||
|
.get("t")
|
||||||
|
.and_then(|v| v.as_i64())
|
||||||
|
.unwrap_or_else(now_ms);
|
||||||
let text = ev.value.to_string();
|
let text = ev.value.to_string();
|
||||||
if let Err(e) = event_store.insert_event(t, &ev.kind, &text).await {
|
if let Err(e) = event_store.insert_event(t, &ev.kind, &text).await {
|
||||||
tracing::warn!(error = %e, "failed to persist event");
|
tracing::warn!(error = %e, "failed to persist event");
|
||||||
|
|||||||
@@ -56,10 +56,7 @@ impl Rpc {
|
|||||||
) -> Result<Value, RpcError> {
|
) -> Result<Value, RpcError> {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
|
|
||||||
self.pending
|
self.pending.lock().await.insert(corr_val.to_string(), tx);
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.insert(corr_val.to_string(), tx);
|
|
||||||
|
|
||||||
if !shard.send(command.to_string()).await {
|
if !shard.send(command.to_string()).await {
|
||||||
self.pending.lock().await.remove(corr_val);
|
self.pending.lock().await.remove(corr_val);
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ pub struct Store {
|
|||||||
impl Store {
|
impl Store {
|
||||||
/// Opens (creating if absent) the SQLite database and ensures the schema exists.
|
/// Opens (creating if absent) the SQLite database and ensures the schema exists.
|
||||||
pub async fn open(path: &str) -> anyhow::Result<Self> {
|
pub async fn open(path: &str) -> anyhow::Result<Self> {
|
||||||
let opts = SqliteConnectOptions::from_str(&format!("sqlite://{path}"))?
|
let opts =
|
||||||
.create_if_missing(true);
|
SqliteConnectOptions::from_str(&format!("sqlite://{path}"))?.create_if_missing(true);
|
||||||
|
|
||||||
let pool = SqlitePoolOptions::new()
|
let pool = SqlitePoolOptions::new()
|
||||||
.max_connections(4)
|
.max_connections(4)
|
||||||
@@ -78,7 +78,12 @@ impl Store {
|
|||||||
self.recent(Some("economy.supply"), limit).await
|
self.recent(Some("economy.supply"), limit).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn record_link(&self, account: &str, website_user_id: &str, t: i64) -> anyhow::Result<()> {
|
pub async fn record_link(
|
||||||
|
&self,
|
||||||
|
account: &str,
|
||||||
|
website_user_id: &str,
|
||||||
|
t: i64,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO links (account, website_user_id, linked_t) VALUES (?, ?, ?)
|
"INSERT INTO links (account, website_user_id, linked_t) VALUES (?, ?, ?)
|
||||||
ON CONFLICT(account) DO UPDATE SET website_user_id = excluded.website_user_id, linked_t = excluded.linked_t",
|
ON CONFLICT(account) DO UPDATE SET website_user_id = excluded.website_user_id, linked_t = excluded.linked_t",
|
||||||
|
|||||||
@@ -123,7 +123,8 @@ fn iso_ms(ms: i64) -> Option<String> {
|
|||||||
if ms <= 0 {
|
if ms <= 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
chrono::DateTime::from_timestamp_millis(ms).map(|dt| dt.format("%Y-%m-%dT%H:%M:%SZ").to_string())
|
chrono::DateTime::from_timestamp_millis(ms)
|
||||||
|
.map(|dt| dt.format("%Y-%m-%dT%H:%M:%SZ").to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- gate: protocol check + auth ----
|
// ---- gate: protocol check + auth ----
|
||||||
@@ -174,8 +175,15 @@ async fn gate(State(st): State<AppState>, req: Request, next: Next) -> Response
|
|||||||
|
|
||||||
fn extract_token(req: &Request) -> Option<String> {
|
fn extract_token(req: &Request) -> Option<String> {
|
||||||
// Authorization: Bearer <token>
|
// Authorization: Bearer <token>
|
||||||
if let Some(v) = req.headers().get("authorization").and_then(|h| h.to_str().ok()) {
|
if let Some(v) = req
|
||||||
if let Some(rest) = v.strip_prefix("Bearer ").or_else(|| v.strip_prefix("bearer ")) {
|
.headers()
|
||||||
|
.get("authorization")
|
||||||
|
.and_then(|h| h.to_str().ok())
|
||||||
|
{
|
||||||
|
if let Some(rest) = v
|
||||||
|
.strip_prefix("Bearer ")
|
||||||
|
.or_else(|| v.strip_prefix("bearer "))
|
||||||
|
{
|
||||||
return Some(rest.trim().to_string());
|
return Some(rest.trim().to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,7 +357,10 @@ async fn page_respond(
|
|||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
Json(body): Json<Value>,
|
Json(body): Json<Value>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let message = body.get("message").and_then(|m| m.as_str()).unwrap_or_default();
|
let message = body
|
||||||
|
.get("message")
|
||||||
|
.and_then(|m| m.as_str())
|
||||||
|
.unwrap_or_default();
|
||||||
if message.trim().is_empty() {
|
if message.trim().is_empty() {
|
||||||
return (
|
return (
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::BAD_REQUEST,
|
||||||
@@ -439,7 +450,10 @@ async fn vendors(State(st): State<AppState>, Path(account): Path<String>) -> imp
|
|||||||
|
|
||||||
/// Body: {"code":"AB12CD","websiteUserId":"9931"}. Correlated on `code`.
|
/// Body: {"code":"AB12CD","websiteUserId":"9931"}. Correlated on `code`.
|
||||||
async fn link_confirm(State(st): State<AppState>, Json(body): Json<Value>) -> impl IntoResponse {
|
async fn link_confirm(State(st): State<AppState>, Json(body): Json<Value>) -> impl IntoResponse {
|
||||||
let code = body.get("code").and_then(|c| c.as_str()).unwrap_or_default();
|
let code = body
|
||||||
|
.get("code")
|
||||||
|
.and_then(|c| c.as_str())
|
||||||
|
.unwrap_or_default();
|
||||||
let web_id = body
|
let web_id = body
|
||||||
.get("websiteUserId")
|
.get("websiteUserId")
|
||||||
.and_then(|w| w.as_str())
|
.and_then(|w| w.as_str())
|
||||||
@@ -501,10 +515,7 @@ async fn towncrier_add(State(st): State<AppState>, Json(body): Json<Value>) -> i
|
|||||||
respond(st.rpc.call(&st.shard, cmd, &id).await)
|
respond(st.rpc.call(&st.shard, cmd, &id).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn towncrier_remove(
|
async fn towncrier_remove(State(st): State<AppState>, Path(id): Path<String>) -> impl IntoResponse {
|
||||||
State(st): State<AppState>,
|
|
||||||
Path(id): Path<String>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let cmd = json!({"kind":"towncrier.remove","id":id});
|
let cmd = json!({"kind":"towncrier.remove","id":id});
|
||||||
respond(st.rpc.call(&st.shard, cmd, &id).await)
|
respond(st.rpc.call(&st.shard, cmd, &id).await)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user