fix: replace em dash in ntfy title headers with ASCII dash
HTTP headers only accept bytes 0-255; the em dash (U+2014) caused 'Cannot convert argument to ByteString' errors. Replace non-ASCII chars in the title header and use plain hyphens in title strings.
This commit is contained in:
1 file changed
+5
-3
@@ -59,11 +59,13 @@ function fmtDate(iso) {
|
|||||||
async function sendNtfy(topic, title, message, tags = []) {
|
async function sendNtfy(topic, title, message, tags = []) {
|
||||||
if (!topic) return;
|
if (!topic) return;
|
||||||
const url = topic.startsWith('http') ? topic : `https://ntfy.sh/${topic}`;
|
const url = topic.startsWith('http') ? topic : `https://ntfy.sh/${topic}`;
|
||||||
|
// HTTP headers must be ASCII-only; replace non-ASCII characters
|
||||||
|
const safeTitle = title.replace(/[^\x00-\x7F]/g, '-');
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Title': title,
|
'Title': safeTitle,
|
||||||
'Content-Type': 'text/plain',
|
'Content-Type': 'text/plain',
|
||||||
...(tags.length ? { 'Tags': tags.join(',') } : {}),
|
...(tags.length ? { 'Tags': tags.join(',') } : {}),
|
||||||
},
|
},
|
||||||
@@ -87,7 +89,7 @@ async function sendDailyDigest() {
|
|||||||
});
|
});
|
||||||
await sendNtfy(
|
await sendNtfy(
|
||||||
settings.ntfyTopic,
|
settings.ntfyTopic,
|
||||||
`Prayer Journal — ${prayers.length} active prayer${prayers.length !== 1 ? 's' : ''}`,
|
`Prayer Journal -${prayers.length} active prayer${prayers.length !== 1 ? 's' : ''}`,
|
||||||
lines.join('\n'),
|
lines.join('\n'),
|
||||||
['pray', 'raised_hands']
|
['pray', 'raised_hands']
|
||||||
);
|
);
|
||||||
@@ -226,7 +228,7 @@ app.put('/api/settings', (req, res) => {
|
|||||||
app.post('/api/notifications/test', async (req, res) => {
|
app.post('/api/notifications/test', async (req, res) => {
|
||||||
const settings = readSettings();
|
const settings = readSettings();
|
||||||
if (!settings.ntfyTopic) return res.status(400).json({ error: 'No ntfy topic configured.' });
|
if (!settings.ntfyTopic) return res.status(400).json({ error: 'No ntfy topic configured.' });
|
||||||
await sendNtfy(settings.ntfyTopic, 'Prayer Journal — Test', 'Notifications are working! 🙏', ['white_check_mark']);
|
await sendNtfy(settings.ntfyTopic, 'Prayer Journal -Test', 'Notifications are working! 🙏', ['white_check_mark']);
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user