fix(wechat): sync MindSpace pages after MP generation and redirect on 401
Memind CI / Test, build, and release guards (push) Failing after 3m31s
Memind CI / Test, build, and release guards (push) Failing after 3m31s
WeChat page delivery now triggers syncUserGeneratedPages so write_file HTML gets page records; public share widget redirects unauthenticated owners to WeChat OAuth instead of only showing an error. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Repair icyxu (清风徐徐女士) WeChat pages missing MindSpace records/publications.
|
||||
*
|
||||
* Usage:
|
||||
* node scripts/repair-icyxu-wechat-pages-103.mjs [--apply]
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createDbPool } from '../db.mjs';
|
||||
import { createAssetService } from '../mindspace-assets.mjs';
|
||||
import { createPageService } from '../mindspace-pages.mjs';
|
||||
import { createPageSyncService } from '../mindspace-page-sync-service.mjs';
|
||||
import { createPublicationService } from '../mindspace-publications.mjs';
|
||||
import { createWorkspacePageDeliverService } from '../mindspace-workspace-page-deliver.mjs';
|
||||
import { resolveMindSpaceStorageRoot } from '../mindspace-runtime-config.mjs';
|
||||
|
||||
const repoRoot = 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(repoRoot, '.env'));
|
||||
loadEnvFile(path.join(repoRoot, '.env.local'));
|
||||
loadEnvFile(path.join(repoRoot, '../../.env.local'));
|
||||
|
||||
const USER_ID = '7a650359-5f2e-4911-85ad-cbc74c0cdb22';
|
||||
const TARGET_PATHS = ['public/poem.html', 'public/mountain-trip.html'];
|
||||
|
||||
const apply = process.argv.includes('--apply');
|
||||
const h5Root = process.env.H5_ROOT || repoRoot;
|
||||
const storageRoot = resolveMindSpaceStorageRoot(h5Root, process.env);
|
||||
|
||||
async function main() {
|
||||
const pool = createDbPool();
|
||||
const pageService = createPageService(pool, { h5Root, storageRoot });
|
||||
const assetService = createAssetService(pool, { h5Root, storageRoot });
|
||||
const pageSyncService = createPageSyncService({
|
||||
pool,
|
||||
pageService,
|
||||
assetService,
|
||||
h5Root,
|
||||
syncWorkspaceAssets: assetService.syncWorkspaceAssets?.bind(assetService),
|
||||
});
|
||||
const publicationService = createPublicationService(pool, { h5Root, storageRoot });
|
||||
const workspacePageDeliveryService = createWorkspacePageDeliverService({
|
||||
pool,
|
||||
pageService,
|
||||
publicationService,
|
||||
pageSyncService,
|
||||
h5Root,
|
||||
storageRoot,
|
||||
findPageByRelativePath: pageService.findPageByRelativePath.bind(pageService),
|
||||
});
|
||||
|
||||
const actions = [];
|
||||
for (const relativePath of TARGET_PATHS) {
|
||||
const absPath = path.join(h5Root, 'MindSpace', USER_ID, relativePath);
|
||||
actions.push({
|
||||
relativePath,
|
||||
exists: fs.existsSync(absPath),
|
||||
size: fs.existsSync(absPath) ? fs.statSync(absPath).size : 0,
|
||||
});
|
||||
}
|
||||
|
||||
console.log(JSON.stringify({ userId: USER_ID, dryRun: !apply, targets: actions }, null, 2));
|
||||
|
||||
if (!apply) {
|
||||
console.log('\nDry run only. Re-run with --apply to sync and publish.');
|
||||
await pool.end();
|
||||
return;
|
||||
}
|
||||
|
||||
const syncResult = await pageSyncService.syncUserGeneratedPages(USER_ID, {
|
||||
onlyRelativePaths: TARGET_PATHS,
|
||||
});
|
||||
console.log('sync:', JSON.stringify(syncResult));
|
||||
|
||||
const publishResult = await workspacePageDeliveryService.ensureWorkspaceHtmlPublications(
|
||||
USER_ID,
|
||||
{ onlyRelativePaths: TARGET_PATHS },
|
||||
);
|
||||
console.log('publish:', JSON.stringify(publishResult));
|
||||
|
||||
for (const relativePath of TARGET_PATHS) {
|
||||
const page = await pageService.findPageByRelativePath(USER_ID, relativePath);
|
||||
const publication = page?.id
|
||||
? await publicationService.getCurrent(USER_ID, page.id)
|
||||
: null;
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
relativePath,
|
||||
pageId: page?.id ?? null,
|
||||
pageStatus: page?.status ?? null,
|
||||
publicationId: publication?.id ?? null,
|
||||
publicationStatus: publication?.status ?? null,
|
||||
publicUrl: publication?.publicUrl ?? publication?.public_url ?? null,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error instanceof Error ? error.stack ?? error.message : error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user