AT Protocol PDS + AppView + Tauri Desktop Client, 160-char post limit. - PDS (Rust + axum + sqlx) - Auth: createAccount, createSession, refreshSession - Records: createRecord, deleteRecord (race-safe via SELECT FOR UPDATE) - Feed: feed.like.create, feed.repost.create - Sync: getRepo, getBlocks, getLatestCommit, getRecord (with MST proof), listRepos - Identity: resolveHandle - MST: spec-conformant (at-mst crate, 27 tests) - Repo: signed commits, TID counter (monotonic, 4096 wrap safe) - AppView (Rust + axum + sqlx) - Jetstream consumer (WebSocket, exponential backoff, 38k+ events indexed) - REST API: timeline/home (graph-aware), profile, search, post (with thread hydration) - Handle-sync worker (did:plc + did:web) - JSONB embed storage + thread columns (migration 0003) - Like/repost counter cache (migration 0004) - Tauri 2 + Svelte 5 Desktop Client - System tray (Show/Compose/Quit menu) - OS notifications (tauri-plugin-notification) - Auto-update (tauri-plugin-updater, placeholder endpoint) - Window-state (tauri-plugin-window-state) - 160-char compose with live counter - Image/Link embed rendering - LocalStorage-persisted like state - Timeline with poll (prepend new posts) - Custom TitleBar (transparent, no decorations) - Orange/IBM Plex Mono maarcade design Tests: 231 Rust + 9 vitest = 240 passed.
81 lines
2.5 KiB
Rust
81 lines
2.5 KiB
Rust
use anyhow::Result;
|
|
use async_trait::async_trait;
|
|
use at_shared::did::Did;
|
|
|
|
/// Resolve a human-readable handle (`alice.bsky.social`) to its [`Did`].
|
|
///
|
|
/// Distinct from [`DidHandleResolver`], which is the inverse — it resolves
|
|
/// a DID back to its current handle. Both live in the same module so the
|
|
/// AppView's handle-sync worker can plug in a stub for tests.
|
|
#[async_trait]
|
|
pub trait HandleResolver: Send + Sync {
|
|
async fn resolve(&self, handle: &str) -> Result<Option<Did>>;
|
|
}
|
|
|
|
/// Resolve a DID (e.g. `did:plc:...`) to its current handle, if known.
|
|
///
|
|
/// Returns `Ok(None)` — never `Err` — when the handle can't be determined
|
|
/// for legitimate reasons (e.g. unknown DID or unsupported method such as
|
|
/// `did:web:`). `Err(_)` is reserved for genuine network / protocol
|
|
/// failures so the worker can distinguish "nothing to do" from "try again
|
|
/// next pass".
|
|
#[async_trait]
|
|
pub trait DidHandleResolver: Send + Sync {
|
|
async fn resolve_handle(&self, did: &str) -> Result<Option<String>>;
|
|
}
|
|
|
|
pub struct WellKnownResolver {
|
|
pub client: reqwest::Client,
|
|
pub dns_zone: String,
|
|
}
|
|
|
|
impl WellKnownResolver {
|
|
pub fn new(dns_zone: String) -> Self {
|
|
Self {
|
|
client: reqwest::Client::builder()
|
|
.timeout(std::time::Duration::from_secs(5))
|
|
.build()
|
|
.unwrap(),
|
|
dns_zone,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl HandleResolver for WellKnownResolver {
|
|
async fn resolve(&self, handle: &str) -> Result<Option<Did>> {
|
|
if let Some(zone) = handle.strip_prefix('@') {
|
|
if zone.ends_with(&self.dns_zone.trim_start_matches('.')) {
|
|
let user = handle.trim_start_matches('@').trim_end_matches(&self.dns_zone);
|
|
if let Some(did) = self.lookup_local(user).await? {
|
|
return Ok(Some(did));
|
|
}
|
|
}
|
|
}
|
|
if let Ok(resp) = self
|
|
.client
|
|
.get(format!("https://{}/.well-known/atproto-did", handle))
|
|
.send()
|
|
.await
|
|
{
|
|
if resp.status().is_success() {
|
|
let body = resp.text().await?;
|
|
let did: Did = body.trim().parse()?;
|
|
return Ok(Some(did));
|
|
}
|
|
}
|
|
Ok(None)
|
|
}
|
|
}
|
|
|
|
impl WellKnownResolver {
|
|
async fn lookup_local(&self, user: &str) -> Result<Option<Did>> {
|
|
let _ = user;
|
|
Ok(None)
|
|
}
|
|
}
|
|
|
|
pub async fn resolve_handle(handle: &str, resolver: &dyn HandleResolver) -> Result<Option<Did>> {
|
|
resolver.resolve(handle).await
|
|
}
|