change topic safe in message-delivery-method-web-push
Deploy service message-delivery-method-web-push / service message-delivery-method-web-push (push) Successful in 59s

This commit is contained in:
2024-12-06 08:02:28 +02:00
parent bb94c8fc9a
commit 113012ddc3
@@ -1,4 +1,5 @@
import webpush, { WebPushError } from "web-push";
import { createHash } from "crypto";
const heartbeat = Number(process.env.HEARTBEAT_INTERVAL ?? 30_000);
@@ -21,6 +22,11 @@ function limitStringLengthWithEllipsis(str: string, maxLength: number): string {
return str.length > maxLength ? str.substring(0, maxLength) + "…" : str;
}
function getTopicSafe(str: string) {
const hash = createHash("sha256").update(str).digest("base64");
return Buffer.from(hash, "hex").toString("base64").replace(/=+$/, "");
}
const start = async () => {
const checkedDatabases = await checkDatabases();
await setupVapidDetails();
@@ -78,9 +84,10 @@ const start = async () => {
const qrDoc = await qrDb.get(`qr_code:${msgDoc.qr_code_uri}`);
const timestamp = new Date(msgDoc.created_at).getTime();
const topic = `cht_${msgDoc.qr_code_uri}_${msgDoc.chat}`;
const topicUnsafe = `cht_${msgDoc.qr_code_uri}_${msgDoc.chat}`;
const topic = getTopicSafe(topicUnsafe);
const tag = `${topic}_${(timestamp - new Date(qrDoc.created_at).getTime()).toString(36)}`;
const tag = `${topicUnsafe}_${(timestamp - new Date(qrDoc.created_at).getTime()).toString(36)}`;
if (msgDoc.from === "guest") {
console.log("FROM GUEST");