bb6aa75b3b
Memind CI / Test, build, and release guards (push) Successful in 4m14s
Co-authored-by: Cursor <cursoragent@cursor.com>
27 lines
807 B
JavaScript
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;
|
|
}
|