Files
VoelinClient/crates/voelin-query/src/http.rs
T
Claude e050148a32 Rename the project to Voelin; packages hold only the app, tsgw is a Linux server package
The product is Voelin (app id io.github.faumaray.Voelin), everywhere:
- crates tsc-* -> voelin-* (and voelin-fuzz), the desktop binary
  tsc-desktop -> voelin, the development CLI tsctl -> voelinctl;
- the Android app: applicationId, Kotlin package io.github.faumaray.voelin,
  VoelinApp, libvoelin_android.so (JNI class names follow);
- TSC_* environment variables -> VOELIN_*, Gradle properties tsc.* ->
  voelin.*, signing secrets VOELIN_SIGNING_*;
- the data/config/cache/state folder tsc -> voelin, the keyring service,
  thread names, the dev compose project;
- desktop file, metainfo, icon, Flatpak manifest, NSIS installer, docs.
The gateway keeps its name: bin tsgw (crate voelin-gateway), TSGW_* env
vars, the tsgw.v1+json protocol, the tsgw image. The window title and the
About page show "Voelin <version>" from voelin_platform::APP_NAME.

Packages (scripts/package.sh): the app only (voelin, voelin.exe, APKs,
Flatpak). voelinctl is a development tool and in no package. tsgw is for
servers and now its own Linux package, tsgw_<v>_amd64.deb and
tsgw-<v>-linux-x86_64.tar.gz, with a sandboxed systemd unit
(packaging/linux/tsgw.service; /etc/tsgw config, /var/lib/tsgw state) and
dependencies of its own (no GUI libraries). docs/gateway-admin.md has an
Install section.

Fixes:
- package-windows: makensis on Windows found no file through "D:/a/..."
  paths; pass Windows paths (cygpath -w).
- StartupWMClass is the app id, which the app sets as its X11 WM_CLASS
  (it was the binary name, so desktops could not match the window).
- Gradle wrapper download timeout 10 s -> 60 s (slow proxies).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-26 21:11:17 +00:00

94 lines
2.5 KiB
Rust

//! HTTP WebQuery: `GET /<sid>/<command>?key=value` with an `x-api-key` header,
//! answered with JSON `{"body": [...], "status": {"code": 0, "message": "ok"}}`.
use serde::Deserialize;
use crate::codec::{Command, QueryError, Row};
use crate::{Error, Result};
#[derive(Clone)]
pub struct HttpClient {
http: reqwest::Client,
base: String,
api_key: Option<String>,
sid: u32,
}
#[derive(Deserialize)]
struct Status {
code: u32,
message: String,
#[serde(default)]
extra_message: Option<String>,
#[serde(default)]
failed_permission: Option<serde_json::Value>,
}
#[derive(Deserialize)]
struct Reply {
#[serde(default)]
body: Vec<serde_json::Map<String, serde_json::Value>>,
status: Status,
}
impl HttpClient {
/// `base` is e.g. `http://host:10080`. Without an API key requests run
/// with the server's guest query permissions.
pub fn new(base: &str, api_key: Option<String>, sid: u32) -> Result<Self> {
let http = reqwest::Client::builder().build()?;
Ok(Self { http, base: base.trim_end_matches('/').to_string(), api_key, sid })
}
pub fn set_sid(&mut self, sid: u32) {
self.sid = sid;
}
pub async fn send(&self, cmd: &Command) -> Result<Vec<Row>> {
// Multi-row commands are not expressible as query parameters.
if cmd.rows.len() > 1 {
return Err(Error::Unsupported("multi-row commands over HTTP"));
}
// Instance-level commands have no server id in the path.
let url = if matches!(cmd.name.as_str(), "serverlist" | "version" | "hostinfo") {
format!("{}/{}", self.base, cmd.name)
} else {
format!("{}/{}/{}", self.base, self.sid, cmd.name)
};
let mut params: Vec<(String, String)> = cmd.rows[0].clone();
params.extend(cmd.flags.iter().map(|f| (f.clone(), String::new())));
let mut req = self.http.get(url).query(&params);
if let Some(key) = &self.api_key {
req = req.header("x-api-key", key);
}
let reply: Reply = req.send().await?.json().await?;
if reply.status.code != 0 && reply.status.code != 1281 {
return Err(QueryError {
id: reply.status.code,
msg: reply.status.message,
extra_msg: reply.status.extra_message.or_else(|| {
reply.status.failed_permission.map(|p| format!("missing permission {p}"))
}),
failed_permid: None,
}
.into());
}
Ok(reply
.body
.into_iter()
.map(|obj| {
Row(obj
.into_iter()
.map(|(k, v)| {
let v = match v {
serde_json::Value::String(s) => s,
serde_json::Value::Null => String::new(),
other => other.to_string(),
};
(k, v)
})
.collect())
})
.collect())
}
}