mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
use seconds instead of ms for claims payload
This commit is contained in:
@@ -54,17 +54,17 @@ export class NotificationService {
|
|||||||
"kid": keyId,
|
"kid": keyId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const now = Date.now();
|
const nowMs = Date.now();
|
||||||
const claimsPayload = {
|
const claimsPayload = {
|
||||||
"iss": teamId,
|
"iss": teamId,
|
||||||
"iat": now,
|
"iat": Math.ceil(nowMs / 1000), // APNs requires number of seconds since Epoch
|
||||||
};
|
};
|
||||||
|
|
||||||
this.apnsToken = jwt.sign(claimsPayload, privateKey, {
|
this.apnsToken = jwt.sign(claimsPayload, privateKey, {
|
||||||
algorithm: "ES256",
|
algorithm: "ES256",
|
||||||
header: tokenHeader
|
header: tokenHeader
|
||||||
});
|
});
|
||||||
this._lastRefreshedTimeMs = now;
|
this._lastRefreshedTimeMs = nowMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private lastReloadedTimeForAPNsIsTooRecent() {
|
private lastReloadedTimeForAPNsIsTooRecent() {
|
||||||
@@ -109,25 +109,30 @@ export class NotificationService {
|
|||||||
"apns-priority": "10",
|
"apns-priority": "10",
|
||||||
"apns-topic": bundleId,
|
"apns-topic": bundleId,
|
||||||
};
|
};
|
||||||
const response = await fetch(url, {
|
try {
|
||||||
method: "POST",
|
const response = await fetch(url, {
|
||||||
headers,
|
method: "POST",
|
||||||
body: JSON.stringify({
|
headers,
|
||||||
aps: {
|
body: JSON.stringify({
|
||||||
alert: {
|
aps: {
|
||||||
title: "Shuttle is arriving",
|
alert: {
|
||||||
body: `Shuttle is approaching ${stop.name} in ${Math.ceil(eta.secondsRemaining / 60)} minutes.`
|
title: "Shuttle is arriving",
|
||||||
|
body: `Shuttle is approaching ${stop.name} in ${Math.ceil(eta.secondsRemaining / 60)} minutes.`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}),
|
||||||
}),
|
});
|
||||||
});
|
const json = await response.json();
|
||||||
const json = await response.json();
|
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
console.error(`Notification failed for device ${deviceId}:`, json.reason);
|
console.error(`Notification failed for device ${deviceId}:`, json.reason);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getAPNsFullUrlToUse(deviceId: string) {
|
public static getAPNsFullUrlToUse(deviceId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user