1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-20 03:23:12 +02:00

Continued work on publishing from the web app

This commit is contained in:
Philipp Heckel 2022-03-27 09:10:47 -04:00
parent d5eff0cd34
commit 187c19f3b2
6 changed files with 182 additions and 52 deletions
web/src/app

View file

@ -26,23 +26,18 @@ class Api {
return messages;
}
async publish(baseUrl, topic, message, title, priority, tags) {
async publish(baseUrl, topic, message, options) {
const user = await userManager.get(baseUrl);
const url = topicUrl(baseUrl, topic);
console.log(`[Api] Publishing message to ${url}`);
console.log(`[Api] Publishing message to ${topicUrl(baseUrl, topic)}`);
const headers = {};
if (title) {
headers["X-Title"] = title;
}
if (priority !== 3) {
headers["X-Priority"] = `${priority}`;
}
if (tags.length > 0) {
headers["X-Tags"] = tags.join(",");
}
await fetch(url, {
const body = {
topic: topic,
message: message,
...options
};
await fetch(baseUrl, {
method: 'PUT',
body: message,
body: JSON.stringify(body),
headers: maybeWithBasicAuth(headers, user)
});
}