fix(wechat): 早报必须搜当日新闻,禁止用旧稿充草稿
生成说明强制联网搜索当天内容,pushDraft 拒绝非当日页面;forceGenerateOnce 用于发版后重跑今日早报。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Set news_morning_draft.forceGenerateOnce so the 103 Portal worker
|
||||
* regenerates today's daily-news page on the next scan (~30s).
|
||||
* Dry-run by default; pass --apply to persist.
|
||||
*/
|
||||
import process from 'node:process';
|
||||
import mysql from 'mysql2/promise';
|
||||
import { loadH5Environment } from './load-env.mjs';
|
||||
|
||||
loadH5Environment(import.meta.dirname);
|
||||
|
||||
const CONFIG_KEY = 'news_morning_draft';
|
||||
const CONFIG_TABLE = 'h5_wechat_admin_config';
|
||||
|
||||
async function main() {
|
||||
const apply = process.argv.includes('--apply');
|
||||
if (!process.env.DATABASE_URL) {
|
||||
console.error('DATABASE_URL missing');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const pool = mysql.createPool({ uri: process.env.DATABASE_URL, connectionLimit: 2 });
|
||||
const [rows] = await pool.query(
|
||||
`SELECT config_json FROM ${CONFIG_TABLE} WHERE config_key = ? LIMIT 1`,
|
||||
[CONFIG_KEY],
|
||||
);
|
||||
const current = rows[0]?.config_json
|
||||
? (typeof rows[0].config_json === 'string'
|
||||
? JSON.parse(rows[0].config_json)
|
||||
: rows[0].config_json)
|
||||
: {};
|
||||
const next = { ...current, forceGenerateOnce: true, enabled: current.enabled !== false };
|
||||
|
||||
console.log(JSON.stringify({
|
||||
apply,
|
||||
currentForceGenerateOnce: Boolean(current.forceGenerateOnce),
|
||||
sourceUserId: current.sourceUserId ?? null,
|
||||
enabled: next.enabled,
|
||||
}, null, 2));
|
||||
|
||||
if (apply) {
|
||||
const now = Date.now();
|
||||
await pool.query(
|
||||
`INSERT INTO ${CONFIG_TABLE} (config_key, config_json, updated_by, updated_at)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
config_json = VALUES(config_json),
|
||||
updated_by = VALUES(updated_by),
|
||||
updated_at = VALUES(updated_at)`,
|
||||
[CONFIG_KEY, JSON.stringify(next), 'manual-force-generate', now],
|
||||
);
|
||||
console.log('forceGenerateOnce=true persisted');
|
||||
}
|
||||
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user