fix(mindspace): 修复删除时无法解析 MySQL JSON 导致页面复活
source_snapshot_json 在 mysql2 中已是对象,JSON.parse 失败会使 relative_path 丢失、工作区 HTML 未清理;同步后页面重新出现。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+11
-6
@@ -52,6 +52,16 @@ async function findPageByWorkspaceRelativePath(pool, userId, relativePath) {
|
||||
return { id: row.id, updatedAt: Number(row.updated_at ?? 0) };
|
||||
}
|
||||
|
||||
function parseJsonColumn(value, fallback = {}) {
|
||||
if (value == null || value === '') return { ...fallback };
|
||||
if (typeof value === 'object' && !Buffer.isBuffer(value)) return value;
|
||||
try {
|
||||
return JSON.parse(String(value));
|
||||
} catch {
|
||||
return { ...fallback };
|
||||
}
|
||||
}
|
||||
|
||||
async function loadIndexedWorkspacePages(pool, userId) {
|
||||
const [rows] = await pool.query(
|
||||
`SELECT p.id, p.updated_at, p.source_asset_id, pv.source_snapshot_json
|
||||
@@ -62,12 +72,7 @@ async function loadIndexedWorkspacePages(pool, userId) {
|
||||
);
|
||||
const byPath = new Map();
|
||||
for (const row of rows) {
|
||||
let snapshot = {};
|
||||
try {
|
||||
snapshot = JSON.parse(row.source_snapshot_json ?? '{}');
|
||||
} catch {
|
||||
snapshot = {};
|
||||
}
|
||||
const snapshot = parseJsonColumn(row.source_snapshot_json);
|
||||
const relativePath = normalizePublicHtmlPath(snapshot.relative_path);
|
||||
if (relativePath) {
|
||||
byPath.set(relativePath, {
|
||||
|
||||
Reference in New Issue
Block a user