feat(mindspace): enforce PostgreSQL user data delivery
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user