feat(content): 分组对所有内容类型生效,统一分区/分组/条目模型

- 分区=容器,分组=任意类型的可选子容器,条目可挂分区或分组(直属分区)
- catalog 所有类型统一输出 groups + items,条目查询按节点取
- 详情/侧栏/首页卡片预览支持所有类型的分组;多组显示小标题 + 未分组
- 后台「分区」「侧栏导航」对所有类型可建组;「内容」弹窗分组可选直属分区,编辑可换组
- 修复首页卡片配置为「整个分区」时预览为空
- 测试 59 passed
This commit is contained in:
2026-10-30 18:56:17 +08:00
parent cc08188c1e
commit c84c41dc7d
11 changed files with 264 additions and 200 deletions
+13 -21
View File
@@ -361,22 +361,17 @@ pub fn create_group(conn: &mut Connection, section_id: &str, new: NewGroup) -> R
return Err(StashError::InvalidDirectory("分组标题需为 1–40 个字".into()));
}
let view_mode: Option<String> = conn
let section_exists: Option<String> = conn
.query_row(
"SELECT view_mode FROM node WHERE key = ?1 AND kind = 'section'",
"SELECT key FROM node WHERE key = ?1 AND kind = 'section'",
[section_id],
|row| row.get(0),
)
.optional()
.map_err(map_error)?;
let Some(view_mode) = view_mode else {
if section_exists.is_none() {
return Err(StashError::NotFound(format!("分区不存在: {section_id}")));
};
if view_mode != "apps" {
return Err(StashError::InvalidDirectory(
"只有应用类分区可以添加分组".into(),
));
}
let exists: i64 = conn
@@ -712,21 +707,18 @@ mod tests {
}
#[test]
fn groups_only_under_apps_sections() {
fn groups_under_any_kind_of_section() {
let mut conn = db();
create(&mut conn, section("films", "电影", "posters")).expect("应能创建");
assert!(
create_group(
&mut conn,
"films",
NewGroup {
id: "g1".into(),
title: "分组".into()
}
)
.is_err(),
"海报分区不能建分组"
);
create_group(
&mut conn,
"films",
NewGroup {
id: "g1".into(),
title: "片单".into(),
},
)
.expect("海报分区也应能建分组");
}
#[test]