feat: Face JSON v2 schema - add schema_version, bbox x2/y2/center, keep embeddings, update clustering

This commit is contained in:
Accusys
2026-11-02 14:34:02 +08:00
parent 2fca49b120
commit 5d18183d82
566 changed files with 321788 additions and 1662 deletions
+152
View File
@@ -0,0 +1,152 @@
use axum::{
body::Body,
http::{header, Request, StatusCode},
middleware::Next,
response::{Html, IntoResponse, Response},
routing::get,
Router,
};
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
use std::net::SocketAddr;
use tower_http::services::{ServeDir, ServeFile};
#[tokio::main]
async fn main() {
let port = std::env::var("DOCSERVER_PORT")
.unwrap_or_else(|_| "8000".to_string())
.parse()
.unwrap_or(8000);
let username = std::env::var("DOCSERVER_USER")
.unwrap_or_else(|_| "admin".to_string());
let password = std::env::var("DOCSERVER_PASSWORD")
.unwrap_or_else(|_| "admin123".to_string());
let docs_dir = std::env::var("MOMENTRY_DOCS_DIR")
.unwrap_or_else(|_| {
std::env::current_exe()
.ok()
.and_then(|p| {
p.parent()
.map(|d| d.join("docs_v1.0/doc_wasm").to_string_lossy().to_string())
})
.unwrap_or_else(|| "docs_v1.0/doc_wasm".to_string())
});
tracing_subscriber::fmt::init();
tracing::info!("Starting docserver on port {}", port);
tracing::info!("Docs directory: {}", docs_dir);
tracing::info!("Username: {}", username);
let config = Config {
username,
password,
docs_dir: docs_dir.clone(),
};
let pkg_service = ServeDir::new(format!("{}/pkg", docs_dir));
let modules_service = ServeDir::new(format!("{}/modules", docs_dir));
let app = Router::new()
.route("/", get(serve_index))
.route("/health", get(|| async { "OK" }))
.nest_service("/pkg", pkg_service)
.nest_service("/modules", modules_service)
.route("/logout", get(logout_handler))
.nest_service("/logout.html", ServeFile::new(format!("{}/logout.html", docs_dir)))
.layer(axum::middleware::from_fn(move |req, next| {
let username = config.username.clone();
let password = config.password.clone();
async move { auth_middleware(req, next, &username, &password).await }
}));
let addr = SocketAddr::from(([0, 0, 0, 0], port));
tracing::info!("Listening on {}", addr);
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
struct Config {
username: String,
password: String,
docs_dir: String,
}
async fn auth_middleware(
req: Request<Body>,
next: Next,
expected_username: &str,
expected_password: &str,
) -> Response {
// Skip auth for health, logout, and logout.html endpoints
let path = req.uri().path();
if path == "/health" || path == "/logout" || path == "/logout.html" {
return next.run(req).await;
}
// Extract Authorization header
let auth_header = req
.headers()
.get("Authorization")
.and_then(|h| h.to_str().ok());
// Validate credentials
if let Some(auth) = auth_header {
if auth.starts_with("Basic ") {
let encoded = &auth[6..];
if let Ok(decoded) = BASE64.decode(encoded) {
if let Ok(decoded_str) = String::from_utf8(decoded) {
let parts: Vec<&str> = decoded_str.splitn(2, ':').collect();
if parts.len() == 2 {
let (username, password) = (parts[0], parts[1]);
if username == expected_username && password == expected_password {
return next.run(req).await;
}
}
}
}
}
}
// Return 401 with WWW-Authenticate header
(
StatusCode::UNAUTHORIZED,
[(header::WWW_AUTHENTICATE, "Basic realm=\"Momentry Documentation\"")],
"Authentication required",
)
.into_response()
}
async fn serve_index() -> Result<Html<String>, StatusCode> {
let docs_dir = std::env::var("MOMENTRY_DOCS_DIR")
.unwrap_or_else(|_| "docs_v1.0/doc_wasm".to_string());
let index_path = std::path::Path::new(&docs_dir).join("index.html");
tokio::fs::read_to_string(&index_path)
.await
.map(Html)
.map_err(|_| StatusCode::NOT_FOUND)
}
async fn logout_handler() -> impl IntoResponse {
// Serve logout.html page with absolute path
let logout_path = "/Users/accusys/momentry_core/docs_v1.0/doc_wasm/logout.html";
match tokio::fs::read_to_string(&logout_path).await {
Ok(html) => Html(html).into_response(),
Err(e) => {
eprintln!("Error reading logout.html: {}", e);
(
StatusCode::UNAUTHORIZED,
[(header::WWW_AUTHENTICATE, "Basic realm=\"Momentry Documentation - Logout\"")],
"Logged out - please close browser or clear cache",
).into_response()
}
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ async fn main() -> Result<()> {
);
// 顯示轉換後的 tsquery (除錯用)
match pg.prepare_tsquery(query_str).await {
// match pg.prepare_tsquery(query_str).await {
Ok(tsquery) => println!(" TSQUERY: {}", tsquery),
Err(e) => println!(" TSQUERY 錯誤: {}", e),
}
+1 -1
View File
@@ -20,7 +20,7 @@ async fn main() -> Result<()> {
println!("\n🔍 測試查詢 (簡體): '{}'", query_str);
// 顯示轉換後的 tsquery
match pg.prepare_tsquery(query_str).await {
// match pg.prepare_tsquery(query_str).await {
Ok(tsquery) => println!(" TSQUERY: {}", tsquery),
Err(e) => println!(" TSQUERY 錯誤: {}", e),
}
+1 -1
View File
@@ -39,7 +39,7 @@ async fn main() -> Result<()> {
}
// 顯示轉換後的 tsquery
match pg.prepare_tsquery(query_str).await {
// match pg.prepare_tsquery(query_str).await {
Ok(tsquery) => println!(" TSQUERY: {}", tsquery),
Err(e) => println!(" TSQUERY 錯誤: {}", e),
}