fix(page-data): deliver MindSpace workspace URLs instead of /u/.../pages/ routes.

Page Data questionnaires were returning publication slugs to users; password-mode
pages always fell back to /u/ routes. Prefer MindSpace paths at publish time and
rewrite mistaken delivery links in WeChat and Portal chat.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-12 13:54:24 +08:00
parent 048f25f580
commit 294e331a03
12 changed files with 1224 additions and 24 deletions
+30
View File
@@ -269,6 +269,36 @@ test('sanitizePublicHtmlLinksInText links existing inline public html paths', ()
}
});
test('sanitizePublicHtmlLinksInText rewrites own publication route links to MindSpace workspace urls', () => {
const owner = `test-user-${Date.now()}-pub-route`;
const publicRoot = path.join(process.cwd(), 'MindSpace', owner, 'public');
const previousBase = process.env.H5_PUBLIC_BASE_URL;
process.env.H5_PUBLIC_BASE_URL = 'https://m.tkmind.cn';
try {
fs.mkdirSync(publicRoot, { recursive: true });
fs.writeFileSync(
path.join(publicRoot, 'zhiqu-survey.html'),
'<!doctype html><title>问卷</title><script src="/assets/page-data-client.js"></script>',
);
fs.writeFileSync(
path.join(publicRoot, 'zhiqu-survey-admin.html'),
'<!doctype html><title>后台</title><script src="/assets/page-data-client.js"></script>',
);
const text = [
'问卷:https://m.tkmind.cn/u/john/pages/zhiqu-58bccceb',
'后台:https://m.tkmind.cn/u/john/pages/zhiqu-admin-98f11681',
].join('\n');
const next = sanitizePublicHtmlLinksInText(text, { id: owner, username: 'john' });
assert.doesNotMatch(next, /\/u\/john\/pages\//);
assert.match(next, new RegExp(`https://m\\.tkmind\\.cn/MindSpace/${owner}/public/zhiqu-survey\\.html`));
assert.match(next, new RegExp(`https://m\\.tkmind\\.cn/MindSpace/${owner}/public/zhiqu-survey-admin\\.html`));
} finally {
if (previousBase == null) delete process.env.H5_PUBLIC_BASE_URL;
else process.env.H5_PUBLIC_BASE_URL = previousBase;
fs.rmSync(path.join(process.cwd(), 'MindSpace', owner), { recursive: true, force: true });
}
});
test('sanitizeSessionConversationPublicHtmlLinks updates text items inside conversation messages', () => {
const owner = `test-user-${Date.now()}-conversation`;
const publicRoot = path.join(process.cwd(), 'MindSpace', owner, 'public');