Add page data delivery and publication guards
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user