Files
fpv-rid-workbench/src/http/registry.rs
T
JiuContinent 281af4fe3d ```
refactor(registry): 生产环境数据库访问迁移至 SQLx 并统一测试端口策略

将 rusqlite 从生产依赖移至 dev-dependencies,正式数据库操作全部
由 SQLx 完成;rusqlite 仅保留用于测试夹具及旧数据库兼容验证。

UI 验收脚本移除 HTTP 代理和动态端口分配,统一通过
ui-test-port.mjs 的 assertUiPortAvailable 直连 8787 端口,
确保测试与正式实例串行执行。

新增 doc/registry/rust/axum-sqlx-architecture.md 记录模块职责、
数据兼容、退出资源回收及验证维护规范。

修复接收器页面按钮缺少显式 height 导致的布局偏差。
```
2026-10-27 20:04:34 +08:00

123 lines
3.7 KiB
Rust

use super::*;
pub(super) fn router() -> Router<Services> {
Router::new()
.route("/api/records", get(records).post(register))
.route(
"/api/records/{id}",
patch(update_record).delete(delete_record),
)
.route(
"/api/records/{id}/photos/{slot}",
get(photo).delete(delete_photo),
)
.route("/api/records/{id}/archive", get(download_card))
.route("/r/{id}", get(public_card))
.route("/api/resolve", get(resolve))
.route("/api/archive/status", get(archive_status))
.route("/api/archive/retry", post(retry_archive))
.route("/api/export/archive", post(export_archive))
.route("/api/export/excel", post(export_excel))
}
async fn records(
State(s): State<Services>,
LocalQuery(query): LocalQuery<RecordsQuery>,
) -> Result<Json<Value>> {
Ok(Json(
s.records(&query.q, query.page.as_deref(), query.page_size.as_deref())
.await?,
))
}
async fn register(
State(s): State<Services>,
Extension(Payload(body)): Extension<Payload>,
) -> Result<Json<Value>> {
Ok(Json(s.register(body).await?))
}
async fn update_record(
State(s): State<Services>,
Path(id): Path<String>,
Extension(Payload(body)): Extension<Payload>,
) -> Result<Json<Value>> {
record_id(&id)?;
Ok(Json(s.patch(&id, body).await?))
}
async fn delete_record(State(s): State<Services>, Path(id): Path<String>) -> Result<Json<Value>> {
record_id(&id)?;
Ok(Json(s.delete(&id, None).await?))
}
async fn delete_photo(
State(s): State<Services>,
Path((id, n)): Path<(String, String)>,
) -> Result<Json<Value>> {
record_id(&id)?;
Ok(Json(s.delete(&id, Some(slot(&n)?)).await?))
}
async fn photo(
State(s): State<Services>,
Path((id, n)): Path<(String, String)>,
) -> Result<Response> {
record_id(&id)?;
let (mime, bytes) = s.photo(&id, slot(&n)?).await?;
Ok(binary(bytes, &mime, None, None))
}
async fn download_card(State(s): State<Services>, Path(id): Path<String>) -> Result<Response> {
record_id(&id)?;
let (html, name) = s.card(&id, true).await?;
Ok(binary(
html.into_bytes(),
"text/html; charset=utf-8",
Some(&name),
Some(
"default-src 'none'; img-src data:; style-src 'unsafe-inline'; base-uri 'none'; frame-ancestors 'none'",
),
))
}
async fn public_card(State(s): State<Services>, Path(id): Path<String>) -> Result<Response> {
record_id(&id)?;
let (html, _) = s.card(&id, false).await?;
Ok(binary(
html.into_bytes(),
"text/html; charset=utf-8",
None,
Some(
"default-src 'none'; img-src 'self'; style-src 'unsafe-inline'; base-uri 'none'; frame-ancestors 'none'",
),
))
}
async fn resolve(
State(s): State<Services>,
LocalQuery(query): LocalQuery<ResolveQuery>,
) -> Result<Json<Value>> {
Ok(Json(s.resolve(query.url.as_deref()).await?))
}
async fn archive_status(State(s): State<Services>) -> Result<Json<Value>> {
Ok(Json(s.archive_status().await?))
}
async fn retry_archive(State(s): State<Services>) -> Result<Json<Value>> {
Ok(Json(s.sync_archive().await?))
}
async fn export_archive(
State(s): State<Services>,
Extension(Payload(body)): Extension<Payload>,
) -> Result<Response> {
Ok(binary(
s.export(body, false).await?,
"application/zip",
Some("FPV-RID-archive.zip"),
None,
))
}
async fn export_excel(
State(s): State<Services>,
Extension(Payload(body)): Extension<Payload>,
) -> Result<Response> {
Ok(binary(
s.export(body, true).await?,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
Some("FPV-RID-records.xlsx"),
None,
))
}