feat: JNPF 7.0 通用资产包独立分发,示例数据与官方 init SQL 对齐

- 新增 pack-jnpf-assets.sh:web 构建产物 + 示例数据库种子按 JNPF 版本单独出包,
  与 sspf 版本、OS/CPU、工具链解耦;manifest 声明版本绑定,SHA256SUMS 可逐项校验。
- demo_seed.sql 以官方 jnpf_dbnull_init.sql 为真源:58 表 / 14242 行,
  补齐行政区划、国际化、地图三张表,DDL 幂等可重复启动。
- 新增 SSW_ASSETS_DIR / SSW_DEMO_SEED_FILE 外置加载,编译期内嵌为兜底;
  换 JNPF 版本的演示数据无需重编二进制;release.sh 以资产包为 web/ 唯一真源,
  并加 --no-web 剥离选项。
- 修 SSW_STATIC_DIR 相对路径在 PGlite chdir 后失效;补 14 张官方图标并加
  /api/file/Image 精确白名单,其它 /api/** 仍保持信封 404。
- 新增 65 页 A/B 走查报告与 CHANGELOG v0.5.0 条目:UI/路由/接口形状与
  init SQL 基础数据页已 1:1,运行时业务数据页差异源于参考库额外演示数据。
This commit is contained in:
admin committed 2026-11-06 15:50:15 +08:00
1 parent 8af5b901b5
commit d8a9d16d2c
37 files changed
+79350 -36

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1018 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

File diff suppressed because it is too large. Load diff
+59 -1
View File
@@ -26,6 +26,7 @@
//! (`packs_gen.rs` / `modules/mod.rs` / `Cargo.toml` / `contract.md`)。
//! **本文件一行都不用改** —— 包的清单在 `crate::packs_gen`(生成的)。
use std::path::Path;
use std::sync::OnceLock;
use axum::Router;
@@ -94,8 +95,65 @@ pub async fn ensure_base(db: &Db) -> Result<(), pglite::Error> {
///
/// 🔴 平台层 [`seed::ensure_base`] 只认「传进来的 `MenuSpec` 列表」,不认业务 ⇒
/// 谁给清单谁负责(本仓 = [`ensure_base`];外部业务仓 = 门面注入)。
///
/// 🔴 **这里无条件并入「官方 JNPF 7.0 菜单清单」**(`sspf_compat_system::menus`):
/// 它不是业务菜单,是**官方前端能渲染出页面**所必需的路由表 ——
///
/// ```text
/// 官方前端 generate-routes-backend.ts:
/// route.path = '/' + node.urlAddress
/// route.component = pageMap[node.pageAddress ?? node.urlAddress]
/// └─ pageMap = import.meta.glob('../views/**/*.vue')
/// ```
///
/// ⇒ 少种这一份 ⇒ 前端**一条动态路由都注册不出来** ⇒ 每个页面都显示
/// 「哎呀!未找到页面」⇒ **后端端点再全也一个都不会被调用**
/// (实测:本仓 65 个菜单全 404,真实后端调用只有 21 个;
/// 官方同 65 个菜单 ⇒ 163 个端点)。
///
/// ⇒ 放在**装配根**(本文件)而不是平台层 ⇒ 平台层(`sspf-core`)不碰
/// 官方形状 ⇒ 闸门 CP6(平台层菜单条数由契约推导)不受影响。
pub async fn ensure_base_with(db: &Db, menus: &[MenuSpec]) -> Result<(), pglite::Error> {
seed::ensure_base(db, menus).await
let mut all: Vec<MenuSpec> = menus.to_vec();
all.extend_from_slice(sspf_compat_core::menus::official_menus());
seed::ensure_base(db, &all).await
}
/// 🔴 **导入官方 JNPF 7.0 示例数据**(幂等,每次启动都跑)。
///
/// 🔴 **为什么不在 [`ensure_base_with`] 里**:
/// - `ensure_base_with` 被 **40+ 个集成测试**调用 ⇒ 把示例数据塞进去
/// ⇒ 测试里的**行数断言全崩**(`base_dictionary_data` 期望 13 行、
/// `base_business_category` 期望 38 行 …)。
/// - ⇒ 示例数据是**「启动时灌」**,不是**「种子结构」** ⇒ 独立入口。
///
/// 🔴 **为什么放在装配根**(本文件)而不是平台层:
/// 示例数据是**官方形状的知识**(官方有哪些表 / 哪些列 / 哪些行)
/// ⇒ 平台层不许认识它(红线 12 / 闸门 CP1)⇒ 实现放在**契约面**
/// (`sspf_compat_core::demo_data`),本文件只做**接线**。
///
/// - `db`:库句柄。
/// - `seed_file`:**外置**示例数据 SQL(`SSW_ASSETS_DIR` / `SSW_DEMO_SEED_FILE` 推导)。
/// `None` ⇒ 用二进制编译期内嵌的那份。
///
/// 🔴 **为什么要外置**:示例数据只跟 **JNPF 版本**有关,跟 sspf 版本 / 平台 / 环境无关
/// ⇒ 单独打「JNPF 通用资产包」,换演示数据不需要重编二进制。
/// 读不到文件(路径错 / 权限)时**告警后回退内嵌**,绝不让服务起不来。
pub async fn ensure_demo_data(db: &Db, seed_file: Option<&Path>) -> Result<(), pglite::Error> {
if let Some(p) = seed_file {
match std::fs::read_to_string(p) {
Ok(sql) => {
eprintln!("[demo-data] 使用外置 JNPF 资产包示例数据: {}", p.display());
return sspf_compat_core::demo_data::ensure_demo_data_sql(db, &sql).await;
}
Err(e) => eprintln!(
"[demo-data] 外置示例数据读取失败({}: {}),回退编译期内嵌",
p.display(),
e
),
}
}
sspf_compat_core::demo_data::ensure_demo_data(db).await
}
/// 🔴 **装载全部业务包** —— 委托给**生成**的包清单 [`crate::packs_gen`]。
+69 -2
View File
@@ -2643,8 +2643,9 @@ pub fn build_app(state: AppState) -> axum::Router {
///
/// 🔴 **`extras.static_dir` 只影响平台默认 fallback**:
/// - `None` ⇒ 未命中就是信封 404(与历史行为**逐字一致**);
/// - `Some(dir)` ⇒ `/api/**` 仍是信封 404;其它未命中路径先找静态文件,
/// 找不到再回退 `index.html`(前端 history 路由的深链);
/// - `Some(dir)` ⇒ `/api/**` 仍是信封 404(**唯一例外**:`/api/file/Image/**`
/// 命中资产包里的同名图片文件时返文件,官方图标资源走的就是这个路径);
/// 其它未命中路径先找静态文件,找不到再回退 `index.html`(前端 history 路由的深链);
/// - `extras.fallback` 给了值 ⇒ 用 `fallback_service`,**忽略** `static_dir`。
pub fn build_app_with(state: AppState, mut extras: Extras) -> axum::Router {
// 🔴 第二阶段的三个注入点先 take 出来;剩下的 Extras 整体交给 build_router_with。
@@ -2687,6 +2688,24 @@ pub fn build_app_with(state: AppState, mut extras: Extras) -> axum::Router {
async fn fallback_response(static_dir: Option<PathBuf>, req: Request) -> Response {
if let Some(dir) = static_dir {
let path = req.uri().path();
// 🔴 **官方文件资源例外**:JNPF 前端把数据库类型图标 / AI 模型图标放在
// `/api/file/Image/**`,这些是**文件**,不是接口。官方后端用 302 重定向到
// 文件服务;同源静态托管没有文件服务 ⇒ 之前全返信封 404(图标不显示,
// 控制台 9 条 404)。JNPF 资产包把这些图片放在
// `<static_dir>/api/file/Image/...` ⇒ 命中就返文件;**未命中仍走信封 404**
// ⇒ `/api/**` 的 404 契约不变,只是多了这一个精确白名单。
if path.starts_with("/api/file/Image/")
&& matches!(*req.method(), Method::GET | Method::HEAD)
{
if let Some(decoded) = percent_decode_path(path) {
if let Some(mut resp) = serve_from(&dir, &decoded).await {
if req.method() == Method::HEAD {
*resp.body_mut() = Body::empty();
}
return resp;
}
}
}
// 🔴 `/api/**` **永远**走信封 404 —— 静态托管不许吞掉接口的 404 契约。
if !path.starts_with("/api/") && path != "/api" {
if matches!(*req.method(), Method::GET | Method::HEAD) {
@@ -2730,6 +2749,34 @@ async fn serve_file(path: &Path) -> Option<Response> {
Some(resp)
}
/// 百分号解码 URL 路径(**仅**给 `/api/file/Image/**` 的中文文件名用)。
///
/// 🔴 安全:解码结果里出现 `/` / `\` / NUL 一律拒绝 ⇒ `%2F` 之类不能凭空造出
/// 路径分隔符;解码完还会再走一遍 [`safe_rel_path`] 的 `..` / 穿越检查。
fn percent_decode_path(p: &str) -> Option<String> {
let b = p.as_bytes();
let mut out = Vec::with_capacity(b.len());
let mut i = 0usize;
while i < b.len() {
if b[i] == b'%' {
if i + 2 >= b.len() {
return None;
}
let hex = std::str::from_utf8(&b[i + 1..i + 3]).ok()?;
let v = u8::from_str_radix(hex, 16).ok()?;
if v == b'/' || v == b'\\' || v == 0 {
return None;
}
out.push(v);
i += 3;
} else {
out.push(b[i]);
i += 1;
}
}
String::from_utf8(out).ok()
}
/// URL 路径 ⇒ 相对路径。**拒绝** `..` / 反斜杠 / NUL(目录穿越)。
fn safe_rel_path(url_path: &str) -> Option<PathBuf> {
let mut out = PathBuf::new();
@@ -2932,6 +2979,26 @@ mod tests {
use sspf_core::session::{SessionStore, TicketStore};
use crate::test_support;
/// `/api/file/Image/**` 的中文文件名要百分号解码;`%2F` 不许造出路径分隔符。
#[test]
fn percent_decode_path_handles_chinese_and_blocks_traversal() {
assert_eq!(
percent_decode_path(
"/api/file/Image/databaseicon/%E8%87%AA%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E5%BA%93.png"
),
Some("/api/file/Image/databaseicon/自定义数据库.png".to_string())
);
assert_eq!(
percent_decode_path("/api/file/Image/AiFile/a.png"),
Some("/api/file/Image/AiFile/a.png".to_string())
);
// 解码后含 `/` ⇒ 拒绝(目录穿越);非法 hex ⇒ 拒绝。
assert_eq!(percent_decode_path("/api/file/Image/a%2Fb.png"), None);
assert_eq!(percent_decode_path("/api/file/Image/a%5Cb.png"), None);
assert_eq!(percent_decode_path("/api/file/Image/a%ZZ.png"), None);
assert_eq!(percent_decode_path("/api/file/Image/a%"), None);
}
/// 全进程共享的临时库(pglite 进程级全局单例 ⇒ 只能开一次,所有单测共用)。
async fn db() -> &'static Db {
test_support::shared_db().await