fix(XZH-21): 统一回收站路由与模块标签、历史旧口径对齐、升级后会话不再误判
- AdminTools.vue: 回收站恢复/永久删除统一走 /admin-tools/trash/{kind}/{id}(RSS/提示词/工作流/收集箱此前拼到 /library → 404);模块标签改由后端 /admin-tools/trash/kinds 提供;过滤下拉覆盖全部 11 个模块
- adminRoutes.ts: moduleNames 与后端 TrashService 对齐(笔记/素材…),补 prompts/flows/inbox
- AdminToolsController: TRASH 视图限定 planner kind;新增 GET /admin-tools/trash/kinds
- LibraryController: /library/{kind}/trash 接受全部 kind,与 /admin-tools/trash 行为一致;删除通知标题列改用 TrashService.titleColumn(笔记不再写成素材)
- NotesController: history/{n} 对旧口径行按「≤n 的最大旧版本号」解析,旧库升级后最高一版保存前内容可读、恢复写回正确内容
- App.vue: 401 先确认 /auth/me,避免切模块时偶发 401 清掉登录态导致白屏
This commit is contained in:
1 parent
a60ea8d262
commit
bd8264b8cf
6 files changed
+84
-30
No files matched your search
@@ -32,13 +32,25 @@ public class AdminToolsController {
|
||||
union all select 'blogs',id,title,deleted_at,category from blogs
|
||||
union all select 'bookmarks',id,title,deleted_at,category from bookmarks
|
||||
union all select 'assets',id,name,deleted_at,category from assets
|
||||
union all select kind,id,title,deleted_at,'' from planner_items
|
||||
union all select kind,id,title,deleted_at,'' from planner_items where kind in ('tasks','events','snippets')
|
||||
union all select 'rss',id,title,deleted_at,category from rss_sources
|
||||
union all select 'prompts',id,title,deleted_at,category from ai_prompts
|
||||
union all select 'flows',id,title,deleted_at,'' from workspace_flows
|
||||
union all select 'inbox',id,title,deleted_at,'收集箱' from inbox_items
|
||||
""";
|
||||
|
||||
/**
|
||||
* 回收站每个 kind 的表与标题列。前端据此决定调用哪个回收站接口,
|
||||
* 新增模块只需改 TrashService 一处,不再在前端重复维护 kind → 路由映射。
|
||||
*/
|
||||
@GetMapping("/trash/kinds")
|
||||
public List<Map<String,Object>> trashKinds() {
|
||||
List<Map<String,Object>> kinds=new ArrayList<>();
|
||||
for(String kind:TrashService.KINDS) kinds.add(Map.of("kind",kind,"label",TrashService.label(kind),
|
||||
"titleColumn",TrashService.titleColumn(kind),"planner",TrashService.isPlanner(kind)));
|
||||
return kinds;
|
||||
}
|
||||
|
||||
public record Name(@NotBlank @Size(max=60) String name) {}
|
||||
public record Flow(@NotBlank @Size(max=60) String title,@NotBlank @Size(max=8000) String instructions) {}
|
||||
public record Preferences(@NotBlank @Size(max=60) String display_name,@NotNull @Size(max=300) String bio, boolean autosave) {}
|
||||
|
||||
@@ -160,32 +160,37 @@ public class LibraryController {
|
||||
+ " where id=? and deleted_at is null", id);
|
||||
}
|
||||
|
||||
/** 回收站列表只覆盖知识库类模块;RSS/提示词/工作流/收集箱用 /admin-tools/trash。 */
|
||||
@GetMapping("/{kind}/trash")
|
||||
public List<Map<String, Object>> trashList(@PathVariable String kind,
|
||||
@RequestParam(defaultValue = "0") @Min(0) int offset) {
|
||||
checkKind(kind);
|
||||
return db.queryForList("select id," + (kind.equals("assets") ? "name as title" : "title")
|
||||
return db.queryForList("select id," + TrashService.titleColumn(kind) + " as title"
|
||||
+ ",deleted_at from " + kind + " where deleted_at is not null order by deleted_at desc,id limit 100 offset ?", offset);
|
||||
}
|
||||
|
||||
/** 回收站恢复/永久删除统一走 TrashService,分类缺失时自动补回。 */
|
||||
/**
|
||||
* 回收站恢复/永久删除统一走 TrashService,分类缺失时自动补回。
|
||||
* 接受 TrashService 的全部 kind,与 /admin-tools/trash/{kind}/{id} 等价,避免同一记录在两套路由上行为不同。
|
||||
*/
|
||||
@PostMapping("/{kind}/trash/{id}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void restore(@PathVariable String kind, @PathVariable UUID id) {
|
||||
checkKind(kind);
|
||||
TrashService.spec(kind);
|
||||
trash.restore(kind, id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{kind}/trash/{id}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void purge(@PathVariable String kind, @PathVariable UUID id) {
|
||||
checkKind(kind);
|
||||
TrashService.spec(kind);
|
||||
trash.purge(kind, id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private int trashOne(String kind, UUID id) {
|
||||
String title = db.queryForList("select " + (kind.equals("assets") ? "name" : "title") + " from " + kind
|
||||
// 标题列以 TrashService 为准:素材的标题列是 name,其余是 title
|
||||
String title = db.queryForList("select " + TrashService.titleColumn(kind) + " from " + kind
|
||||
+ " where id=? and deleted_at is null for update", String.class, id).stream().findFirst()
|
||||
.orElseThrow(LibraryController::missing);
|
||||
if (trash(kind, id) == 0) throw missing();
|
||||
|
||||
@@ -179,13 +179,28 @@ public class NotesController {
|
||||
|
||||
/**
|
||||
* 取历史 version 的内容。保存前快照以「保存后的版本号」写入,因此 history/N 永远是「第 N 版保存前的内容」,
|
||||
* 编号与 notes.version 连续、无空洞。旧口径(V18 之前写入的行)与新快照同号时以新快照为准。
|
||||
* 编号与 notes.version 连续、无空洞。旧口径(V18 之前写入的行)会按 legacy 映射归到对应版本号,见 {@link #legacyAnchor}。
|
||||
*/
|
||||
private Map<String, Object> contentAt(Map<String, Object> note, long version) {
|
||||
return db.queryForList("select title,body,category,folder,tags,star,saved_at from note_history"
|
||||
+ " where note_id=? and version=? order by legacy_versioning limit 1", note.get("id"), version)
|
||||
.stream().findFirst()
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "版本不存在"));
|
||||
return contentAt((UUID) note.get("id"), version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 某个版本号对应的「保存前内容」。新旧口径在库里的编号规则不同:
|
||||
* 新口径行 version=N 就是第 N 版保存前;旧口径行 version=N 是第 N 版保存前、第 N+1 版的内容,
|
||||
* 所以旧行只在「≤ N 的最大旧版本号」这一次被使用——旧库升级后最高版本的保存前内容正好在这一行。
|
||||
* 旧行不会压过更新的新快照(新快照优先),新保存的快照也不会被旧行顶替。读取与恢复共用这一份映射。
|
||||
*/
|
||||
private Map<String, Object> contentAt(UUID noteId, long version) {
|
||||
// 1) 同号行(新口径优先);2) 否则取旧口径锚点行:≤ N 的最大旧版本号,旧库没有更高版本的旧行时就是最高一版
|
||||
var row = db.queryForList("select * from note_history where note_id=? and version=?"
|
||||
+ " order by legacy_versioning limit 1", noteId, version).stream().findFirst();
|
||||
if (row.isEmpty() && version > 0)
|
||||
row = db.queryForList("select * from note_history where note_id=? and version=(select coalesce("
|
||||
+ " (select max(l.version) from note_history l where l.note_id=? and l.legacy_versioning and l.version<=?),"
|
||||
+ " (select n.version-1 from notes n where n.id=?))) and legacy_versioning", noteId, noteId, version, noteId)
|
||||
.stream().findFirst();
|
||||
return row.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "版本不存在"));
|
||||
}
|
||||
|
||||
public record Restore(@Min(0) Long currentVersion) {}
|
||||
@@ -197,10 +212,8 @@ public class NotesController {
|
||||
var current = lock(id);
|
||||
// 版本号可选:旧调用方仍传 currentVersion 做并发校验;新调用方不传,就以库内最新内容为准
|
||||
if (input != null && input.currentVersion() != null) checkVersion(current, input.currentVersion());
|
||||
// 恢复必须基于真实的历史行,不能落到「当前内容」兜底
|
||||
var old = db.queryForList("select title,body,category,folder,tags,star,saved_at from note_history"
|
||||
+ " where note_id=? and version=?", id, version).stream().findFirst()
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "版本不存在"));
|
||||
// 恢复必须基于真实的历史行,不能落到「当前内容」兜底;版本号解析与 GET /history/{version} 一致
|
||||
var old = contentAt(id, version);
|
||||
String category = db.queryForList("select name from note_categories where name=?",
|
||||
String.class, old.get("category")).stream().findFirst().orElse((String) current.get("category"));
|
||||
String tags = (String) old.get("tags");
|
||||
|
||||
Reference in new issue
Block a user