102 lines
3.0 KiB
JavaScript
102 lines
3.0 KiB
JavaScript
/**
|
|
* 修复 john 教育问卷:问卷页 public + 独立后台页 password。
|
|
* 用法:node scripts/repair-child-education-survey.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 DATASET = 'child_edu_survey';
|
|
|
|
const pool = createDbPool();
|
|
const h5Root = root;
|
|
const storageRoot = resolveMindSpaceStorageRoot(h5Root);
|
|
|
|
const pages = [
|
|
{
|
|
relativePath: 'public/child-education-analysis.html',
|
|
accessMode: 'public',
|
|
password: null,
|
|
policy: {
|
|
accessMode: 'public',
|
|
datasets: {
|
|
[DATASET]: {
|
|
insert: true,
|
|
read: false,
|
|
columns: { insert: ['q1_pressure', 'q2_concern', 'q3_action'] },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
relativePath: 'public/child-education-analysis-admin.html',
|
|
accessMode: 'password',
|
|
password: ADMIN_PASSWORD,
|
|
policy: {
|
|
accessMode: 'password',
|
|
datasets: {
|
|
[DATASET]: {
|
|
insert: false,
|
|
read: true,
|
|
columns: {
|
|
read: ['id', 'q1_pressure', 'q2_concern', 'q3_action', 'created_at'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
];
|
|
|
|
console.log('修复教育问卷发布配置…\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(` accessMode: ${result.publicationAccessMode}`);
|
|
console.log(` workspace: ${result.workspaceUrl}\n`);
|
|
}
|
|
|
|
console.log('完成。测试入口:');
|
|
console.log(` 问卷:http://127.0.0.1:8081/MindSpace/${JOHN_USER_ID}/public/child-education-analysis.html`);
|
|
console.log(` 后台:http://127.0.0.1:8081/MindSpace/${JOHN_USER_ID}/public/child-education-analysis-admin.html`);
|
|
console.log(` 后台口令:${ADMIN_PASSWORD}`);
|
|
|
|
await pool.end();
|