/** * 重新绑定并刷新 john 的体验调研页发布快照与 Page Data 策略。 */ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { createDbPool } from '../db.mjs'; import { bindWorkspaceHtmlForPageData } from '../page-data-workspace-bind.mjs'; import { resolveMindSpaceStorageRoot } from '../mindspace-runtime-config.mjs'; const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); function loadEnvFile(filePath) { if (!fs.existsSync(filePath)) return; for (const line of fs.readFileSync(filePath, 'utf8').split('\n')) { const trimmed = line.trim(); if (!trimmed || trimmed.startsWith('#')) continue; const eq = trimmed.indexOf('='); if (eq < 0) continue; const key = trimmed.slice(0, eq).trim(); const value = trimmed.slice(eq + 1).trim(); if (!process.env[key]) process.env[key] = value; } } loadEnvFile(path.join(root, '.env')); loadEnvFile(path.join(root, '../../.env.local')); const JOHN_USER_ID = '1c99b83b-0454-474f-a5d2-129d34506a32'; const WORKSPACE_ROOT = path.join(root, 'MindSpace', JOHN_USER_ID); const ADMIN_PASSWORD = '66668888'; const pool = createDbPool(); const h5Root = root; const storageRoot = resolveMindSpaceStorageRoot(h5Root); const DATASET = { name: 'tkmind_exp_survey', columns: { insert: ['satisfaction', 'best_features', 'improvement'], read: ['id', 'satisfaction', 'best_features', 'improvement', 'created_at'], }, }; const pages = [ { relativePath: 'public/tkmind-experience-survey.html', accessMode: 'public', password: null, policy: { accessMode: 'public', datasets: { [DATASET.name]: { insert: true, read: false, columns: { insert: DATASET.columns.insert }, }, }, }, }, { relativePath: 'public/tkmind-survey-experience-admin.html', accessMode: 'password', password: ADMIN_PASSWORD, policy: { accessMode: 'password', datasets: { [DATASET.name]: { insert: false, read: true, columns: { read: DATASET.columns.read }, }, }, }, }, ]; for (const page of pages) { const result = await bindWorkspaceHtmlForPageData({ pool, h5Root, storageRoot, userId: JOHN_USER_ID, workspaceRoot: WORKSPACE_ROOT, relativePath: page.relativePath, accessMode: page.accessMode, password: page.password, pageDataPolicy: page.policy, }); console.log(`✓ ${page.relativePath}`); console.log(` pageId: ${result.pageId}`); console.log(` workspace: ${result.workspaceUrl}`); console.log(` publication: ${result.publicationUrl}`); console.log(` policy datasets: ${Object.keys(result.policy?.datasets ?? {}).join(', ')}\n`); } await pool.end();