From 71760cbb1fa1899e215dbba8bb619abeedd5d294 Mon Sep 17 00:00:00 2001 From: feie9456 Date: Fri, 17 Apr 2026 14:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dios=20topic=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/push.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/push.ts b/lib/push.ts index e92331f..ade108b 100644 --- a/lib/push.ts +++ b/lib/push.ts @@ -153,6 +153,10 @@ function getEndpointHost(endpoint: string) { } } +function shouldOmitTopic(endpoint: string) { + return getEndpointHost(endpoint) === "web.push.apple.com"; +} + function getPushFailureDetail(subscription: StoredPushSubscription, error: unknown) { const statusCode = error && typeof error === "object" && "statusCode" in error @@ -190,7 +194,7 @@ function getPushFailureDetail(subscription: StoredPushSubscription, error: unkno async function deliverPushToSubscriptions(input: { subscriptions: StoredPushSubscription[]; payload: string; - topic: string; + topic?: string; collectFailureDetails?: boolean; }) { if (input.subscriptions.length === 0) { @@ -210,6 +214,19 @@ async function deliverPushToSubscriptions(input: { const results = await Promise.all( input.subscriptions.map(async (subscription) => { try { + const requestOptions: { + TTL: number; + urgency: "high"; + topic?: string; + } = { + TTL: 60 * 30, + urgency: "high", + }; + + if (input.topic && !shouldOmitTopic(subscription.endpoint)) { + requestOptions.topic = input.topic; + } + await webpush.sendNotification( { endpoint: subscription.endpoint, @@ -220,11 +237,7 @@ async function deliverPushToSubscriptions(input: { }, }, input.payload, - { - TTL: 60 * 30, - urgency: "high", - topic: input.topic, - }, + requestOptions, ); return "sent" as const;