feat: OpsxDB 桌面数据库客户端首版入库

含工作台/连库多引擎字段与 SSH·SSL、结果编辑、Redis 键浏览、
Tauri 桌面与 docs/落地页;排除本地构建产物与 sidecar 二进制。
This commit is contained in:
logan committed 2026-09-19 22:43:45 +08:00
commit f8740d27f7
240 files changed
+21625

No files matched your search

+220
View File
@@ -0,0 +1,220 @@
{
"name": "@opsxdb/desktop",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@opsxdb/desktop",
"version": "0.1.0",
"devDependencies": {
"@tauri-apps/cli": "^2.4.0"
}
},
"node_modules/@tauri-apps/cli": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli/-/cli-2.11.4.tgz",
"integrity": "sha512-R8xGtMpwyetawSqm9kYOuMmEqkhUbvcUy8n0aNXIxollKBLESUu5f4Fx+64hgASYm1H+jSWq6jCW6zqTnH6hqQ==",
"dev": true,
"bin": {
"tauri": "tauri.js"
},
"engines": {
"node": ">= 10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/tauri"
},
"optionalDependencies": {
"@tauri-apps/cli-darwin-arm64": "2.11.4",
"@tauri-apps/cli-darwin-x64": "2.11.4",
"@tauri-apps/cli-linux-arm-gnueabihf": "2.11.4",
"@tauri-apps/cli-linux-arm64-gnu": "2.11.4",
"@tauri-apps/cli-linux-arm64-musl": "2.11.4",
"@tauri-apps/cli-linux-riscv64-gnu": "2.11.4",
"@tauri-apps/cli-linux-x64-gnu": "2.11.4",
"@tauri-apps/cli-linux-x64-musl": "2.11.4",
"@tauri-apps/cli-win32-arm64-msvc": "2.11.4",
"@tauri-apps/cli-win32-ia32-msvc": "2.11.4",
"@tauri-apps/cli-win32-x64-msvc": "2.11.4"
}
},
"node_modules/@tauri-apps/cli-darwin-arm64": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.11.4.tgz",
"integrity": "sha512-1ryOF3ZhpZ/nemHV5zVwBQBz9jDGKmKPvWPADOhc83ig0P4bMc2iER4NbC6r9sjeIZ6RVQ4g3RZIYvezhcl4TQ==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-darwin-x64": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.11.4.tgz",
"integrity": "sha512-uFsGQAAfuyz1k/yGLmkWfkBlgKAqZfxqlHmLWx81QU27RJWfmbNHCIq8T8w1e+VClleIuZUjpHWfoE4E3DLo3A==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-arm-gnueabihf": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.11.4.tgz",
"integrity": "sha512-IaHZn5CdBL21oUmjiVOS1ctw6Ip1O0pjp70FwOWmYz1myWe0SY96ZIj2FYf7pT0m8bI2h/hrs5ZbEXXh44/MkQ==",
"cpu": [
"arm"
],
"dev": true,
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-arm64-gnu": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.11.4.tgz",
"integrity": "sha512-N41/ukTRVe6XSuUTESuFdGeOW2i7k62tK+6gHK5Kd5/q5RPvvi19GaWAVPPb9u95HSGmTChSolBfzynUsssFaA==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-arm64-musl": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.11.4.tgz",
"integrity": "sha512-v277UnT/fB64xAfSroL5N3Km3tLmvATWqJJw/wRI+g6o+HkeD0slyE7gOhNs1MbjE41R7bQOTxMVoL3aomUJmw==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-riscv64-gnu": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-riscv64-gnu/-/cli-linux-riscv64-gnu-2.11.4.tgz",
"integrity": "sha512-qqgNkQ2u1yZHxjhxsZaxUtRDW8dIqIYm33rx/mzwQv0SfY9x1B+iraj8vWeFiXjjSVVhEMepXSOts1TqPzvXNQ==",
"cpu": [
"riscv64"
],
"dev": true,
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-x64-gnu": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.11.4.tgz",
"integrity": "sha512-2VRNWl84FOH0m2giiDkO2h0QXlcMJeX+zJDpI5kDIQAx6s+geF3v48F4DXfJez4GS/FdoDGnPnw1C2iYGbQ7bQ==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-linux-x64-musl": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.11.4.tgz",
"integrity": "sha512-o9GyhYor/nc7xarmwDE3ka2szuW3uuZzXjHWh64Q8YX5AtSgxdQkFWzrY4O8KiGtVNvFBI14H3Q49Qj5TOIP/A==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-win32-arm64-msvc": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-2.11.4.tgz",
"integrity": "sha512-ld5Ehb598m0VkYyylRPNeCFsBe/km0jxis6KgMpl3IGY6I/i1RwQXO05I1AsXUXO2WC6AvB/Lw4qTf/asiuEiQ==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-win32-ia32-msvc": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.11.4.tgz",
"integrity": "sha512-12Hxi0XX/H5VFxO/bGgHkFWhml9VMgEOu9CidjeCeTNQ1l6fpUlbiGgSP7CLI3PFtW9/FfbeHieZ+kyWK5H7CA==",
"cpu": [
"ia32"
],
"dev": true,
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@tauri-apps/cli-win32-x64-msvc": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.11.4.tgz",
"integrity": "sha512-+vDiqBIU5dMISg/wNvX3sF+ZHfgJGJ5T0AcO+EHNXV9GGAG+P5fzodlDXD3QdKCRgZxMoCm5PPvj3BqLNjBthw==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"name": "@opsxdb/desktop",
"version": "0.1.0",
"private": true,
"scripts": {
"tauri": "tauri"
},
"devDependencies": {
"@tauri-apps/cli": "^2.4.0"
}
}
+4811
View File
File diff suppressed because it is too large. Load diff
+21
View File
@@ -0,0 +1,21 @@
[package]
name = "opsxdb-desktop"
version = "0.1.0"
description = "OpsxDB Tauri desktop shell"
authors = ["OpsxDB"]
edition = "2021"
[lib]
name = "opsxdb_desktop_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] } # path via Manager
serde = { version = "1", features = ["derive"] }
serde_json = "1"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "json", "blocking"] }
tokio = { version = "1", features = ["time"] }
url = "2"
@@ -0,0 +1,8 @@
# Sidecar binaries
`./run.sh package` 会把 `opsxdb-server` 复制为带目标三元组后缀的文件,例如:
- `opsxdb-server-aarch64-apple-darwin`
- `opsxdb-server-x86_64-apple-darwin`
Tauri `externalBin` 在构建时按当前 triple 解析。
+3
View File
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
@@ -0,0 +1,11 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Default capabilities for the OpsxDB main window",
"windows": [
"main"
],
"permissions": [
"core:default"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
<background android:drawable="@color/ic_launcher_background"/>
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#fff</color>
</resources>
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

+7
View File
@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
<rect width="512" height="512" rx="112" fill="#E11D2E"/>
<g transform="rotate(-20 256 256)">
<path d="M256 108 L290 216 L404 216 L312 286 L344 398 L256 332 L168 398 L200 286 L108 216 L222 216 Z"
fill="none" stroke="#FFFFFF" stroke-width="30" stroke-linejoin="round" stroke-linecap="round"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

+150
View File
@@ -0,0 +1,150 @@
mod sidecar;
use tauri::Manager;
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()
.manage(sidecar::SidecarState::default())
.setup(|app| {
let state = app.state::<sidecar::SidecarState>();
sidecar::ensure_backend(app.handle(), &state);
Ok(())
})
.invoke_handler(tauri::generate_handler![
http_send,
ws_connect,
ws_send,
ws_close
])
.build(tauri::generate_context!())
.expect("error while building OpsxDB desktop")
.run(|app, event| {
let state = app.state::<sidecar::SidecarState>();
sidecar::on_run_event(app, &event, &state);
});
}
+3
View File
@@ -0,0 +1,3 @@
fn main() {
opsxdb_desktop_lib::run();
}
+108
View File
@@ -0,0 +1,108 @@
//! 桌面启动时拉起本机 OpsxDB Gin 后端(默认 127.0.0.1:8788)。
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
use std::sync::Mutex;
use std::thread;
use std::time::Duration;
use tauri::{AppHandle, Manager, RunEvent};
const HEALTH: &str = "http://127.0.0.1:8788/health";
const ADDR: &str = "127.0.0.1:8788";
pub struct SidecarState {
child: Mutex<Option<Child>>,
}
impl Default for SidecarState {
fn default() -> Self {
Self {
child: Mutex::new(None),
}
}
}
fn health_ok() -> bool {
ureq_get(HEALTH).is_ok()
}
/// 轻量 GET,避免再引 reqwest 阻塞;用 std 即可。
fn ureq_get(url: &str) -> Result<(), ()> {
let Ok(resp) = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(1))
.build()
.and_then(|c| c.get(url).send())
else {
return Err(());
};
if resp.status().is_success() {
Ok(())
} else {
Err(())
}
}
fn candidate_bins(app: &AppHandle) -> Vec<PathBuf> {
let mut out = Vec::new();
// 打包资源:externalBin → 与可执行文件同级的 binaries 或 resource
if let Ok(dir) = app.path().resource_dir() {
out.push(dir.join("opsxdb-server"));
out.push(dir.join("binaries").join("opsxdb-server"));
}
if let Ok(exe) = app.path().executable_dir() {
out.push(exe.join("opsxdb-server"));
out.push(exe.join("binaries").join("opsxdb-server"));
}
// 开发态:仓库 apps/server/bin
out.push(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../server/bin/opsxdb-server"));
out.push(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../../apps/server/bin/opsxdb-server"));
out
}
fn spawn_server(bin: &PathBuf) -> std::io::Result<Child> {
Command::new(bin)
.env("OPSXDB_ADDR", ADDR)
.env("GIN_MODE", "release")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
}
pub fn ensure_backend(app: &AppHandle, state: &SidecarState) {
if health_ok() {
return;
}
for bin in candidate_bins(app) {
if !bin.exists() {
continue;
}
match spawn_server(&bin) {
Ok(child) => {
*state.child.lock().unwrap() = Some(child);
for _ in 0..30 {
if health_ok() {
return;
}
thread::sleep(Duration::from_millis(100));
}
return;
}
Err(_) => continue,
}
}
}
pub fn stop_backend(state: &SidecarState) {
if let Ok(mut g) = state.child.lock() {
if let Some(mut child) = g.take() {
let _ = child.kill();
let _ = child.wait();
}
}
}
pub fn on_run_event(app: &AppHandle, event: &RunEvent, state: &SidecarState) {
if matches!(event, RunEvent::Exit | RunEvent::ExitRequested { .. }) {
stop_backend(state);
let _ = app;
}
}
+43
View File
@@ -0,0 +1,43 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "OpsxDB",
"version": "0.1.0",
"identifier": "com.opsx.db",
"build": {
"beforeDevCommand": "bash -lc 'curl -fsS http://127.0.0.1:5174 >/dev/null 2>&1 || npm --prefix ../.. run dev:web'",
"devUrl": "http://127.0.0.1:5174",
"beforeBuildCommand": "bash -lc 'cd ../.. && VITE_OPSXDB_API=http://127.0.0.1:8788 npm run build:web'",
"frontendDist": "../../web/dist"
},
"app": {
"windows": [
{
"title": "OpsxDB",
"width": 1280,
"height": 800,
"minWidth": 960,
"minHeight": 640,
"resizable": true,
"fullscreen": false,
"label": "main"
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"externalBin": [
"binaries/opsxdb-server"
]
}
}