Files
memind/mindspace-workspace-path.mjs
T

26 lines
798 B
JavaScript
Raw Normal View History

import fs from 'node:fs';
import path from 'node:path';
import {
normalizeWorkspaceRelativePath,
resolveAssetWorkspaceRelativePath,
resolvePageWorkspaceRelativePath,
} from './mindspace-workspace-relative-path.mjs';
import { resolvePublishDir } from './user-publish.mjs';
export {
normalizeWorkspaceRelativePath,
resolveAssetWorkspaceRelativePath,
resolvePageWorkspaceRelativePath,
};
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;
}
}