feat(wechat): add news morning draft admin UI and API routes
Expose preview/push controls for daily-news WeChat draft publishing with inline HTML body mode in the Wechat admin page.
This commit is contained in:
@@ -108,6 +108,7 @@ export function createAdminApp(services) {
|
||||
skillRuntimeConfigService,
|
||||
billingConfigService,
|
||||
wechatScheduleLlmConfigService,
|
||||
wechatNewsMorningDraftService,
|
||||
wechatIntentRouterConfigService,
|
||||
wechatCursorExecutorPolicyService,
|
||||
adminSystemTestService,
|
||||
@@ -420,6 +421,68 @@ export function createAdminApp(services) {
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
adminApi.get('/wechat/news-morning-draft/config', requireAdmin, async (_req, res) => {
|
||||
if (!wechatNewsMorningDraftService) {
|
||||
return res.status(503).json({ message: '新闻早报草稿推送未启用' });
|
||||
}
|
||||
const [config, template] = await Promise.all([
|
||||
wechatNewsMorningDraftService.getConfig(),
|
||||
Promise.resolve(wechatNewsMorningDraftService.getTemplate()),
|
||||
]);
|
||||
return res.json({ config, template });
|
||||
});
|
||||
|
||||
adminApi.patch('/wechat/news-morning-draft/config', requireAdmin, async (req, res) => {
|
||||
if (!wechatNewsMorningDraftService) {
|
||||
return res.status(503).json({ message: '新闻早报草稿推送未启用' });
|
||||
}
|
||||
const config = await wechatNewsMorningDraftService.updateConfig(req.body ?? {}, {
|
||||
updatedBy: req.currentUser.id,
|
||||
});
|
||||
return res.json({ config });
|
||||
});
|
||||
|
||||
adminApi.get('/wechat/news-morning-draft/preview', requireAdmin, async (_req, res) => {
|
||||
if (!wechatNewsMorningDraftService) {
|
||||
return res.status(503).json({ message: '新闻早报草稿推送未启用' });
|
||||
}
|
||||
try {
|
||||
return res.json(await wechatNewsMorningDraftService.preview());
|
||||
} catch (error) {
|
||||
return res.status(400).json({
|
||||
message: error instanceof Error ? error.message : '预览失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
adminApi.post('/wechat/news-morning-draft/push', requireAdmin, async (req, res) => {
|
||||
if (!wechatNewsMorningDraftService) {
|
||||
return res.status(503).json({ message: '新闻早报草稿推送未启用' });
|
||||
}
|
||||
try {
|
||||
const result = await wechatNewsMorningDraftService.pushDraft({
|
||||
triggeredBy: req.currentUser.id,
|
||||
dryRun: req.body?.dryRun === true,
|
||||
});
|
||||
return res.json(result);
|
||||
} catch (error) {
|
||||
return res.status(400).json({
|
||||
message: error instanceof Error ? error.message : '推送失败',
|
||||
run: error?.run ?? null,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
adminApi.get('/wechat/news-morning-draft/runs', requireAdmin, async (req, res) => {
|
||||
if (!wechatNewsMorningDraftService) {
|
||||
return res.status(503).json({ message: '新闻早报草稿推送未启用' });
|
||||
}
|
||||
const runs = await wechatNewsMorningDraftService.listRuns({
|
||||
limit: req.query.limit,
|
||||
});
|
||||
return res.json({ runs });
|
||||
});
|
||||
|
||||
adminApi.get('/wechat/intent-router/config', requireAdmin, async (_req, res) => {
|
||||
if (!wechatIntentRouterConfigService?.getConfig) {
|
||||
return res.status(503).json({ message: '微信意图路由配置未启用' });
|
||||
|
||||
@@ -43,6 +43,7 @@ export async function bootstrapAdminServices() {
|
||||
const { createAssetGatewayConfigService } = await importMemind('asset-gateway.mjs');
|
||||
const { ensureAssetGatewaySchema } = await importMemind('db.mjs');
|
||||
const { createWechatScheduleLlmConfigService } = await importMemind('wechat-schedule-llm-config.mjs');
|
||||
const { createWechatNewsMorningDraftService } = await importMemind('wechat-news-morning-draft.mjs');
|
||||
const { createWechatIntentRouterConfigService } = await importMemind('wechat-intent-router-config.mjs');
|
||||
const { createWechatCursorExecutorAdminConfigService } = await importMemind(
|
||||
'wechat-cursor-executor-admin-config.mjs',
|
||||
@@ -138,6 +139,12 @@ export async function bootstrapAdminServices() {
|
||||
portalBaseUrl: `http://127.0.0.1:${process.env.H5_PORT ?? 8081}`,
|
||||
});
|
||||
const wechatMpConfig = loadWechatMpConfig();
|
||||
const wechatNewsMorningDraftService = createWechatNewsMorningDraftService(pool, {
|
||||
mpConfig: wechatMpConfig,
|
||||
h5Root,
|
||||
memindLibRoot: resolveMemindLib(),
|
||||
env: process.env,
|
||||
});
|
||||
const wechatMpService = createWechatMpService({
|
||||
config: wechatMpConfig,
|
||||
userAuth,
|
||||
@@ -204,6 +211,7 @@ export async function bootstrapAdminServices() {
|
||||
skillRuntimeConfigService,
|
||||
billingConfigService,
|
||||
wechatScheduleLlmConfigService,
|
||||
wechatNewsMorningDraftService,
|
||||
wechatIntentRouterConfigService,
|
||||
wechatCursorExecutorPolicyService,
|
||||
adminSystemTestService,
|
||||
|
||||
@@ -112,6 +112,7 @@ ready
|
||||
skillRuntimeConfigService,
|
||||
billingConfigService,
|
||||
wechatScheduleLlmConfigService,
|
||||
wechatNewsMorningDraftService,
|
||||
wechatIntentRouterConfigService,
|
||||
wechatCursorExecutorPolicyService,
|
||||
adminSystemTestService,
|
||||
@@ -144,6 +145,7 @@ ready
|
||||
skillRuntimeConfigService,
|
||||
billingConfigService,
|
||||
wechatScheduleLlmConfigService,
|
||||
wechatNewsMorningDraftService,
|
||||
wechatIntentRouterConfigService,
|
||||
wechatCursorExecutorPolicyService,
|
||||
adminSystemTestService,
|
||||
|
||||
Reference in New Issue
Block a user