桌面应用图标替换为 B-brackets 设计(深藏青 + 白/蓝花括号)
- icon.svg 取自 opsx-icon-options/api/B-brackets.svg,全套光栅重生成: icon.icns(iconutil)、icon.ico(PNG-in-ICO 6 尺寸)、16-1024 PNG、Windows Square*/StoreLogo - 替换 Tauri 脚手架默认五角星图标;GUI 重启实测 Dock 图标已生效 - 服务全量重启:server 8787(官网/文档 200)+ web 5173 + 桌面 GUI
No files matched your search
@@ -329,7 +329,7 @@ checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures 0.3.1",
|
||||
"rand_core",
|
||||
"rand_core 0.10.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -529,6 +529,12 @@ dependencies = [
|
||||
"syn 3.0.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06"
|
||||
|
||||
[[package]]
|
||||
name = "dbus"
|
||||
version = "0.9.12"
|
||||
@@ -1086,7 +1092,7 @@ dependencies = [
|
||||
"js-sys",
|
||||
"libc",
|
||||
"r-efi 6.0.0",
|
||||
"rand_core",
|
||||
"rand_core 0.10.1",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
@@ -1350,7 +1356,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower-service",
|
||||
"webpki-roots",
|
||||
"webpki-roots 1.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2170,13 +2176,17 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
name = "opsxapi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"http",
|
||||
"reqwest 0.12.28",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
"url",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2373,6 +2383,15 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "precomputed-hash"
|
||||
version = "0.1.1"
|
||||
@@ -2479,7 +2498,7 @@ dependencies = [
|
||||
"bytes",
|
||||
"getrandom 0.4.3",
|
||||
"lru-slab",
|
||||
"rand",
|
||||
"rand 0.10.2",
|
||||
"rand_pcg",
|
||||
"ring",
|
||||
"rustc-hash",
|
||||
@@ -2527,6 +2546,17 @@ version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.10.2"
|
||||
@@ -2535,7 +2565,26 @@ checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80"
|
||||
dependencies = [
|
||||
"chacha20",
|
||||
"getrandom 0.4.3",
|
||||
"rand_core",
|
||||
"rand_core 0.10.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom 0.2.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2550,7 +2599,7 @@ version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
"rand_core 0.10.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2662,7 +2711,7 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
"webpki-roots 1.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3041,6 +3090,17 @@ dependencies = [
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures 0.2.17",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
@@ -3634,9 +3694,21 @@ dependencies = [
|
||||
"mio",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.26.5"
|
||||
@@ -3647,6 +3719,22 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-tungstenite"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"log",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tungstenite",
|
||||
"webpki-roots 0.26.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.7.19"
|
||||
@@ -3872,6 +3960,26 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "tungstenite"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"bytes",
|
||||
"data-encoding",
|
||||
"http",
|
||||
"httparse",
|
||||
"log",
|
||||
"rand 0.8.8",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"sha1",
|
||||
"thiserror 1.0.69",
|
||||
"utf-8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typeid"
|
||||
version = "1.0.3"
|
||||
@@ -3968,6 +4076,12 @@ dependencies = [
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf-8"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||
|
||||
[[package]]
|
||||
name = "utf8_iter"
|
||||
version = "1.0.4"
|
||||
@@ -4196,6 +4310,15 @@ dependencies = [
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.26.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
|
||||
dependencies = [
|
||||
"webpki-roots 1.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "1.0.9"
|
||||
@@ -4735,6 +4858,26 @@ dependencies = [
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerofrom"
|
||||
version = "0.1.8"
|
||||
|
||||
@@ -22,5 +22,9 @@ tauri = { version = "2", features = [] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "json"] }
|
||||
tokio = { version = "1", features = ["time"] }
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time", "net"] }
|
||||
url = "2"
|
||||
tokio-tungstenite = { version = "0.24", features = ["rustls-tls-webpki-roots"] }
|
||||
futures-util = "0.3"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
http = "1"
|
||||
@@ -2,10 +2,10 @@
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Default capabilities for the OpsxAPI main window",
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default"
|
||||
"core:default",
|
||||
"core:event:default",
|
||||
"transport"
|
||||
]
|
||||
}
|
||||
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 1022 B After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 950 B After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 742 B After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 57 KiB |
@@ -1,13 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
|
||||
<defs>
|
||||
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#0B182C"/>
|
||||
<stop offset="100%" stop-color="#0F203A"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="28" y="28" width="456" height="456" rx="110" fill="url(#g)"/>
|
||||
<text x="256" y="240" text-anchor="middle" font-family="SF Pro Display, Helvetica, Arial" font-size="140" font-weight="700" fill="#FFFFFF">API</text>
|
||||
<text x="256" y="340" text-anchor="middle" font-family="SF Pro Display, Helvetica, Arial" font-size="42" fill="#94A3B8">Opsx</text>
|
||||
<circle cx="110" cy="400" r="16" fill="#10B981"/>
|
||||
<rect width="512" height="512" rx="112" fill="#0B182C"/>
|
||||
<path d="M200 130c-48 0-70 28-70 70v28c0 22-14 34-34 38v20c20 4 34 16 34 38v28c0 42 22 70 70 70" fill="none" stroke="#FFFFFF" stroke-width="36" stroke-linecap="round"/>
|
||||
<path d="M312 130c48 0 70 28 70 70v28c0 22 14 34 34 38v20c-20 4-34 16-34 38v28c0 42-22 70-70 70" fill="none" stroke="#3B82F6" stroke-width="36" stroke-linecap="round"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 738 B After Width: | Height: | Size: 496 B |
|
Before Width: | Height: | Size: 349 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 801 B After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 445 B After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 774 B After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 774 B After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 987 B After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 987 B After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 957 B After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 9.7 KiB |
@@ -0,0 +1,4 @@
|
||||
[[permission]]
|
||||
identifier = "transport"
|
||||
description = "Allow HTTP/WebSocket native transport"
|
||||
commands.allow = ["http_send", "ws_connect", "ws_send", "ws_close"]
|
||||
@@ -1,6 +1,12 @@
|
||||
use futures_util::{SinkExt, StreamExt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
use tauri::{AppHandle, Emitter, Manager, State};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -32,10 +38,34 @@ struct HttpResult {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WsSpec {
|
||||
url: String,
|
||||
protocols: Option<Vec<String>>,
|
||||
headers: Option<HashMap<String, String>>,
|
||||
#[serde(default)]
|
||||
headers: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WsEvent {
|
||||
session_id: String,
|
||||
kind: String,
|
||||
data: String,
|
||||
}
|
||||
|
||||
enum WsCmd {
|
||||
Send(String),
|
||||
Close,
|
||||
}
|
||||
|
||||
struct WsHandle {
|
||||
tx: mpsc::UnboundedSender<WsCmd>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct WsState {
|
||||
sessions: Mutex<HashMap<String, WsHandle>>,
|
||||
}
|
||||
|
||||
fn validate_http_url(raw: &str) -> Result<url::Url, String> {
|
||||
@@ -44,13 +74,35 @@ fn validate_http_url(raw: &str) -> Result<url::Url, String> {
|
||||
"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" => Err("blocked metadata host".into()),
|
||||
_ => Ok(parsed),
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_ws_url(raw: &str) -> Result<String, String> {
|
||||
let mut parsed = url::Url::parse(raw).map_err(|e| format!("invalid URL: {e}"))?;
|
||||
match parsed.scheme() {
|
||||
"ws" | "wss" => {}
|
||||
"http" => {
|
||||
parsed
|
||||
.set_scheme("ws")
|
||||
.map_err(|_| "cannot set ws scheme".to_string())?;
|
||||
}
|
||||
"https" => {
|
||||
parsed
|
||||
.set_scheme("wss")
|
||||
.map_err(|_| "cannot set wss scheme".to_string())?;
|
||||
}
|
||||
_ => return Err("only ws/wss 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)
|
||||
Ok(parsed.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -71,8 +123,8 @@ async fn http_send(spec: HttpSpec) -> Result<HttpResult, String> {
|
||||
.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);
|
||||
for (key, value) in &spec.headers {
|
||||
request = request.header(key, value);
|
||||
}
|
||||
if let Some(body) = spec.body {
|
||||
if body.mode != "none" {
|
||||
@@ -101,30 +153,135 @@ async fn http_send(spec: HttpSpec) -> Result<HttpResult, String> {
|
||||
}
|
||||
|
||||
#[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
|
||||
))
|
||||
async fn ws_connect(
|
||||
app: AppHandle,
|
||||
state: State<'_, WsState>,
|
||||
spec: WsSpec,
|
||||
) -> Result<String, String> {
|
||||
let url = validate_ws_url(&spec.url)?;
|
||||
let session_id = Uuid::new_v4().to_string();
|
||||
|
||||
let mut req = http::Request::builder().method("GET").uri(&url);
|
||||
for (k, v) in &spec.headers {
|
||||
req = req.header(k.as_str(), v.as_str());
|
||||
}
|
||||
if let Some(protocols) = &spec.protocols {
|
||||
let joined = protocols
|
||||
.iter()
|
||||
.map(|s| s.trim())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
if !joined.is_empty() {
|
||||
req = req.header("Sec-WebSocket-Protocol", joined);
|
||||
}
|
||||
}
|
||||
let request = req
|
||||
.body(())
|
||||
.map_err(|e| format!("build ws request: {e}"))?;
|
||||
|
||||
let (tx, mut rx) = mpsc::unbounded_channel::<WsCmd>();
|
||||
{
|
||||
let mut map = state.sessions.lock().map_err(|e| e.to_string())?;
|
||||
map.insert(session_id.clone(), WsHandle { tx });
|
||||
}
|
||||
|
||||
let sid = session_id.clone();
|
||||
let app2 = app.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let emit = |kind: &str, data: String| {
|
||||
let _ = app2.emit(
|
||||
"ws-event",
|
||||
WsEvent {
|
||||
session_id: sid.clone(),
|
||||
kind: kind.to_string(),
|
||||
data,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
match tokio_tungstenite::connect_async(request).await {
|
||||
Ok((ws, _)) => {
|
||||
emit("status", "open".into());
|
||||
let (mut write, mut read) = ws.split();
|
||||
loop {
|
||||
tokio::select! {
|
||||
cmd = rx.recv() => {
|
||||
match cmd {
|
||||
Some(WsCmd::Send(data)) => {
|
||||
if write.send(Message::Text(data.into())).await.is_err() {
|
||||
emit("status", "error".into());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Some(WsCmd::Close) | None => {
|
||||
let _ = write.close().await;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
msg = read.next() => {
|
||||
match msg {
|
||||
Some(Ok(Message::Text(t))) => emit("message", t.to_string()),
|
||||
Some(Ok(Message::Binary(b))) => {
|
||||
emit("message", format!("[binary {} bytes]", b.len()))
|
||||
}
|
||||
Some(Ok(Message::Close(_))) | None => break,
|
||||
Some(Ok(_)) => {}
|
||||
Some(Err(e)) => {
|
||||
emit("message", format!("[ws error] {e}"));
|
||||
emit("status", "error".into());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
emit("status", "closed".into());
|
||||
}
|
||||
Err(e) => {
|
||||
emit("message", format!("[ws_connect error] {e}"));
|
||||
emit("status", "error".into());
|
||||
emit("status", "closed".into());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(st) = app2.try_state::<WsState>() {
|
||||
if let Ok(mut map) = st.sessions.lock() {
|
||||
map.remove(&sid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(session_id)
|
||||
}
|
||||
|
||||
#[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())
|
||||
async fn ws_send(state: State<'_, WsState>, session_id: String, data: String) -> Result<(), String> {
|
||||
let map = state.sessions.lock().map_err(|e| e.to_string())?;
|
||||
let handle = map
|
||||
.get(&session_id)
|
||||
.ok_or_else(|| format!("unknown ws session {session_id}"))?;
|
||||
handle
|
||||
.tx
|
||||
.send(WsCmd::Send(data))
|
||||
.map_err(|_| "ws session closed".to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn ws_close(session_id: String) -> Result<(), String> {
|
||||
let _ = session_id;
|
||||
async fn ws_close(state: State<'_, WsState>, session_id: String) -> Result<(), String> {
|
||||
let mut map = state.sessions.lock().map_err(|e| e.to_string())?;
|
||||
if let Some(handle) = map.remove(&session_id) {
|
||||
let _ = handle.tx.send(WsCmd::Close);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.manage(WsState::default())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
http_send,
|
||||
ws_connect,
|
||||
|
||||
@@ -3,17 +3,28 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"opsxapi/server/internal/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
addr := os.Getenv("OPSXAPI_ADDR")
|
||||
if addr == "" {
|
||||
addr = ":8787"
|
||||
}
|
||||
addr := resolveListenAddr()
|
||||
log.Printf("OpsxAPI server listening on %s", addr)
|
||||
if err := server.NewRouter().Run(addr); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// resolveListenAddr:默认仅本机 127.0.0.1:8787(Mock 本机优先)。
|
||||
// 显式对外:OPSXAPI_BIND_PUBLIC=1 或 OPSXAPI_ADDR=0.0.0.0:8787 / :8787。
|
||||
func resolveListenAddr() string {
|
||||
if v := strings.TrimSpace(os.Getenv("OPSXAPI_ADDR")); v != "" {
|
||||
return v
|
||||
}
|
||||
pub := strings.ToLower(strings.TrimSpace(os.Getenv("OPSXAPI_BIND_PUBLIC")))
|
||||
if pub == "1" || pub == "true" || pub == "yes" {
|
||||
return ":8787"
|
||||
}
|
||||
return "127.0.0.1:8787"
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
server:
|
||||
addr: ":8787"
|
||||
# 默认仅本机;公网需显式 OPSXAPI_BIND_PUBLIC=1 或 OPSXAPI_ADDR=:8787
|
||||
addr: "127.0.0.1:8787"
|
||||
proxy:
|
||||
timeout_ms: 30000
|
||||
# Environment overrides:
|
||||
# OPSXAPI_ADDR=:8787
|
||||
# OPSXAPI_ADDR=127.0.0.1:8787
|
||||
# OPSXAPI_BIND_PUBLIC=1
|
||||
# OPSXAPI_PROXY_TIMEOUT_MS=30000
|
||||
@@ -2,6 +2,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -43,6 +44,9 @@ func (a *API) Register(r *gin.Engine) {
|
||||
g.GET("/workspaces/:id", a.auth(a.handleGetWorkspace))
|
||||
g.PUT("/workspaces/:id", a.auth(a.handlePutWorkspace))
|
||||
g.PUT("/workspaces/:id/mock", a.auth(a.handlePublishMock))
|
||||
g.PUT("/mock/local", a.handlePublishLocalMock)
|
||||
g.DELETE("/mock/local", a.handleRevokeLocalMock)
|
||||
g.DELETE("/workspaces/:id/mock", a.auth(a.handleRevokeMock))
|
||||
}
|
||||
|
||||
/* ---------------- 中间件 ---------------- */
|
||||
@@ -312,7 +316,8 @@ func (a *API) handlePublishMock(c *gin.Context, user *store.User) {
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
Endpoints []mocksrv.Endpoint `json:"endpoints" binding:"required"`
|
||||
Endpoints []mocksrv.Endpoint `json:"endpoints" binding:"required"`
|
||||
TTLSeconds int64 `json:"ttlSeconds"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "缺少 endpoints"})
|
||||
@@ -322,15 +327,39 @@ func (a *API) handlePublishMock(c *gin.Context, user *store.User) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "单空间最多发布 200 个 Mock 接口"})
|
||||
return
|
||||
}
|
||||
if req.TTLSeconds < 0 || req.TTLSeconds > 30*24*3600 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ttlSeconds 需在 0~2592000(30 天)之间"})
|
||||
return
|
||||
}
|
||||
if err := a.store.ReplaceMockEndpoints(ws.ID, req.Endpoints); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "发布失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
var expiresAt int64
|
||||
if req.TTLSeconds > 0 {
|
||||
expiresAt = time.Now().Unix() + req.TTLSeconds
|
||||
}
|
||||
if err := a.store.SetMockExpiry(ws.ID, expiresAt); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "设置 TTL 失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
base := ws.MockToken
|
||||
if base == "" {
|
||||
base = strconv.FormatInt(ws.ID, 10) // 兜底(不应出现)
|
||||
base = strconv.FormatInt(ws.ID, 10)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true, "count": len(req.Endpoints), "base": "/mock/" + base})
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true, "count": len(req.Endpoints), "base": "/mock/" + base, "expiresAt": expiresAt})
|
||||
}
|
||||
|
||||
func (a *API) handleRevokeMock(c *gin.Context, user *store.User) {
|
||||
ws := a.workspaceOf(c, user)
|
||||
if ws == nil {
|
||||
return
|
||||
}
|
||||
if _, err := a.store.RevokeMock(ws.ID); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "作废失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
/* ---------------- 工作区同步 ---------------- */
|
||||
@@ -385,3 +414,76 @@ func (a *API) handlePutWorkspace(c *gin.Context, user *store.User) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"updatedAt": now})
|
||||
}
|
||||
|
||||
/* ---------------- 本机联调 Mock(不绑账号) ---------------- */
|
||||
|
||||
func (a *API) handlePublishLocalMock(c *gin.Context) {
|
||||
if !isLoopbackRequest(c) {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "本机联调发布仅允许从 127.0.0.1 / ::1 调用"})
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
Endpoints []mocksrv.Endpoint `json:"endpoints" binding:"required"`
|
||||
TTLSeconds int64 `json:"ttlSeconds"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "缺少 endpoints"})
|
||||
return
|
||||
}
|
||||
if len(req.Endpoints) > 200 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "单空间最多发布 200 个 Mock 接口"})
|
||||
return
|
||||
}
|
||||
if req.TTLSeconds < 0 || req.TTLSeconds > 30*24*3600 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ttlSeconds 需在 0~2592000(30 天)之间"})
|
||||
return
|
||||
}
|
||||
wsID, token, err := a.store.EnsureLocalMockWorkspace()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "本地 Mock 空间初始化失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := a.store.ReplaceMockEndpoints(wsID, req.Endpoints); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "发布失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
var expiresAt int64
|
||||
if req.TTLSeconds > 0 {
|
||||
expiresAt = time.Now().Unix() + req.TTLSeconds
|
||||
}
|
||||
if err := a.store.SetMockExpiry(wsID, expiresAt); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "设置 TTL 失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true, "count": len(req.Endpoints), "base": "/mock/" + token, "token": token, "expiresAt": expiresAt})
|
||||
}
|
||||
|
||||
func (a *API) handleRevokeLocalMock(c *gin.Context) {
|
||||
if !isLoopbackRequest(c) {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "本机联调作废仅允许从 127.0.0.1 / ::1 调用"})
|
||||
return
|
||||
}
|
||||
wsID, _, err := a.store.EnsureLocalMockWorkspace()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "本地 Mock 空间初始化失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
if _, err := a.store.RevokeMock(wsID); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "作废失败:" + err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
func isLoopbackRequest(c *gin.Context) bool {
|
||||
ip := net.ParseIP(c.ClientIP())
|
||||
if ip != nil && ip.IsLoopback() {
|
||||
return true
|
||||
}
|
||||
host, _, err := net.SplitHostPort(c.Request.RemoteAddr)
|
||||
if err != nil {
|
||||
host = c.Request.RemoteAddr
|
||||
}
|
||||
ip = net.ParseIP(host)
|
||||
return ip != nil && ip.IsLoopback()
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func localhostCORS() gin.HandlerFunc {
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
c.Header("Vary", "Origin")
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization, Cookie, X-Opsx-Probe, X-Opsx-Cookie")
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
}
|
||||
if c.Request.Method == http.MethodOptions {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
|
||||
@@ -108,6 +108,7 @@ CREATE INDEX IF NOT EXISTS idx_workspaces_owner ON workspaces(owner_id);
|
||||
if _, err := s.db.Exec(`ALTER TABLE workspaces ADD COLUMN mock_token TEXT`); err == nil {
|
||||
_, _ = s.db.Exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_workspaces_mock_token ON workspaces(mock_token)`)
|
||||
}
|
||||
_, _ = s.db.Exec(`ALTER TABLE workspaces ADD COLUMN mock_expires_at INTEGER NOT NULL DEFAULT 0`)
|
||||
// 老库补擅长列(幂等)
|
||||
_, _ = s.db.Exec(`ALTER TABLE team_members ADD COLUMN specialty TEXT NOT NULL DEFAULT ''`)
|
||||
rows, err := s.db.Query(`SELECT id FROM workspaces WHERE mock_token IS NULL OR mock_token = ''`)
|
||||
@@ -511,19 +512,114 @@ func (s *Store) FindMockEndpoint(workspaceID int64, method, path string) (*mocks
|
||||
return e, true, nil
|
||||
}
|
||||
|
||||
// ResolveMockToken:mock token → workspace id(不存在返回 false,不暴露信息)
|
||||
// ResolveMockToken:mock token → workspace id(不存在 / 已过期 / 已作废 均返回 false)
|
||||
func (s *Store) ResolveMockToken(token string) (int64, bool, error) {
|
||||
var id int64
|
||||
err := s.db.QueryRow(`SELECT id FROM workspaces WHERE mock_token = ?`, token).Scan(&id)
|
||||
var expiresAt int64
|
||||
err := s.db.QueryRow(
|
||||
`SELECT id, IFNULL(mock_expires_at, 0) FROM workspaces WHERE mock_token = ? AND mock_token != ''`,
|
||||
token,
|
||||
).Scan(&id, &expiresAt)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
if expiresAt > 0 && time.Now().Unix() >= expiresAt {
|
||||
return 0, false, nil
|
||||
}
|
||||
return id, true, nil
|
||||
}
|
||||
|
||||
// SetMockExpiry 设置可选 TTL(expiresAtUnix=0 表示不过期)。
|
||||
func (s *Store) SetMockExpiry(workspaceID int64, expiresAtUnix int64) error {
|
||||
_, err := s.db.Exec(`UPDATE workspaces SET mock_expires_at = ? WHERE id = ?`, expiresAtUnix, workspaceID)
|
||||
return err
|
||||
}
|
||||
|
||||
// RevokeMock 作废当前 mock token:轮换新 token、清零过期、清空 endpoints;旧链接立刻失效。
|
||||
func (s *Store) RevokeMock(workspaceID int64) (newToken string, err error) {
|
||||
newToken = newMockToken()
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, err := tx.Exec(
|
||||
`UPDATE workspaces SET mock_token = ?, mock_expires_at = 0 WHERE id = ?`,
|
||||
newToken, workspaceID,
|
||||
); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err := tx.Exec(`DELETE FROM mock_endpoints WHERE workspace_id = ?`, workspaceID); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return newToken, nil
|
||||
}
|
||||
|
||||
const localMockWorkspaceName = "__opsxapi_local_mock__"
|
||||
const localMockUserEmail = "__local_mock__@opsxapi.internal"
|
||||
|
||||
// ensureLocalMockOwner 系统账号,仅作 FK 锚点,不出现在登录流程。
|
||||
func (s *Store) ensureLocalMockOwner() (int64, error) {
|
||||
var id int64
|
||||
err := s.db.QueryRow(`SELECT id FROM users WHERE email = ?`, localMockUserEmail).Scan(&id)
|
||||
if err == nil {
|
||||
return id, nil
|
||||
}
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, err
|
||||
}
|
||||
res, err := s.db.Exec(
|
||||
`INSERT INTO users(name, email, pass_hash, created_at) VALUES(?,?,?,?)`,
|
||||
"本机联调", localMockUserEmail, hashPassword(newMockToken()), time.Now().Unix(),
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.LastInsertId()
|
||||
}
|
||||
|
||||
// EnsureLocalMockWorkspace 为本机联调预留的系统空间(不绑真实用户账号)。
|
||||
func (s *Store) EnsureLocalMockWorkspace() (id int64, token string, err error) {
|
||||
err = s.db.QueryRow(
|
||||
`SELECT id, IFNULL(mock_token,'') FROM workspaces WHERE name = ? AND team_id IS NULL LIMIT 1`,
|
||||
localMockWorkspaceName,
|
||||
).Scan(&id, &token)
|
||||
if err == nil {
|
||||
if token == "" {
|
||||
token = newMockToken()
|
||||
if _, e := s.db.Exec(`UPDATE workspaces SET mock_token = ? WHERE id = ?`, token, id); e != nil {
|
||||
return 0, "", e
|
||||
}
|
||||
}
|
||||
return id, token, nil
|
||||
}
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, "", err
|
||||
}
|
||||
ownerID, err := s.ensureLocalMockOwner()
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
token = newMockToken()
|
||||
now := time.Now().Unix()
|
||||
res, err := s.db.Exec(
|
||||
`INSERT INTO workspaces(name, team_id, owner_id, data, updated_at, mock_token) VALUES(?,NULL,?,'',?,?)`,
|
||||
localMockWorkspaceName, ownerID, now, token,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
id, err = res.LastInsertId()
|
||||
return id, token, err
|
||||
}
|
||||
|
||||
|
||||
func (s *Store) SaveWorkspace(wsID int64, data string) (int64, error) {
|
||||
now := time.Now().Unix()
|
||||
_, err := s.db.Exec(`UPDATE workspaces SET data = ?, updated_at = ? WHERE id = ?`, data, now, wsID)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>OpsxAPI · 路径 B 代理错误分层验收</title>
|
||||
<style>
|
||||
:root { --bg:#0f1419; --text:#e7ecf3; --muted:#8b98a8; --border:#2a3441; --btn:#1e2733; }
|
||||
* { box-sizing: border-box; }
|
||||
body { margin:0; font:13px/1.45 ui-sans-serif,system-ui,sans-serif; background:var(--bg); color:var(--text); padding:24px; }
|
||||
h1 { font-size:16px; margin:0 0 4px; }
|
||||
.sub { color:var(--muted); margin-bottom:20px; }
|
||||
.stack { display:flex; flex-direction:column; gap:14px; max-width:720px; }
|
||||
.banner { border-radius:10px; border:1px solid; padding:12px 14px; }
|
||||
.row { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
|
||||
.pill { display:inline-flex; align-items:center; border-radius:999px; padding:2px 8px; font-size:11px; font-weight:650; ring:1px; }
|
||||
.title { font-weight:650; }
|
||||
.detail { white-space:pre-wrap; opacity:.9; }
|
||||
.actions { display:flex; flex-wrap:wrap; gap:10px; align-items:center; margin-top:10px; }
|
||||
.btn { background:var(--btn); color:var(--text); border:1px solid var(--border); border-radius:8px; padding:5px 10px; font-size:12px; }
|
||||
.link { font-size:12px; opacity:.8; text-decoration:underline; text-underline-offset:2px; background:none; border:0; color:inherit; cursor:pointer; }
|
||||
.proxy { border-color:rgba(245,158,11,.4); background:rgba(245,158,11,.1); }
|
||||
.proxy .pill { background:rgba(245,158,11,.25); color:#fde68a; }
|
||||
.target { border-color:rgba(14,165,233,.4); background:rgba(14,165,233,.1); }
|
||||
.target .pill { background:rgba(14,165,233,.25); color:#bae6fd; }
|
||||
.auth { border-color:rgba(244,63,94,.4); background:rgba(244,63,94,.1); }
|
||||
.auth .pill { background:rgba(244,63,94,.25); color:#fecdd3; }
|
||||
.unknown { border-color:rgba(113,113,122,.45); background:rgba(113,113,122,.12); }
|
||||
.unknown .pill { background:rgba(113,113,122,.35); color:#e4e4e7; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>路径 B · ProxyErrorBanner 中文分层芯片</h1>
|
||||
<div class="sub">线框:代理 / 目标 / 鉴权 · unknown 中性灰 · 主按钮 / 次链接</div>
|
||||
<div class="stack">
|
||||
<div class="banner proxy">
|
||||
<div class="row"><span class="pill">代理</span><span class="title">代理层失败</span></div>
|
||||
<div class="detail">Failed to fetch · ECONNREFUSED 127.0.0.1:8787</div>
|
||||
<div class="actions"><button class="btn">检查本地代理</button><button class="btn">切换桌面直连</button><button class="link">查看通道说明</button></div>
|
||||
</div>
|
||||
<div class="banner target">
|
||||
<div class="row"><span class="pill">目标</span><span class="title">目标服务失败</span></div>
|
||||
<div class="detail">HTTP 502 · ENOTFOUND api.internal.example</div>
|
||||
<div class="actions"><button class="btn">检查 BaseURL / VPN</button></div>
|
||||
</div>
|
||||
<div class="banner auth">
|
||||
<div class="row"><span class="pill">鉴权</span><span class="title">鉴权层失败</span></div>
|
||||
<div class="detail">401 Unauthorized · Bearer 无效</div>
|
||||
<div class="actions"><button class="btn">检查 Token / Auth</button></div>
|
||||
</div>
|
||||
<div class="banner unknown">
|
||||
<div class="row"><span class="pill">未知</span><span class="title">请求失败(请按层排查)</span></div>
|
||||
<div class="detail">Unexpected error</div>
|
||||
<div class="actions"><button class="btn">查代理 :8787</button><button class="btn">切换桌面直连</button><button class="link">查环境 / BaseURL</button></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,15 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
||||
<defs>
|
||||
<linearGradient id="g" x1="0" y1="0" x2="64" y2="64" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#2563EB"/>
|
||||
<stop offset="1" stop-color="#06B6D4"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="64" height="64" rx="14" fill="url(#g)"/>
|
||||
<g stroke="#fff" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" fill="none">
|
||||
<path d="M17 25h26"/>
|
||||
<path d="M37 19l6 6-6 6"/>
|
||||
<path d="M47 39H21"/>
|
||||
<path d="M27 33l-6 6 6 6"/>
|
||||
</g>
|
||||
<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="#0B182C"/>
|
||||
<path d="M200 130c-48 0-70 28-70 70v28c0 22-14 34-34 38v20c20 4 34 16 34 38v28c0 42 22 70 70 70" fill="none" stroke="#FFFFFF" stroke-width="36" stroke-linecap="round"/>
|
||||
<path d="M312 130c48 0 70 28 70 70v28c0 22 14 34 34 38v20c-20 4-34 16-34 38v28c0 42-22 70-70 70" fill="none" stroke="#3B82F6" stroke-width="36" stroke-linecap="round"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 564 B After Width: | Height: | Size: 496 B |
@@ -199,7 +199,7 @@
|
||||
border-bottom-color: var(--accent);
|
||||
}
|
||||
.ops-tab .ops-count {
|
||||
@apply ml-1 rounded-full px-1.5 text-[10px];
|
||||
@apply ml-1 rounded-full px-1.5 text-[11px];
|
||||
background: var(--hover);
|
||||
color: var(--text-dim);
|
||||
}
|
||||
@@ -232,7 +232,7 @@
|
||||
.ops-method-HEAD { color: var(--m-HEAD); }
|
||||
.ops-method-OPTIONS { color: var(--m-OPTIONS); }
|
||||
.ops-method-badge {
|
||||
@apply inline-block rounded px-1.5 py-0.5 text-[10px] font-bold tracking-wide;
|
||||
@apply inline-block rounded px-1.5 py-0.5 text-[11px] font-bold tracking-wide;
|
||||
background: var(--hover);
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@
|
||||
.env-dialog-item:hover { background: var(--hover); color: var(--text); }
|
||||
.env-dialog-item.active { background: var(--active); color: var(--accent-strong); }
|
||||
.env-dialog-current {
|
||||
@apply rounded-full px-1.5 py-0.5 text-[10px] font-semibold;
|
||||
@apply rounded-full px-1.5 py-0.5 text-[11px] font-semibold;
|
||||
background: color-mix(in srgb, var(--success) 14%, transparent);
|
||||
color: var(--success);
|
||||
}
|
||||
@@ -442,9 +442,15 @@
|
||||
}
|
||||
.set-toggle.on .set-toggle-dot { transform: translateX(18px); }
|
||||
|
||||
/* Mock 规则表(随右侧内容区整体滚动,表头吸附) */
|
||||
/* Mock 规则表:表内滚动,表头吸顶(避免整窗跟着 60+ 行狂滚) */
|
||||
.set-group .ops-hint { margin: 10px 12px 0; }
|
||||
.mock-rules { @apply mt-2; }
|
||||
.mock-rules {
|
||||
@apply mt-2;
|
||||
max-height: min(42vh, 380px);
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
border-top: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
|
||||
}
|
||||
.mock-rule-head, .mock-rule-row {
|
||||
display: grid;
|
||||
grid-template-columns: 88px 84px minmax(110px, 1fr) minmax(130px, 1.2fr) minmax(96px, 0.9fr) 44px 30px;
|
||||
@@ -453,7 +459,7 @@
|
||||
padding: 4px 12px;
|
||||
}
|
||||
.mock-rule-head {
|
||||
@apply sticky top-0 z-[1] text-[11px] font-semibold;
|
||||
@apply sticky top-0 z-[2] text-[11px] font-semibold;
|
||||
color: var(--text-faint);
|
||||
background: var(--panel-2);
|
||||
border-bottom: 1px solid var(--border);
|
||||
@@ -483,7 +489,7 @@
|
||||
.mock-cheat-item .ops-faint { flex: 1; min-width: 0; @apply truncate; }
|
||||
.mock-cheat-gen {
|
||||
max-width: 46%;
|
||||
@apply truncate font-mono text-[10px];
|
||||
@apply truncate font-mono text-[11px];
|
||||
color: var(--text-faint);
|
||||
}
|
||||
.mock-preview-value {
|
||||
@@ -538,6 +544,29 @@
|
||||
border-radius: 2px;
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
/* 工作区角标:绿=本地,蓝=团队 */
|
||||
.rail-ws-badge {
|
||||
position: absolute;
|
||||
right: -2px;
|
||||
bottom: -1px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
border: 1.5px solid var(--panel);
|
||||
}
|
||||
.rail-ws-badge.local { background: #22c55e; }
|
||||
.rail-ws-badge.team { background: #3b82f6; }
|
||||
.rail-ws-badge.cloud { background: #60a5fa; }
|
||||
.rail-ws-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.rail-ws-dot.local { background: #22c55e; }
|
||||
.rail-ws-dot.team { background: #3b82f6; }
|
||||
|
||||
.rail-item.rail-login {
|
||||
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
||||
color: var(--accent-strong);
|
||||
@@ -602,7 +631,7 @@
|
||||
}
|
||||
.member-row:hover { background: var(--panel-2); }
|
||||
.spec-chip {
|
||||
@apply inline-flex shrink-0 items-center rounded-full border px-2 py-px text-[10px] font-medium;
|
||||
@apply inline-flex shrink-0 items-center rounded-full border px-2 py-px text-[11px] font-medium;
|
||||
}
|
||||
.spec-preset {
|
||||
@apply rounded-full border px-2 py-0.5 text-[11px] transition;
|
||||
@@ -628,7 +657,7 @@
|
||||
|
||||
/* ---------- 账号 / 空间 ---------- */
|
||||
.ops-user-avatar {
|
||||
@apply grid h-[18px] w-[18px] shrink-0 place-items-center rounded-full text-[10px] font-bold text-white;
|
||||
@apply grid h-[18px] w-[18px] shrink-0 place-items-center rounded-full text-[11px] font-bold text-white;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent-strong, var(--accent)));
|
||||
}
|
||||
|
||||
@@ -758,3 +787,48 @@
|
||||
outline: 1.5px dashed var(--accent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
/* === design-system tokens (v1) === */
|
||||
:root {
|
||||
--space-1: 4px;
|
||||
--space-2: 8px;
|
||||
--space-3: 12px;
|
||||
--space-4: 16px;
|
||||
--space-5: 24px;
|
||||
--radius-sm: 6px;
|
||||
--radius-md: 8px;
|
||||
--radius-lg: 12px;
|
||||
--bg-app: var(--bg);
|
||||
--bg-panel: var(--panel);
|
||||
--bg-elevated: var(--panel-2);
|
||||
--code-bg: var(--input-bg);
|
||||
--toolbar-h: 42px;
|
||||
--input-h: 32px;
|
||||
--ws-out: #38bdf8;
|
||||
--ws-in: #34d399;
|
||||
--ws-sys: #94a3b8;
|
||||
--ws-err: #fb7185;
|
||||
}
|
||||
.ops-toolbar { min-height: var(--toolbar-h); }
|
||||
.ops-status-pill {
|
||||
display: inline-flex; align-items: center; gap: 4px;
|
||||
border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.ops-status-2xx { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }
|
||||
.ops-status-3xx { color: var(--accent-strong); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
|
||||
.ops-status-4xx { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); border-color: color-mix(in srgb, var(--warn) 35%, var(--border)); }
|
||||
.ops-status-5xx { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
|
||||
.ops-status-idle { color: var(--text-faint); }
|
||||
.ops-msg-out { border-left: 2px solid var(--ws-out); }
|
||||
.ops-msg-in { border-left: 2px solid var(--ws-in); }
|
||||
.ops-msg-sys { border-left: 2px solid var(--ws-sys); }
|
||||
.ops-msg-err { border-left: 2px solid var(--ws-err); }
|
||||
.ops-filter-chip {
|
||||
border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; font-size: 11px; color: var(--text-dim);
|
||||
background: transparent;
|
||||
}
|
||||
.ops-filter-chip-active { color: var(--accent-strong); border-color: var(--accent); background: var(--accent-soft); }
|
||||
|
||||
/* alias panel-2 */
|
||||
:root, :root[data-theme="dark"], :root[data-theme="light"] { --panel-2: var(--panel-2); --code-bg: var(--input-bg); }
|
||||
@@ -23,6 +23,7 @@ export default defineConfig({
|
||||
"/v1": {
|
||||
target: "http://127.0.0.1:8787",
|
||||
changeOrigin: true,
|
||||
ws: true,
|
||||
},
|
||||
"/health": {
|
||||
target: "http://127.0.0.1:8787",
|
||||
|
||||