feat(mindspace): enforce PostgreSQL user data delivery

This commit is contained in:
john
2026-07-13 15:29:29 +08:00
parent b33c943b69
commit a6620fb719
57 changed files with 2779 additions and 164 deletions
+17 -4
View File
@@ -436,10 +436,20 @@ export function createWorkspaceAssetSync({
}
};
const syncCategory = async (userId, categoryCode, source = {}) => {
const syncCategory = async (userId, categoryCode, source = {}, { onlyRelativePaths = null } = {}) => {
if (!h5Root) return { imported: 0, updated: 0, skipped: 0 };
const workspaceRoot = resolveUserWorkspaceRoot(h5Root, { id: userId });
const files = await listWorkspaceZoneFiles(workspaceRoot, categoryCode);
let files = await listWorkspaceZoneFiles(workspaceRoot, categoryCode);
if (onlyRelativePaths != null) {
const allowed = new Set(
onlyRelativePaths
.map((item) => normalizeWorkspaceRelativePath(item))
.filter(Boolean),
);
files = files.filter((file) =>
allowed.has(normalizeWorkspaceRelativePath(`${categoryCode}/${file.filename}`)),
);
}
const [categories] = await pool.query(
`SELECT c.id, c.space_id, c.category_code
FROM h5_space_categories c
@@ -487,14 +497,17 @@ export function createWorkspaceAssetSync({
return { imported, updated, skipped };
};
const syncUserWorkspace = async (userId, { categoryCode, sourceSessionId, sourceMessageId, title } = {}) => {
const syncUserWorkspace = async (
userId,
{ categoryCode, sourceSessionId, sourceMessageId, title, onlyRelativePaths = null } = {},
) => {
const codes = categoryCode ? [categoryCode] : UPLOAD_ZONE_CODES;
let imported = 0;
let updated = 0;
let skipped = 0;
const source = { sessionId: sourceSessionId, messageId: sourceMessageId, title };
for (const code of codes) {
const result = await syncCategory(userId, code, source);
const result = await syncCategory(userId, code, source, { onlyRelativePaths });
imported += result.imported;
updated += result.updated;
skipped += result.skipped;