chore: restart the repository with a clean history
CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s

Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
This commit is contained in:
fristy committed 2026-11-10 11:31:13 +03:00
commit 650807c1fb
438 files changed
+45070

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
use anyhow::{bail, Result};
use reqwest::Client;
use serde::Deserialize;
pub struct ApiClient {
client: Client,
base_url: String,
token: Option<String>,
}
#[derive(Deserialize)]
pub struct ServerInfo { pub name: String, pub version: String, #[serde(rename = "baseDomain")] pub base_domain: String }
#[derive(Deserialize)]
pub struct DeviceRequest {
pub code: String,
#[serde(rename = "pollToken")] pub poll_token: String,
#[serde(rename = "handoffUrl")] pub handoff_url: String,
}
#[derive(Deserialize)]
pub struct DevicePoll { pub status: String, pub token: Option<String> }
impl ApiClient {
pub fn new(base_url: &str, token: Option<&str>, accept_invalid_certs: bool) -> Result<Self> {
Ok(Self {
client: Client::builder().danger_accept_invalid_certs(accept_invalid_certs).build()?,
base_url: base_url.trim_end_matches('/').to_string(),
token: token.map(|t| t.to_string()),
})
}
fn url(&self, path: &str) -> String { format!("{}/@frislit/api{}", self.base_url, path) }
pub async fn info(&self) -> Result<ServerInfo> {
let resp = self.client.get(self.url("/info")).send().await?;
if !resp.status().is_success() { bail!("Server did not answer like a frislit server ({})", resp.status()); }
Ok(resp.json().await?)
}
pub async fn device_create(&self, client: &str) -> Result<DeviceRequest> {
let response = self.client.post(self.url("/auth/device/create"))
.json(&serde_json::json!({ "client": client })).send().await?;
if !response.status().is_success() { bail!("Could not start the login ({})", response.status()); }
Ok(response.json().await?)
}
pub async fn device_poll(&self, poll_token: &str) -> Result<DevicePoll> {
let response = self.client.post(self.url("/auth/device/poll"))
.json(&serde_json::json!({ "pollToken": poll_token })).send().await?;
if !response.status().is_success() { bail!("Could not check the login ({})", response.status()); }
Ok(response.json().await?)
}
pub async fn get<T: serde::de::DeserializeOwned>(&self, path: &str) -> Result<T> {
let token = self.token.as_deref().ok_or_else(|| anyhow::anyhow!("Not authenticated"))?;
let response = self.client.get(self.url(path)).header("Authorization", format!("Bearer {token}")).send().await?;
match response.status().as_u16() {
200 => Ok(response.json().await?),
401 => bail!("This device is not linked any more. Run `frislit login`"),
other => bail!("Unexpected response from server: {other}"),
}
}
pub async fn whoami(&self) -> Result<Me> {
self.get("/whoami").await
}
}
#[derive(serde::Deserialize)]
pub struct Me { pub username: String, pub guest: Option<String> }
impl Me {
pub fn label(&self) -> String {
match &self.guest { Some(guest) => format!("{guest} (guest of {})", self.username), None => self.username.clone() }
}
}
pub fn ws_url(base_url: &str) -> String {
let base = base_url.trim_end_matches('/').replacen("https://", "wss://", 1).replacen("http://", "ws://", 1);
format!("{base}/@frislit/ws")
}