feat: harden orchestrator execution runtime

This commit is contained in:
john
2026-07-24 23:53:32 +08:00
parent 396bb78200
commit f6f2cd0933
55 changed files with 5122 additions and 194 deletions
+51
View File
@@ -2,6 +2,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { PUBLISH_KEY_UUID, PUBLISH_ROOT_DIR } from './user-publish.mjs';
import { normalizeWorkspaceRelativePath } from './mindspace-pages.mjs';
import { getPageDataPolicyIndexByWorkspacePath } from './page-data-policy-index.mjs';
const LOCAL_HOST_PATTERN = /^(localhost|127\.0\.0\.1|\[::1\]|192\.168\.|10\.|100\.)/i;
@@ -102,6 +103,56 @@ export function injectPublishedPageDataContext(html, { pageSource = null, public
});
}
export async function resolveMindSpacePageDataContext({
pool = null,
pageService = null,
userId,
relativePath,
logger = console,
} = {}) {
const normalizedUserId = String(userId ?? '').trim().toLowerCase();
const normalizedRelativePath = normalizeWorkspaceRelativePath(relativePath);
if (!normalizedUserId || !normalizedRelativePath) return null;
// Page Data policy lives in the Portal control plane. In split-service mode the
// generic MindSpace page service is remote, so it may not see a local binding
// immediately. Resolve the local binding index first and retain the page service
// as the compatibility fallback for ordinary published pages.
const indexed = await getPageDataPolicyIndexByWorkspacePath(
pool,
normalizedUserId,
normalizedRelativePath,
).catch((error) => {
logger?.warn?.(
`[MindSpace] failed to resolve local Page Data binding for ${normalizedUserId}/${normalizedRelativePath}: ${error?.message || error}`,
);
return null;
});
if (indexed?.pageId) {
return {
pageId: indexed.pageId,
accessMode: indexed.accessMode ?? null,
publicationId: indexed.publicationId ?? null,
};
}
if (typeof pageService?.findPageByRelativePath !== 'function') return null;
const page = await pageService
.findPageByRelativePath(normalizedUserId, normalizedRelativePath)
.catch((error) => {
logger?.warn?.(
`[MindSpace] failed to resolve remote page context for ${normalizedUserId}/${normalizedRelativePath}: ${error?.message || error}`,
);
return null;
});
if (!page?.id) return null;
return {
pageId: page.id,
accessMode: page.publicationAccessMode ?? null,
publicationId: page.currentPublishId ?? page.current_publish_id ?? null,
};
}
export const mindspacePublicPageContextInternals = {
LOCAL_HOST_PATTERN,
};