mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
pushover request fixes
Implemented truncation on data elements to comply with pushover restrictions. Added a timeout for a request to the pushover api endpoint
This commit is contained in:
@@ -12,13 +12,16 @@ export async function sendPushover(
|
|||||||
const {pushoverUserKey, pushoverApiToken, pushoverDevice} = config;
|
const {pushoverUserKey, pushoverApiToken, pushoverDevice} = config;
|
||||||
const priority = parseInt(config.pushoverPriority ?? "0", 10);
|
const priority = parseInt(config.pushoverPriority ?? "0", 10);
|
||||||
|
|
||||||
|
const rawTitle = `[${payload.level.toUpperCase()}] ${payload.title}`;
|
||||||
|
const rawMessage = payload.data
|
||||||
|
? `${payload.message}\n\nData:\n${JSON.stringify(payload.data)}`
|
||||||
|
: payload.message;
|
||||||
|
|
||||||
const body: Record<string, string | number> = {
|
const body: Record<string, string | number> = {
|
||||||
token: pushoverApiToken,
|
token: pushoverApiToken,
|
||||||
user: pushoverUserKey,
|
user: pushoverUserKey,
|
||||||
title: `[${payload.level.toUpperCase()}] ${payload.title}`,
|
title: rawTitle.length > 250 ? rawTitle.slice(0, 249) + "…" : rawTitle,
|
||||||
message: payload.data
|
message: rawMessage.length > 1024 ? rawMessage.slice(0, 1023) + "…" : rawMessage,
|
||||||
? `${payload.message}\n\nData:\n${JSON.stringify(payload.data, null, 2)}`
|
|
||||||
: payload.message,
|
|
||||||
priority,
|
priority,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,6 +39,7 @@ export async function sendPushover(
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
signal: AbortSignal.timeout(10_000),
|
||||||
});
|
});
|
||||||
|
|
||||||
const json = await res.json().catch(() => null);
|
const json = await res.json().catch(() => null);
|
||||||
|
|||||||
Reference in New Issue
Block a user