Add page data delivery and publication guards
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* 绑定并发布 john 的 TKMind 问卷页面(Page Data API 演示)。
|
||||
* 用法:node scripts/setup-page-data-survey-demo.mjs
|
||||
*/
|
||||
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 = '88888888';
|
||||
|
||||
const SURVEY_FORM_POLICY = {
|
||||
accessMode: 'public',
|
||||
datasets: {
|
||||
survey_responses: {
|
||||
insert: true,
|
||||
read: false,
|
||||
columns: {
|
||||
insert: ['q1_feature', 'q2_usage', 'q3_suggestion'],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const SURVEY_ADMIN_POLICY = {
|
||||
accessMode: 'password',
|
||||
datasets: {
|
||||
survey_responses: {
|
||||
insert: false,
|
||||
read: true,
|
||||
columns: {
|
||||
read: ['id', 'q1_feature', 'q2_usage', 'q3_suggestion', 'created_at'],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const pool = createDbPool();
|
||||
const h5Root = root;
|
||||
const storageRoot = resolveMindSpaceStorageRoot(h5Root);
|
||||
|
||||
const pages = [
|
||||
{
|
||||
relativePath: 'public/tkmind-survey.html',
|
||||
accessMode: 'public',
|
||||
password: null,
|
||||
policy: SURVEY_FORM_POLICY,
|
||||
},
|
||||
{
|
||||
relativePath: 'public/tkmind-survey-admin.html',
|
||||
accessMode: 'password',
|
||||
password: ADMIN_PASSWORD,
|
||||
policy: SURVEY_ADMIN_POLICY,
|
||||
},
|
||||
];
|
||||
|
||||
console.log('绑定并发布 Page Data 问卷演示页…\n');
|
||||
|
||||
const results = [];
|
||||
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,
|
||||
});
|
||||
results.push(result);
|
||||
console.log(`✓ ${page.relativePath}`);
|
||||
console.log(` pageId: ${result.pageId}`);
|
||||
console.log(` workspace: ${result.workspaceUrl}`);
|
||||
console.log(` publication: ${result.publicationUrl}\n`);
|
||||
}
|
||||
|
||||
console.log('完成。测试入口:');
|
||||
console.log(` 问卷:${results[0].workspaceUrl}`);
|
||||
console.log(` 后台:${results[1].workspaceUrl}`);
|
||||
console.log(` 后台密码:${ADMIN_PASSWORD}`);
|
||||
|
||||
await pool.end();
|
||||
Reference in New Issue
Block a user