feat: OpsxAPI v1.0 全协议接口工作台

- 六协议调试:HTTP/GraphQL/WebSocket/SSE/Socket.IO/MQTT
- 集合树/多标签/多环境变量/历史记录,localStorage 持久化
- 导入:OpenAPI 2/3/3.1、Postman、Apifox、Apipost、cURL、HAR、
  Insomnia、Hoppscotch、Markdown(自动识别,21 个单测覆盖)
- 导出:OpenAPI 3.0 JSON/YAML、Postman v2.1、Markdown 文档、
  全量备份;单请求生成 cURL/fetch/Python/Go 代码
- Gin 服务:HTTP 代理、NDJSON 流式代理(SSE 透传)、
  WebSocket 隧道(浏览器自定义握手 Header)
- 内置产品官网 /home 与用户文档站 /docs(SSR,随二进制交付)
- lucide 图标体系 + 品牌标识(Logo/favicon),明暗双主题
- 环境变量:彩色徽标切换器、管理弹窗、{{ 自动补全
This commit is contained in:
logan committed 2026-09-18 00:16:59 +08:00
commit dec66db5aa
182 files changed
+23377

No files matched your search

+136
View File
@@ -0,0 +1,136 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::{Duration, Instant};
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct BodySpec {
mode: String,
raw: Option<String>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct HttpSpec {
method: String,
url: String,
#[serde(default)]
headers: HashMap<String, String>,
query: Option<HashMap<String, String>>,
body: Option<BodySpec>,
timeout_ms: Option<u64>,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct HttpResult {
status: u16,
headers: HashMap<String, String>,
body: String,
time_ms: u128,
size: usize,
}
#[derive(Debug, Deserialize)]
struct WsSpec {
url: String,
protocols: Option<Vec<String>>,
headers: Option<HashMap<String, String>>,
}
fn validate_http_url(raw: &str) -> Result<url::Url, String> {
let parsed = url::Url::parse(raw).map_err(|e| format!("invalid URL: {e}"))?;
match parsed.scheme() {
"http" | "https" => {}
_ => return Err("only http/https schemes are allowed".into()),
}
match parsed.host_str().unwrap_or("").to_ascii_lowercase().as_str() {
"169.254.169.254" | "metadata.google.internal" => {
return Err("blocked metadata host".into())
}
_ => {}
}
Ok(parsed)
}
#[tauri::command]
async fn http_send(spec: HttpSpec) -> Result<HttpResult, String> {
let mut url = validate_http_url(&spec.url)?;
if let Some(query) = &spec.query {
let mut pairs = url.query_pairs_mut();
for (key, value) in query {
pairs.append_pair(key, value);
}
}
let method = reqwest::Method::from_bytes(spec.method.as_bytes())
.map_err(|e| format!("invalid method: {e}"))?;
let timeout = Duration::from_millis(spec.timeout_ms.unwrap_or(30_000));
let client = reqwest::Client::builder()
.timeout(timeout)
.build()
.map_err(|e| e.to_string())?;
let mut request = client.request(method, url);
for (key, value) in spec.headers {
request = request.header(&key, &value);
}
if let Some(body) = spec.body {
if body.mode != "none" {
request = request.body(body.raw.unwrap_or_default());
}
}
let started = Instant::now();
let response = request.send().await.map_err(|e| e.to_string())?;
let status = response.status().as_u16();
let headers = response
.headers()
.iter()
.map(|(k, v)| (k.to_string(), v.to_str().unwrap_or("").to_string()))
.collect();
let bytes = response.bytes().await.map_err(|e| e.to_string())?;
let size = bytes.len();
let body = String::from_utf8_lossy(&bytes).into_owned();
Ok(HttpResult {
status,
headers,
body,
time_ms: started.elapsed().as_millis(),
size,
})
}
#[tauri::command]
async fn ws_connect(spec: WsSpec) -> Result<String, String> {
let _ = (&spec.protocols, &spec.headers);
// TODO(week2): hold WebSocket sessions in managed state and emit messages.
Err(format!(
"WebSocket native tunnel is not implemented yet for {} (use browser WS in MVP)",
spec.url
))
}
#[tauri::command]
async fn ws_send(session_id: String, data: String) -> Result<(), String> {
let _ = (session_id, data);
Err("WebSocket native send is a Week 2 stub".into())
}
#[tauri::command]
async fn ws_close(session_id: String) -> Result<(), String> {
let _ = session_id;
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
http_send,
ws_connect,
ws_send,
ws_close
])
.run(tauri::generate_context!())
.expect("error while running OpsxAPI desktop");
}
+5
View File
@@ -0,0 +1,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
opsxapi_lib::run();
}