修复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) {
|
function getPushFailureDetail(subscription: StoredPushSubscription, error: unknown) {
|
||||||
const statusCode =
|
const statusCode =
|
||||||
error && typeof error === "object" && "statusCode" in error
|
error && typeof error === "object" && "statusCode" in error
|
||||||
@ -190,7 +194,7 @@ function getPushFailureDetail(subscription: StoredPushSubscription, error: unkno
|
|||||||
async function deliverPushToSubscriptions(input: {
|
async function deliverPushToSubscriptions(input: {
|
||||||
subscriptions: StoredPushSubscription[];
|
subscriptions: StoredPushSubscription[];
|
||||||
payload: string;
|
payload: string;
|
||||||
topic: string;
|
topic?: string;
|
||||||
collectFailureDetails?: boolean;
|
collectFailureDetails?: boolean;
|
||||||
}) {
|
}) {
|
||||||
if (input.subscriptions.length === 0) {
|
if (input.subscriptions.length === 0) {
|
||||||
@ -210,6 +214,19 @@ async function deliverPushToSubscriptions(input: {
|
|||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
input.subscriptions.map(async (subscription) => {
|
input.subscriptions.map(async (subscription) => {
|
||||||
try {
|
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(
|
await webpush.sendNotification(
|
||||||
{
|
{
|
||||||
endpoint: subscription.endpoint,
|
endpoint: subscription.endpoint,
|
||||||
@ -220,11 +237,7 @@ async function deliverPushToSubscriptions(input: {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
input.payload,
|
input.payload,
|
||||||
{
|
requestOptions,
|
||||||
TTL: 60 * 30,
|
|
||||||
urgency: "high",
|
|
||||||
topic: input.topic,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return "sent" as const;
|
return "sent" as const;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user