```
feat(realtime): 新增 RID 目标与登记档案的人工关联绑定功能 - 新增 target_binding 模块,支持在目标详情面板中搜索、绑定和 解除 RID 与本地登记档案的人工关联 - 实时目标详情中移除内联档案查询逻辑,改用 TargetBinding 组件 - 档案保存后自动将搜索框设为新记录序列号并跳回首页,避免分页 遗漏;监听 rid-workspace-view 和 focus 事件以刷新档案列表 - 重构首页卡片预览图为 SVG 方案,增加 caption 说明文字, 调整白色主题配色以匹配新设计 ```
This commit is contained in:
@@ -18,45 +18,55 @@
|
||||
.home-card-title{display:block;font-size:18px;font-weight:600;line-height:1.5;margin-top:22px}
|
||||
.home-card-desc{display:block;min-height:50px;font-size:14px;line-height:1.85;color:var(--work-muted);margin-top:8px}
|
||||
.home-card-preview{display:block;width:100%;margin-top:23px;pointer-events:none}
|
||||
.home-card .mini{display:block;height:109px;width:100%;border-radius:10px;border:1px solid #b7d1ef1c;background:#08132166;overflow:hidden;position:relative;opacity:.85}
|
||||
.home-card .registry{display:flex;padding:12px;gap:10px}
|
||||
.home-card .mini-side{display:block;width:24%;border-right:1px solid #809dbe1f;padding-right:9px;padding-top:3px}
|
||||
.home-card .mini-side i{display:block;height:6px;width:100%;background:#6b89ac26;margin-bottom:9px;border-radius:2px}
|
||||
.home-card .mini-side i:first-child{background:#6a9ac54a}
|
||||
.home-card .mini-body{display:block;width:49%}
|
||||
.home-card .mini-body b{display:block;width:45%;height:5px;border-radius:2px;background:#a4bcd040;margin:2px 0 9px}
|
||||
.home-card .mini-body>span{display:block;height:12px;border:1px solid #7e9ab526;border-radius:3px;margin:5px 0}
|
||||
.home-card .mini-body em{display:block;height:10px;width:39%;margin-top:8px;background:#5784b14a;border-radius:3px;float:right}
|
||||
.home-card .mini-qr{display:grid;width:22%;place-items:center}
|
||||
.home-card .mini-qr i{display:block;width:34px;height:34px;border:5px solid #93abc038;border-radius:3px;box-shadow:inset 0 0 0 3px #0e1c2b;position:relative}
|
||||
.home-card .mini-qr i:before{content:'';position:absolute;top:4px;left:4px;width:6px;height:6px;background:#b7d0e155}
|
||||
.home-card .radar{background:#122b3459}
|
||||
.home-card .radar-grid{position:absolute;inset:0;background-image:linear-gradient(#91b1c111 1px,transparent 1px),linear-gradient(90deg,#91b1c111 1px,transparent 1px);background-size:29px 27px}
|
||||
.home-card .radar-line{position:absolute;left:45px;top:29px;width:140px;height:48px;border-bottom:1px dashed #a1d3d47d;transform:rotate(-17deg)}
|
||||
.home-card .radar i{width:6px;height:6px;position:absolute;background:#b3ddd6;clip-path:polygon(50% 0,100% 100%,50% 80%,0 100%)}
|
||||
.home-card .radar i:nth-of-type(1){left:22%;top:65%}.home-card .radar i:nth-of-type(2){left:65%;top:28%}.home-card .radar i:nth-of-type(3){left:79%;top:60%}
|
||||
.home-card .map-label{position:absolute;top:12px;left:12px;width:42px;height:8px;background:#8caab822;border-radius:3px}
|
||||
.home-card .appearance{padding:14px 13px;display:grid;grid-template-columns:repeat(3,1fr);gap:8px;align-content:start}
|
||||
.home-card .wall{display:block;height:44px;border:1px solid #a9bdce26;border-radius:5px}
|
||||
.home-card .wall-one{background:linear-gradient(135deg,#3b4a5b,#101b29)}.home-card .wall-two{background:linear-gradient(135deg,#41728f,#193a54)}.home-card .wall-three{background:linear-gradient(135deg,#dae4ec,#8c9eaf)}
|
||||
.home-card .setting-line{display:flex;grid-column:1/4;justify-content:space-between;border-top:1px solid #a7c3e11c;margin-top:4px;padding-top:10px}
|
||||
.home-card .setting-line i{width:45px;height:4px;background:#8dacc32d;border-radius:3px}.home-card .setting-line i:last-child{width:65px}
|
||||
/* Static feature illustrations, not live device data or nested controls. */
|
||||
.home-card .mini{display:flex;flex-direction:column;height:119px;width:100%;border-radius:10px;border:1px solid #33475e;background:#111f30;overflow:hidden;position:relative;color:#c1d1e1}
|
||||
.home-preview-art{display:block;width:100%;height:88px;min-height:0;flex:1}
|
||||
.home-card .home-preview-caption{display:block;flex-shrink:0;padding:3px 11px 7px;font-size:11px;line-height:17px;white-space:nowrap;color:#bacbde}
|
||||
.home-card .preview-sheet{fill:#172b42;stroke:#466689}
|
||||
.home-card .preview-icon-bg{fill:#355a80}
|
||||
.home-card .preview-symbol{fill:none;stroke:#c1dcf7;stroke-width:2}
|
||||
.home-card .preview-title{fill:#deebfb;font-size:12px}
|
||||
.home-card .preview-detail{fill:#a8bfd8;font-size:10px}
|
||||
.home-card .preview-lines{fill:none;stroke:#708fb1;stroke-width:3;stroke-linecap:round}
|
||||
.home-card .preview-arrow{fill:none;stroke:#82aad5}
|
||||
.home-card .preview-code{fill:#192f47;stroke:#81a4ca}
|
||||
.home-card .preview-code-mark{fill:none;stroke:#c7dbef;stroke-width:3}
|
||||
.home-card .preview-code-pixels{fill:#c7dbef}
|
||||
.home-card .radar{background:#10272e}
|
||||
.home-card .preview-map-grid{fill:none;stroke:#28474f;stroke-width:.8}
|
||||
.home-card .preview-map-roads{fill:none;stroke:#40636c;stroke-width:7;opacity:.45}
|
||||
.home-card .preview-track{fill:none;stroke:#8dc8c3;stroke-width:2;stroke-dasharray:4 4}
|
||||
.home-card .preview-target-ring{fill:#73beb622;stroke:#73beb677}
|
||||
.home-card .preview-target{fill:#b5e9e1}
|
||||
.home-card .home-preview-swatches{display:flex;gap:7px;padding:12px 12px 0;flex:1;min-height:0}
|
||||
.home-card .home-preview-swatch{display:flex;flex:1;min-width:0;flex-direction:column;gap:4px;text-align:center;font-size:11px;line-height:17px}
|
||||
.home-card .wall{display:block;height:47px;position:relative;flex-shrink:0;border:1px solid #53667c;border-radius:5px}
|
||||
.home-card .wall-one{background:linear-gradient(135deg,#425264,#152030)}
|
||||
.home-card .wall-two{background:linear-gradient(135deg,#3a6c92,#172e4d);border:2px solid #95bde7}
|
||||
.home-card .wall-three{background:linear-gradient(135deg,#e2e9ef,#849caf)}
|
||||
.home-card .home-preview-check{position:absolute;right:4px;bottom:2px;font-size:11px;color:#e3f3ff}
|
||||
.home-card-open{display:flex;align-items:center;justify-content:space-between;width:100%;border-top:1px solid #b1cbe429;padding-top:18px;margin-top:23px;color:var(--work-text);font-size:14px}
|
||||
.theme-blue .home-top{background:#0d274775}.theme-blue .home-card{background:linear-gradient(145deg,#4a78a84d,#173c6673),#081a30a0;border-color:#b0d6ff36}
|
||||
.theme-white .home-top{background:#eff6ffd1;border-color:#56718c29}
|
||||
.theme-white .home-card{background:linear-gradient(145deg,#ffffff70,#e1edf96e),#eff6ffd0;border-color:#ffffffb0;box-shadow:0 1px 0 #fff9 inset,0 14px 35px #263e5b12}
|
||||
.theme-white .home-card:hover{background:linear-gradient(145deg,#ffffff90,#e1edf98e),#eff6ffd9;border-color:#8eb4dc80}
|
||||
.theme-white .home-card .mini{background:#c4d4e344;border-color:#6f8eac29}
|
||||
.theme-white .home-card .mini-side i,.theme-white .home-card .mini-body b,.theme-white .home-card .setting-line i{background:#698baa4d}
|
||||
.theme-white .home-card .mini-body>span{border-color:#6b8baa3d}.theme-white .home-card .mini-qr i{border-color:#698dad66;box-shadow:none}
|
||||
.theme-white .home-card .radar-line{border-color:#4b7a947d}.theme-white .home-card .radar i{background:#3d788b}
|
||||
.theme-white .home-card .radar-grid{background-image:linear-gradient(#587c9d19 1px,transparent 1px),linear-gradient(90deg,#587c9d19 1px,transparent 1px)}
|
||||
.theme-white .home-card .mini{background:#e3edf6;border-color:#9ab0c7;color:#34516c}
|
||||
.theme-white .home-card .home-preview-caption{color:#34516c}
|
||||
.theme-white .home-card .preview-sheet{fill:#d3e3f2;stroke:#7393b3}
|
||||
.theme-white .home-card .preview-title{fill:#203f5d}
|
||||
.theme-white .home-card .preview-detail{fill:#34516c}
|
||||
.theme-white .home-card .radar{background:#dfefee}
|
||||
.theme-white .home-card .preview-map-grid{stroke:#9bbcbf}
|
||||
.theme-white .home-card .preview-map-roads{stroke:#8aafb4}
|
||||
.theme-white .home-card .preview-track{stroke:#346f72}
|
||||
.theme-white .home-card .preview-target-ring{fill:#346f7214;stroke:#346f7277}
|
||||
.theme-white .home-card .preview-target{fill:#285f62}
|
||||
.theme-white .home-card-open{border-color:#6c8da834}
|
||||
.theme-white .home-launcher.homescreen{background:linear-gradient(130deg,#f1f7ffd9,#d9e7f5bf)!important;backdrop-filter:blur(6px)}
|
||||
body[data-custom-wallpaper="true"]:not(.theme-white) .home-launcher.homescreen{background:#050f1aad!important}
|
||||
body[data-custom-wallpaper="true"]:not(.theme-white) .home-heading p{color:#b6c8dc}
|
||||
.settings-layout .wall-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
|
||||
@media(max-width:1100px){.home-launcher.homescreen{padding:35px 30px 55px}.home-cards{gap:15px}.home-card{padding:21px}.home-card-desc{font-size:14px}.home-card .mini{height:100px}}
|
||||
@media(max-width:1100px){.home-launcher.homescreen{padding:35px 30px 55px}.home-cards{gap:15px}.home-card{padding:21px}.home-card-desc{font-size:14px}}
|
||||
@media(max-width:760px){.home-top{padding:0 20px}.home-launcher.homescreen{align-items:flex-start;padding:34px 22px 40px}.home-space{margin:0}.home-heading{margin-bottom:24px}.home-heading h1{font-size:25px}.home-cards{grid-template-columns:1fr;gap:15px}.home-card{display:grid;grid-template-columns:65px minmax(0,1fr) 19px;gap:4px 17px;padding:19px;min-height:134px}.home-app-icon{width:65px;height:65px;grid-row:1/3}.home-card-title{grid-column:2;grid-row:1;margin:0;align-self:end;font-size:17px}.home-card-desc{grid-column:2;grid-row:2;margin:0;min-height:0;align-self:start;font-size:13px}.home-card-preview{display:none}.home-card-open{grid-column:3;grid-row:1/3;display:block;overflow:hidden;width:19px;height:22px;font-size:0;padding:0;margin:0;border:0}.home-card-open svg{display:block;position:absolute}.settings-layout .wall-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
||||
@media(prefers-reduced-motion:reduce){.home-card{transition:none}.home-card:hover{transform:none}}
|
||||
@media(max-width:760px){.workspace-home-link{min-width:24px;padding:4px}.workspace-home-link>span,.workspace-crumb-separator{display:none}}
|
||||
|
||||
@@ -60,3 +60,14 @@ body.b[data-screen=realtime] .live-panel-restores{top:64px;left:calc(var(--navig
|
||||
@media(max-width:1199px){#rt-list-entry-form{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}#rt-list-entry-form .rt-inline-note{grid-column:1/-1}#rt-list-entry-form .rt-inline-editor-actions{grid-column:1/-1;text-align:right}#rt-list-entry-form .primary{width:auto;min-width:150px}}
|
||||
@media(max-width:900px),(max-height:570px){.rt-list-category-panel{padding:12px}.rt-list-category-panel>h3,.rt-list-category-panel .rt-list-policy{display:none}.rt-list-category-panel .rt-list-tabs{flex-direction:row}.rt-list-category-panel .rt-list-tabs button{width:auto}.rt-list-table-panel{min-height:380px}}
|
||||
@media(max-width:767px){.rt-list-rows table{min-width:0;table-layout:auto;display:block}.rt-list-rows thead{display:none}.rt-list-rows tbody{display:block}.rt-list-row{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;padding:14px;border-bottom:1px solid var(--work-line)}.rt-list-rows .rt-list-row td{display:block;border:0;padding:0;min-width:0}.rt-list-row-note{grid-column:1/-1}.rt-list-row-actions{grid-column:1/-1;display:flex!important;justify-content:flex-end}.rt-inline-editor-row,.rt-inline-editor-row>td{display:block;width:100%}.rt-list-rows .rt-inline-editor-row>td{padding:14px}#rt-list-entry-form{display:flex;flex-direction:column;align-items:stretch;gap:14px}.rt-inline-editor-heading{width:100%}#rt-list-entry-form .primary{width:100%}.rt-list-rows{max-height:600px}.rt-list-category-panel .rt-list-tabs{gap:5px}.rt-list-category-panel .rt-list-tabs button{font-size:11px;padding:9px}.rt-list-search{flex-basis:auto;width:100%;max-width:none}}
|
||||
|
||||
/* Approved A: RID association within the existing target detail panel. */
|
||||
.rt-binding { margin: 16px 0; padding: 14px 0; border-top: 1px solid var(--work-line); }
|
||||
.rt-binding h3 { font-size: 14px; margin: 0 0 10px; }
|
||||
.rt-binding p { font-size: 12px; line-height: 1.7; color: var(--work-muted); overflow-wrap: anywhere; }
|
||||
.rt-binding label { display: block; font-size: 12px; margin: 10px 0 5px; }
|
||||
.mc-layout-b .rt-binding input,.mc-layout-b .rt-binding select { width: 100%; min-width: 0; padding: 9px; color: var(--work-text); background: var(--work-panel, #091927); border: 1px solid var(--work-line); border-radius: 5px; }
|
||||
.mc-layout-b .rt-binding button { padding: 8px; font-size: 12px; margin-top: 8px; }
|
||||
.rt-binding-actions { display: flex; flex-wrap: wrap; gap: 7px; }
|
||||
.rt-binding :focus-visible { outline: 2px solid #8bbdff; outline-offset: 2px; }
|
||||
.rt-binding button:disabled { opacity: .5; cursor: not-allowed; }
|
||||
|
||||
@@ -5,6 +5,7 @@ mod realtime_layout;
|
||||
mod realtime_ui;
|
||||
mod receiver_ui;
|
||||
mod registry;
|
||||
mod target_binding;
|
||||
mod target_lists;
|
||||
mod workspace;
|
||||
|
||||
|
||||
@@ -179,48 +179,6 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
layout.select();
|
||||
if selected.get_untracked() != id {
|
||||
selected.set(id.clone());
|
||||
record.set(None);
|
||||
lookup.set("正在比对本地档案…".into());
|
||||
let expected = id.clone();
|
||||
spawn_local(async move {
|
||||
let result = async {
|
||||
let response = gloo_net::http::Request::get(&format!(
|
||||
"/api/records?q={}",
|
||||
js_sys::encode_uri_component(
|
||||
&expected.chars().take(60).collect::<String>()
|
||||
)
|
||||
))
|
||||
.send()
|
||||
.await
|
||||
.ok()?;
|
||||
if !response.ok() {
|
||||
return None;
|
||||
}
|
||||
response.json::<Value>().await.ok()
|
||||
}
|
||||
.await;
|
||||
if selected.get_untracked() != expected {
|
||||
return;
|
||||
}
|
||||
if let Some(value) = result {
|
||||
let found = value["records"].as_array().and_then(|rows| {
|
||||
rows.iter()
|
||||
.find(|r| r["serialNo"].as_str() == Some(&expected))
|
||||
.cloned()
|
||||
});
|
||||
lookup.set(
|
||||
if found.is_some() {
|
||||
"已匹配本地登记档案"
|
||||
} else {
|
||||
"未匹配本地档案(仅按目标标识比对)"
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
record.set(found);
|
||||
} else {
|
||||
lookup.set("本地档案查询失败".into());
|
||||
}
|
||||
});
|
||||
}
|
||||
let coords = map_call("select", &[id.into()])
|
||||
.ok()
|
||||
@@ -646,12 +604,13 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
<div class="live-detail-body"><button class="live-back" hidden=move||!layout.compact.get() on:click=move |_|layout.mobile.set(1)>"‹ 返回目标目录"</button>
|
||||
<div class="live-target-heading">{move||if selected.get().is_empty(){"请选择目标".into()}else{selected.get()}}</div>
|
||||
<p class="live-data-label">{move||lookup.get()}</p>
|
||||
<super::target_binding::TargetBinding target=selected record=record lookup=lookup/>
|
||||
<div class="rt-detail-classification" hidden=move||selected.get().is_empty()>{move||view!{<Badge lists=lists target=selected.get()/>}}<p>{move||lists.snapshot.with(|snapshot|snapshot.entries.iter().find(|entry|entry.target_id==selected.get()).map(|entry|entry.note.clone()).unwrap_or_default())}</p><div class="rt-detail-list-actions"><button class="rt-white-action" disabled=move||selected.get().is_empty()||!lists.ready.get()||lists.busy.get() on:click=move |_|lists.mark(selected.get_untracked(),ListKind::White)>"加入白名单"</button><button class="rt-black-action" disabled=move||selected.get().is_empty()||!lists.ready.get()||lists.busy.get() on:click=move |_|lists.mark(selected.get_untracked(),ListKind::Black)>"加入黑名单"</button><button disabled=move||selected.get().is_empty()||!lists.ready.get()||lists.busy.get() on:click=move |_|lists.edit(selected.get_untracked())>"编辑名单备注"</button></div><p class="rt-list-inline-feedback" role="status" class:error=move||lists.failed.get()>{move||lists.message.get()}</p></div>
|
||||
|
||||
<div class="live-metrics"><div><span>"经度"</span><strong>{move||position.get().map(|p|format!("{:.6}",p[0])).unwrap_or_else(||"—".into())}</strong></div><div><span>"纬度"</span><strong>{move||position.get().map(|p|format!("{:.6}",p[1])).unwrap_or_else(||"—".into())}</strong></div><div><span>"高度(数据源)"</span><strong>{move||position.get().map(|p|format!("{:.1} m",p[2])).unwrap_or_else(||"—".into())}</strong></div><div><span>"航向"</span><strong>{move||position.get().map(|p|format!("{:.0}°",p[3])).unwrap_or_else(||"—".into())}</strong></div></div>
|
||||
<dl><dt>"登记机型"</dt><dd>{move||record.get().and_then(|r|r["modelName"].as_str().map(str::to_owned)).unwrap_or_else(||"—".into())}</dd><dt>"登记人"</dt><dd>{move||record.get().and_then(|r|r["ownerName"].as_str().map(str::to_owned)).unwrap_or_else(||"—".into())}</dd></dl>
|
||||
<p class="live-data-label">"未收到的字段显示 —。未匹配本地记录不代表违法或未官方备案。"</p>
|
||||
</div><div class="mc-btn-row"><button class="primary" disabled=move||position.get().is_none() on:click=move |_|layout.focus()>"聚焦此目标"</button><a class="mc-btn mc-btn-secondary" aria-disabled=move||selected.get().is_empty().to_string() tabindex=move||if selected.get().is_empty(){-1}else{0} href=move||if selected.get().is_empty(){None}else{Some(format!("/?app=register&q={}",js_sys::encode_uri_component(&selected.get())))}>"查看本地登记"</a></div>
|
||||
</div><div class="mc-btn-row"><button class="primary" disabled=move||position.get().is_none() on:click=move |_|layout.focus()>"聚焦此目标"</button><a class="mc-btn mc-btn-secondary" aria-disabled=move||selected.get().is_empty().to_string() tabindex=move||if selected.get().is_empty(){-1}else{0} href=move||if selected.get().is_empty(){None}else{Some(format!("/?app=register&q={}",js_sys::encode_uri_component(&record.get().and_then(|r|r["serialNo"].as_str().map(str::to_owned)).unwrap_or_else(||selected.get()))))}>"查看本地登记"</a></div>
|
||||
</aside>
|
||||
<section id="rt-dock" class="mc-hud-dock" tabindex="-1" aria-label="事件与接收器" hidden=move||!layout.dock_visible()>
|
||||
<div class="live-resizer" role="separator" tabindex="0" aria-label="调整底栏高度" aria-orientation="horizontal" aria-valuemin="100" aria-valuemax=move||layout.maximum.get().round().to_string() aria-valuenow=move||layout.height.get().round().to_string()
|
||||
|
||||
@@ -526,7 +526,14 @@ async fn save_inner(state: Shared, editing: bool) -> Result<()> {
|
||||
false,
|
||||
);
|
||||
}
|
||||
let page = state.borrow().page.max(1);
|
||||
let page = if editing {
|
||||
state.borrow().page.max(1)
|
||||
} else {
|
||||
// The previous archive search/page may exclude the record just saved.
|
||||
input("history-query").set_value(field(&payload["record"], "serialNo"));
|
||||
state.borrow_mut().selected.clear();
|
||||
1
|
||||
};
|
||||
if let Err(error) = load(state, page).await {
|
||||
message(
|
||||
"history-message",
|
||||
@@ -644,6 +651,29 @@ pub fn init() {
|
||||
page: 1,
|
||||
..State::default()
|
||||
}));
|
||||
for event in ["rid-workspace-view", "focus"] {
|
||||
let state = state.clone();
|
||||
let refresh = Closure::<dyn FnMut(Event)>::new(move |_| {
|
||||
if state.borrow().busy
|
||||
|| document()
|
||||
.body()
|
||||
.and_then(|body| body.get_attribute("data-screen"))
|
||||
.as_deref()
|
||||
!= Some("archives")
|
||||
{
|
||||
return;
|
||||
}
|
||||
let state = state.clone();
|
||||
spawn_local(async move {
|
||||
let page = state.borrow().page.max(1);
|
||||
if let Err(error) = load(state, page).await {
|
||||
message("history-message", &error, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
let _ = window().add_event_listener_with_callback(event, refresh.as_ref().unchecked_ref());
|
||||
refresh.forget();
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
listen("submit", move |event| {
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
//! Approved option A: associate a detected identity from its detail panel.
|
||||
use gloo_net::http::Request;
|
||||
use leptos::prelude::*;
|
||||
use serde_json::{Value, json};
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
async fn response(response: gloo_net::http::Response) -> Result<Value, String> {
|
||||
let ok = response.ok();
|
||||
let value = response
|
||||
.json::<Value>()
|
||||
.await
|
||||
.map_err(|_| "服务响应无效".to_owned())?;
|
||||
if ok {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(value["error"].as_str().unwrap_or("关联操作失败").to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Editor {
|
||||
target: RwSignal<String>,
|
||||
record: RwSignal<Option<Value>>,
|
||||
lookup: RwSignal<String>,
|
||||
bound: RwSignal<Option<String>>,
|
||||
ready: RwSignal<bool>,
|
||||
busy: RwSignal<bool>,
|
||||
message: RwSignal<String>,
|
||||
query: RwSignal<String>,
|
||||
candidates: RwSignal<Vec<Value>>,
|
||||
draft: RwSignal<String>,
|
||||
generation: RwSignal<u64>,
|
||||
}
|
||||
impl Editor {
|
||||
fn apply(self, value: Value) {
|
||||
self.bound
|
||||
.set(value["bindingRecordId"].as_str().map(str::to_owned));
|
||||
self.lookup.set(
|
||||
match value["matchSource"].as_str() {
|
||||
Some("manual") => "已人工绑定登记档案",
|
||||
Some("serial") => "已按序列号精确匹配登记档案",
|
||||
_ => "未关联登记档案",
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
self.record
|
||||
.set(value.get("record").filter(|r| !r.is_null()).cloned());
|
||||
self.ready.set(true);
|
||||
}
|
||||
fn load(self, target: String) {
|
||||
self.generation.update(|v| *v += 1);
|
||||
let generation = self.generation.get_untracked();
|
||||
self.ready.set(false);
|
||||
self.busy.set(false);
|
||||
self.record.set(None);
|
||||
self.bound.set(None);
|
||||
self.candidates.set(Vec::new());
|
||||
self.draft.set(String::new());
|
||||
self.message.set(String::new());
|
||||
self.query.set(String::new());
|
||||
if target.is_empty() {
|
||||
self.lookup.set("请选择目标".into());
|
||||
return;
|
||||
}
|
||||
self.lookup.set("正在读取关联…".into());
|
||||
spawn_local(async move {
|
||||
let result = match Request::get(&format!("/api/target-bindings/{target}"))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(r) => response(r).await,
|
||||
Err(_) => Err("关联读取失败,请重试".into()),
|
||||
};
|
||||
if self.generation.get_untracked() != generation
|
||||
|| self.target.get_untracked() != target
|
||||
{
|
||||
return;
|
||||
}
|
||||
match result {
|
||||
Ok(v) => self.apply(v),
|
||||
Err(e) => {
|
||||
self.lookup.set("关联读取失败".into());
|
||||
self.message.set(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
fn search(self) {
|
||||
if self.busy.get_untracked() {
|
||||
return;
|
||||
}
|
||||
self.busy.set(true);
|
||||
self.message.set("正在搜索档案…".into());
|
||||
self.draft.set(String::new());
|
||||
self.candidates.set(Vec::new());
|
||||
let generation = self.generation.get_untracked();
|
||||
let target = self.target.get_untracked();
|
||||
let q = js_sys::encode_uri_component(&self.query.get_untracked());
|
||||
spawn_local(async move {
|
||||
let result = match Request::get(&format!("/api/records?q={q}&page=1&pageSize=50"))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(r) => response(r).await,
|
||||
Err(_) => Err("档案搜索失败,请重试".into()),
|
||||
};
|
||||
if self.generation.get_untracked() != generation
|
||||
|| self.target.get_untracked() != target
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.busy.set(false);
|
||||
match result {
|
||||
Ok(v) => {
|
||||
let rows = v["records"].as_array().cloned().unwrap_or_default();
|
||||
self.message.set(
|
||||
if rows.is_empty() {
|
||||
"没有匹配档案,请调整关键词或先登记设备。"
|
||||
} else if v["total"].as_u64().unwrap_or(0) > 50 {
|
||||
"仅显示前 50 条,请缩小搜索范围。"
|
||||
} else {
|
||||
"请选择档案,核对序列号与登记人后确认绑定。"
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
self.candidates.set(rows);
|
||||
}
|
||||
Err(e) => self.message.set(e),
|
||||
}
|
||||
});
|
||||
}
|
||||
fn save(self, remove: bool) {
|
||||
if !self.ready.get_untracked() || self.busy.get_untracked() {
|
||||
return;
|
||||
}
|
||||
let draft = self.draft.get_untracked();
|
||||
if !remove && draft.is_empty() {
|
||||
return;
|
||||
}
|
||||
let target = self.target.get_untracked();
|
||||
let generation = self.generation.get_untracked();
|
||||
let body = json!({"recordId":if remove {None}else{Some(draft)},"expectedRecordId":self.bound.get_untracked()});
|
||||
self.busy.set(true);
|
||||
self.message.set("正在保存关联…".into());
|
||||
spawn_local(async move {
|
||||
let result = match Request::put(&format!("/api/target-bindings/{target}")).json(&body) {
|
||||
Ok(request) => match request.send().await {
|
||||
Ok(r) => response(r).await,
|
||||
Err(_) => Err("保存结果未知,请刷新关联确认后重试".into()),
|
||||
},
|
||||
Err(_) => Err("关联参数无效".into()),
|
||||
};
|
||||
if self.generation.get_untracked() != generation
|
||||
|| self.target.get_untracked() != target
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.busy.set(false);
|
||||
match result {
|
||||
Ok(v) => {
|
||||
self.apply(v);
|
||||
self.draft.set(String::new());
|
||||
self.message.set(
|
||||
if remove {
|
||||
"人工绑定已解除;若序列号相同仍会自动匹配。名单保持不变。"
|
||||
} else {
|
||||
"绑定已保存;后续同一 RID 标识将自动关联。名单分类保持不变。"
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
self.ready.set(false);
|
||||
self.message.set(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub(super) fn TargetBinding(
|
||||
target: RwSignal<String>,
|
||||
record: RwSignal<Option<Value>>,
|
||||
lookup: RwSignal<String>,
|
||||
) -> impl IntoView {
|
||||
let editor = Editor {
|
||||
target,
|
||||
record,
|
||||
lookup,
|
||||
bound: RwSignal::new(None),
|
||||
ready: RwSignal::new(false),
|
||||
busy: RwSignal::new(false),
|
||||
message: RwSignal::new(String::new()),
|
||||
query: RwSignal::new(String::new()),
|
||||
candidates: RwSignal::new(Vec::new()),
|
||||
draft: RwSignal::new(String::new()),
|
||||
generation: RwSignal::new(0),
|
||||
};
|
||||
Effect::new(move |_| editor.load(target.get()));
|
||||
view! {
|
||||
<section class="rt-binding" aria-label="关联登记档案" hidden=move||target.get().is_empty()>
|
||||
<h3>"关联登记档案"</h3>
|
||||
<p>{move||record.get().map(|r|format!("{} · {} · {}",r["serialNo"].as_str().unwrap_or("—"),r["modelName"].as_str().filter(|s|!s.is_empty()).unwrap_or("未填机型"),r["ownerName"].as_str().filter(|s|!s.is_empty()).unwrap_or("未填登记人"))).unwrap_or_else(||"尚无匹配档案".into())}</p>
|
||||
<form on:submit=move|e|{e.prevent_default();editor.search();}>
|
||||
<label for="rt-binding-query">"搜索序列号、机型或登记人"</label>
|
||||
<input id="rt-binding-query" maxlength="60" prop:value=move||editor.query.get() disabled=move||editor.busy.get() on:input=move|e|editor.query.set(event_target_value(&e))/>
|
||||
<button type="submit" disabled=move||editor.busy.get()>"搜索档案"</button>
|
||||
</form>
|
||||
<label for="rt-binding-record">"选择要绑定的档案"</label>
|
||||
<select id="rt-binding-record" prop:value=move||editor.draft.get() disabled=move||editor.busy.get() on:change=move|e|editor.draft.set(event_target_value(&e))>
|
||||
<option value="">"请选择搜索结果"</option>
|
||||
<For each=move||editor.candidates.get() key=|r|r["id"].as_str().unwrap_or_default().to_owned() children=move|r|view!{<option value=r["id"].as_str().unwrap_or_default().to_owned()>{format!("{} · {} · {}",r["serialNo"].as_str().unwrap_or(""),r["modelName"].as_str().unwrap_or(""),r["ownerName"].as_str().unwrap_or(""))}</option>}/>
|
||||
</select>
|
||||
<p>"请确认该 RID 目标属于所选设备。绑定不会自动加入白名单。"</p>
|
||||
<div class="rt-binding-actions">
|
||||
<button class="primary" id="rt-binding-save" disabled=move||!editor.ready.get()||editor.busy.get()||editor.draft.get().is_empty() on:click=move |_|editor.save(false)>"确认绑定"</button>
|
||||
<button id="rt-binding-remove" disabled=move||!editor.ready.get()||editor.busy.get()||editor.bound.get().is_none() on:click=move |_|editor.save(true)>"解除人工绑定"</button>
|
||||
<button disabled=move||editor.busy.get() on:click=move |_|editor.load(target.get_untracked())>"刷新关联"</button>
|
||||
</div>
|
||||
<p role="status" id="rt-binding-message">{move||editor.message.get()}</p>
|
||||
</section>
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -8,6 +8,10 @@ Windows x64 发布目录中双击 `启动Rust版.cmd`,保持窗口打开,使
|
||||
|
||||
同一时刻只运行一个登记站。8787 被占用时先关闭原版或其他实例。Rust 版本另外锁定数据目录;旧版 Node 不认识这把锁,因此仍需人工关闭旧版。
|
||||
|
||||
地图框选下载需保留发布包内与主程序同目录的 `rid-map-downloader.exe`,不要只分发主 EXE。目标电脑无需安装 Go 或 Rust。程序优先使用有效的 `RID_MAP_DOWNLOADER` 路径;未设置或指向不存在的文件时,自动使用程序同目录的下载器。源码目录的 `启动Rust版.cmd` 会为本机 Release 版本设置统一工具目录中的下载器路径。
|
||||
|
||||
首次下载未缓存的区域需要联网,并在数据目录的 `maps/config.json` 中配置有效的 `tianditu_token`(或使用启动环境变量 `TIANDITU_TOKEN`)。发布包不包含业务数据或天地图密钥。下载结果保存在数据目录的 `maps/offline/`,下载完成后可离线使用相应区域、图层和层级;失败或取消的任务不代表完整离线覆盖。
|
||||
|
||||
## 编辑和照片
|
||||
|
||||
启动后进入 B1 玻璃工具卡片首页,点击“设备登记”“实时目标”或“设置”进入对应应用。首页不显示左侧菜单;进入应用后恢复菜单和顶部工具栏,可通过顶部“应用”按钮返回首页。菜单收起状态在当前浏览器会话内保留。
|
||||
|
||||
@@ -34,7 +34,7 @@ Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$ridZipPath = Join-Path $ridCleanOutput 'FPV-RID-Rust-Windows-x64.zip'
|
||||
$ridZip = [IO.Compression.ZipFile]::OpenRead($ridZipPath)
|
||||
try {
|
||||
$ridExpected = @('fpv-rid-registry.exe','启动Rust版.cmd','使用说明.md','third-party-licenses.txt','dependency-licenses.txt','build-info.json','SHA256SUMS.txt') | ForEach-Object { 'FPV-RID-Rust/' + $_ }
|
||||
$ridExpected = @('fpv-rid-registry.exe','rid-map-downloader.exe','map-downloader-LICENSE.txt','启动Rust版.cmd','使用说明.md','third-party-licenses.txt','dependency-licenses.txt','build-info.json','SHA256SUMS.txt') | ForEach-Object { 'FPV-RID-Rust/' + $_ }
|
||||
$ridActual = @($ridZip.Entries | ForEach-Object { $_.FullName.Replace('\','/') })
|
||||
if ($ridActual.Count -ne $ridExpected.Count -or @(Compare-Object $ridActual $ridExpected).Count) { throw 'Archive contains unexpected files' }
|
||||
} finally { $ridZip.Dispose() }
|
||||
|
||||
+11
@@ -164,6 +164,17 @@ async fn handle(State(worker): State<Worker>, req: Request) -> Response {
|
||||
}else{return Err(AppError::NotFound("名单接口不存在"))};
|
||||
return Ok(json_response(StatusCode::OK,serde_json::to_value(snapshot).map_err(|e|AppError::Internal(e.to_string()))?));
|
||||
}
|
||||
if let Some(target)=path.strip_prefix("/api/target-bindings/") {
|
||||
let value=match method.as_str() {
|
||||
"GET"=>crate::target_bindings::resolve(s,target)?,
|
||||
"PUT"=>{
|
||||
let mutation=serde_json::from_value(body).map_err(|_|AppError::Validation("关联参数无效".into()))?;
|
||||
crate::target_bindings::save(s,target,mutation)?
|
||||
},
|
||||
_=>return Err(AppError::NotFound("关联接口不存在")),
|
||||
};
|
||||
return Ok(json_response(StatusCode::OK,value));
|
||||
}
|
||||
if path=="/api/appearance" && (method=="GET" || method=="PATCH") {
|
||||
let value=if method=="GET" { crate::appearance::load(&s.db)? } else { crate::appearance::save(&mut s.db,body)? };
|
||||
return Ok(json_response(StatusCode::OK,serde_json::to_value(value).map_err(|e|AppError::Internal(e.to_string()))?));
|
||||
|
||||
@@ -9,6 +9,7 @@ mod monitoring;
|
||||
mod realtime;
|
||||
mod receiver;
|
||||
mod store;
|
||||
mod target_bindings;
|
||||
mod target_lists;
|
||||
mod web_assets {
|
||||
include!(concat!(env!("OUT_DIR"), "/web_assets.rs"));
|
||||
|
||||
+33
-8
@@ -40,15 +40,19 @@ struct Manager {
|
||||
}
|
||||
|
||||
fn executable() -> Option<PathBuf> {
|
||||
std::env::var_os("RID_MAP_DOWNLOADER")
|
||||
.map(PathBuf::from)
|
||||
.or_else(|| {
|
||||
std::env::current_exe()
|
||||
.ok()?
|
||||
.parent()
|
||||
.map(|p| p.join("rid-map-downloader.exe"))
|
||||
resolve_executable(
|
||||
std::env::var_os("RID_MAP_DOWNLOADER").map(PathBuf::from),
|
||||
std::env::current_exe().ok(),
|
||||
)
|
||||
}
|
||||
fn resolve_executable(
|
||||
override_path: Option<PathBuf>,
|
||||
application: Option<PathBuf>,
|
||||
) -> Option<PathBuf> {
|
||||
override_path.filter(|p| p.is_file()).or_else(|| {
|
||||
let adjacent = application?.parent()?.join("rid-map-downloader.exe");
|
||||
adjacent.is_file().then_some(adjacent)
|
||||
})
|
||||
.filter(|p| p.is_file())
|
||||
}
|
||||
fn read_preferences(root: &Path) -> Result<Preferences, String> {
|
||||
let path = root.join("preferences.json");
|
||||
@@ -332,6 +336,27 @@ mod tests {
|
||||
http::Request,
|
||||
};
|
||||
use tower::ServiceExt;
|
||||
#[test]
|
||||
fn downloader_uses_portable_copy_when_override_is_missing_or_stale() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let application = temp.path().join("fpv-rid-registry.exe");
|
||||
let adjacent = temp.path().join("rid-map-downloader.exe");
|
||||
std::fs::write(&adjacent, b"portable downloader").unwrap();
|
||||
for override_path in [None, Some(temp.path().join("old-tools/downloader.exe"))] {
|
||||
assert_eq!(
|
||||
resolve_executable(override_path, Some(application.clone())),
|
||||
Some(adjacent.clone())
|
||||
);
|
||||
}
|
||||
let configured = temp.path().join("configured.exe");
|
||||
std::fs::write(&configured, b"configured downloader").unwrap();
|
||||
assert_eq!(
|
||||
resolve_executable(Some(configured.clone()), Some(application.clone())),
|
||||
Some(configured)
|
||||
);
|
||||
std::fs::remove_file(adjacent).unwrap();
|
||||
assert_eq!(resolve_executable(None, Some(application)), None);
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn shutdown_does_not_allow_a_new_job_to_reset_cancellation() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -139,6 +139,7 @@ impl Store {
|
||||
"CREATE TABLE IF NOT EXISTS app_settings(key TEXT PRIMARY KEY,value TEXT NOT NULL);",
|
||||
)?;
|
||||
db.execute_batch("PRAGMA foreign_keys=ON; CREATE TABLE IF NOT EXISTS records(id TEXT PRIMARY KEY,serial_no TEXT NOT NULL UNIQUE,uas_code TEXT NOT NULL UNIQUE,model_name TEXT NOT NULL DEFAULT '',owner_name TEXT NOT NULL DEFAULT '',created_at TEXT NOT NULL); CREATE TABLE IF NOT EXISTS photos(record_id TEXT NOT NULL REFERENCES records(id) ON DELETE CASCADE,slot INTEGER NOT NULL CHECK(slot IN (1,2)),mime_type TEXT NOT NULL,image BLOB NOT NULL,PRIMARY KEY(record_id,slot)); CREATE TABLE IF NOT EXISTS registry_meta(key TEXT PRIMARY KEY,value TEXT NOT NULL);")?;
|
||||
crate::target_bindings::init(&db)?;
|
||||
let tx = db.transaction_with_behavior(rusqlite::TransactionBehavior::Immediate)?;
|
||||
let done: bool = tx.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM registry_meta WHERE key='legacy_import_done')",
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
//! Explicit RID-to-record associations; classification remains attached to the RID identity.
|
||||
use crate::{error::Result, store::Store};
|
||||
use rusqlite::{Connection, OptionalExtension, params};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
pub fn init(db: &Connection) -> Result<()> {
|
||||
db.execute_batch("CREATE TABLE IF NOT EXISTS target_record_bindings(
|
||||
target_id TEXT PRIMARY KEY COLLATE BINARY,
|
||||
record_id TEXT NOT NULL REFERENCES records(id) ON DELETE CASCADE
|
||||
); CREATE INDEX IF NOT EXISTS target_record_binding_record ON target_record_bindings(record_id);")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(target: &str) -> Result<()> {
|
||||
if !rid_shared::target_lists::valid_target_id(target) {
|
||||
return Err("RID 目标标识无效".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn bound(db: &Connection, target: &str) -> Result<Option<String>> {
|
||||
Ok(db
|
||||
.query_row(
|
||||
"SELECT record_id FROM target_record_bindings WHERE target_id=?1",
|
||||
[target],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.optional()?)
|
||||
}
|
||||
|
||||
pub fn resolve(store: &Store, target: &str) -> Result<Value> {
|
||||
validate(target)?;
|
||||
let binding = bound(&store.db, target)?;
|
||||
let automatic: Option<String> = if binding.is_none() {
|
||||
store
|
||||
.db
|
||||
.query_row(
|
||||
"SELECT id FROM records WHERE serial_no=?1 COLLATE BINARY",
|
||||
[target],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.optional()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let id = binding.as_ref().or(automatic.as_ref());
|
||||
let record = id
|
||||
.map(|id| store.get(id).map(crate::archive::public))
|
||||
.transpose()?;
|
||||
Ok(
|
||||
json!({"targetId":target,"bindingRecordId":binding,"matchSource":if binding.is_some(){"manual"}else if automatic.is_some(){"serial"}else{"none"},"record":record}),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct Mutation {
|
||||
// Required JSON null or string prevents clients silently omitting concurrency checks.
|
||||
expected_record_id: Value,
|
||||
record_id: Value,
|
||||
}
|
||||
|
||||
fn nullable_id(value: &Value) -> Result<Option<&str>> {
|
||||
match value {
|
||||
Value::Null => Ok(None),
|
||||
Value::String(id) if crate::store::valid_id(id) => Ok(Some(id)),
|
||||
_ => Err("档案标识无效".into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(store: &mut Store, target: &str, mutation: Mutation) -> Result<Value> {
|
||||
validate(target)?;
|
||||
let expected = nullable_id(&mutation.expected_record_id)?;
|
||||
let record = nullable_id(&mutation.record_id)?;
|
||||
let tx = store
|
||||
.db
|
||||
.transaction_with_behavior(rusqlite::TransactionBehavior::Immediate)?;
|
||||
if bound(&tx, target)?.as_deref() != expected {
|
||||
return Err("关联已被其他页面修改,请刷新关联后重试".into());
|
||||
}
|
||||
if let Some(id) = record {
|
||||
let exists: bool = tx.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM records WHERE id=?1)",
|
||||
[id],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
if !exists {
|
||||
return Err("登记档案已不存在,请重新搜索".into());
|
||||
}
|
||||
tx.execute("INSERT INTO target_record_bindings(target_id,record_id) VALUES(?1,?2) ON CONFLICT(target_id) DO UPDATE SET record_id=excluded.record_id",params![target,id])?;
|
||||
} else {
|
||||
tx.execute(
|
||||
"DELETE FROM target_record_bindings WHERE target_id=?1",
|
||||
[target],
|
||||
)?;
|
||||
}
|
||||
tx.commit()?;
|
||||
resolve(store, target)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
fn change(expected: Option<&str>, record: Option<&str>) -> Mutation {
|
||||
serde_json::from_value(json!({"expectedRecordId":expected,"recordId":record})).unwrap()
|
||||
}
|
||||
#[test]
|
||||
fn association_persists_is_exact_and_preserves_classification() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut s = Store::open(dir.path().into()).unwrap();
|
||||
let r = s
|
||||
.register(json!({"serialNo":"SERIAL-001","modelName":"Test","ownerName":"Owner"}))
|
||||
.unwrap();
|
||||
let id = r["record"]["id"].as_str().unwrap();
|
||||
assert_eq!(resolve(&s, "SERIAL-001").unwrap()["matchSource"], "serial");
|
||||
assert!(resolve(&s, "serial-001").unwrap()["record"].is_null());
|
||||
crate::target_lists::save(
|
||||
&mut s.db,
|
||||
"RID-001",
|
||||
rid_shared::target_lists::Mutation {
|
||||
list_kind: rid_shared::target_lists::ListKind::Black,
|
||||
note: String::new(),
|
||||
expected_revision: 0,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let result = save(&mut s, "RID-001", change(None, Some(id))).unwrap();
|
||||
assert_eq!(result["record"]["serialNo"], "SERIAL-001");
|
||||
assert_eq!(result["matchSource"], "manual");
|
||||
assert!(save(&mut s, "RID-001", change(None, None)).is_err());
|
||||
assert!(save(&mut s, "RID-001", change(Some(id), Some(&"f".repeat(36)))).is_err());
|
||||
drop(s);
|
||||
let mut s = Store::open(dir.path().into()).unwrap();
|
||||
assert_eq!(resolve(&s, "RID-001").unwrap()["bindingRecordId"], id);
|
||||
save(&mut s, "RID-001", change(Some(id), None)).unwrap();
|
||||
assert!(resolve(&s, "RID-001").unwrap()["record"].is_null());
|
||||
assert_eq!(crate::target_lists::load(&s.db).unwrap().entries.len(), 1);
|
||||
save(&mut s, "RID-001", change(None, Some(id))).unwrap();
|
||||
s.delete(id, None).unwrap();
|
||||
assert!(resolve(&s, "RID-001").unwrap()["record"].is_null());
|
||||
assert!(resolve(&s, "bad id").is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn http_binding_validation_and_origin_protection() {
|
||||
use axum::{body::Body, http::Request};
|
||||
use tower::ServiceExt;
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut store = Store::open(dir.path().into()).unwrap();
|
||||
let r = store.register(json!({"serialNo":"HTTP-001"})).unwrap();
|
||||
let id = r["record"]["id"].as_str().unwrap().to_owned();
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<crate::Job>(8);
|
||||
let worker = std::thread::spawn(move || {
|
||||
while let Some(crate::Job::Execute(job)) = rx.blocking_recv() {
|
||||
job(&mut store);
|
||||
}
|
||||
});
|
||||
let app = crate::http::router(crate::Worker(tx));
|
||||
for (method, body, origin, status) in [
|
||||
("PUT", json!({"recordId":id}), None, 400),
|
||||
(
|
||||
"PUT",
|
||||
json!({"expectedRecordId":null,"recordId":id}),
|
||||
Some("https://foreign.example"),
|
||||
403,
|
||||
),
|
||||
(
|
||||
"PUT",
|
||||
json!({"expectedRecordId":null,"recordId":id}),
|
||||
None,
|
||||
200,
|
||||
),
|
||||
("GET", Value::Null, None, 200),
|
||||
(
|
||||
"PUT",
|
||||
json!({"expectedRecordId":null,"recordId":null}),
|
||||
None,
|
||||
400,
|
||||
),
|
||||
(
|
||||
"PUT",
|
||||
json!({"expectedRecordId":id,"recordId":null}),
|
||||
None,
|
||||
200,
|
||||
),
|
||||
] {
|
||||
let mut request = Request::builder()
|
||||
.method(method)
|
||||
.uri("/api/target-bindings/RID-HTTP");
|
||||
if let Some(origin) = origin {
|
||||
request = request.header("origin", origin);
|
||||
}
|
||||
let response = app
|
||||
.clone()
|
||||
.oneshot(request.body(Body::from(body.to_string())).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status().as_u16(), status, "{method} {body}");
|
||||
if method == "GET" {
|
||||
let bytes = axum::body::to_bytes(response.into_body(), 65536)
|
||||
.await
|
||||
.unwrap();
|
||||
let value: Value = serde_json::from_slice(&bytes).unwrap();
|
||||
assert_eq!(value["record"]["serialNo"], "HTTP-001");
|
||||
}
|
||||
}
|
||||
drop(app);
|
||||
worker.join().unwrap();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ cd /d "%~dp0"
|
||||
if exist "%~dp0fpv-rid-registry.exe" (
|
||||
"%~dp0fpv-rid-registry.exe"
|
||||
) else if exist "D:\Rust_Contact\util\target\Rid_Drone_Receivev\release\fpv-rid-registry-fullstack.exe" (
|
||||
if not exist "%RID_MAP_DOWNLOADER%" set "RID_MAP_DOWNLOADER=D:\Rust_Contact\util\tools\rid-map-downloader\0.1.0\rid-map-downloader.exe"
|
||||
"D:\Rust_Contact\util\target\Rid_Drone_Receivev\release\fpv-rid-registry-fullstack.exe" --data-root "%~dp0."
|
||||
) else (
|
||||
echo Build first: cargo xtask package
|
||||
|
||||
Reference in New Issue
Block a user