Add page data delivery and publication guards

This commit is contained in:
john
2026-07-08 21:10:47 +08:00
parent 8d629e7a4e
commit eea14c1855
66 changed files with 3035 additions and 413 deletions
+14
View File
@@ -1,7 +1,21 @@
import fs from 'node:fs';
import path from 'node:path';
import { normalizeWorkspaceRelativePath } from './mindspace-pages.mjs';
import { resolvePublishDir } from './user-publish.mjs';
export { normalizeWorkspaceRelativePath };
export async function readWorkspacePublishHtml(h5Root, userId, relativePath) {
const normalized = normalizeWorkspaceRelativePath(relativePath);
if (!h5Root || !userId || !normalized) return null;
const filePath = path.join(resolvePublishDir(h5Root, { id: userId }), ...normalized.split('/'));
try {
return await fs.promises.readFile(filePath, 'utf8');
} catch {
return null;
}
}
export function resolvePageWorkspaceRelativePath(snapshot) {
if (!snapshot || typeof snapshot !== 'object') return null;
return normalizeWorkspaceRelativePath(snapshot.relative_path) || null;