Files
memind/wechat/push-subscription-secret-codes.mjs
T
john bb6aa75b3b
Memind CI / Test, build, and release guards (push) Successful in 4m14s
feat(wechat): add secret codes for morning subscribe and news push
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-20 19:10:27 +08:00

27 lines
807 B
JavaScript

/** 微信服务号订阅暗号(精确匹配,忽略首尾与中间空白)。 */
export const PUSH_SUBSCRIPTION_SECRET_CODES = Object.freeze({
morningSubscribe: '美丽心情',
newsImmediate: '新闻早报',
});
function normalizeSecretCodeText(text) {
return String(text ?? '').trim().replace(/\s+/g, '');
}
/**
* 解析订阅暗号。
* @returns {{ kind: 'morning_subscribe' }|{ kind: 'news_immediate' }|null}
*/
export function parsePushSubscriptionSecretCode(text) {
const compact = normalizeSecretCodeText(text);
if (!compact) return null;
if (compact === PUSH_SUBSCRIPTION_SECRET_CODES.morningSubscribe) {
return { kind: 'morning_subscribe' };
}
if (compact === PUSH_SUBSCRIPTION_SECRET_CODES.newsImmediate) {
return { kind: 'news_immediate' };
}
return null;
}