修复ios topic报错
This commit is contained in:
parent
3134aab4dc
commit
71760cbb1f
25
lib/push.ts
25
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user