1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-18 18:43:15 +02:00

Poll on page refresh; validate subscribe dialog properly; avoid save-races

This commit is contained in:
Philipp Heckel 2022-02-26 11:45:39 -05:00
parent aa79fe2861
commit e422c2c479
10 changed files with 96 additions and 37 deletions
web/src/app

View file

@ -1,12 +1,24 @@
import {topicUrlJsonPoll, fetchLinesIterator, topicUrl, topicUrlAuth, maybeWithBasicAuth} from "./utils";
import {
topicUrlJsonPoll,
fetchLinesIterator,
topicUrl,
topicUrlAuth,
maybeWithBasicAuth,
topicShortUrl,
topicUrlJsonPollWithSince
} from "./utils";
class Api {
async poll(baseUrl, topic, user) {
const url = topicUrlJsonPoll(baseUrl, topic);
async poll(baseUrl, topic, since, user) {
const shortUrl = topicShortUrl(baseUrl, topic);
const url = (since > 1) // FIXME Ahh, this is >1, because we do +1 when we call this .....
? topicUrlJsonPollWithSince(baseUrl, topic, since)
: topicUrlJsonPoll(baseUrl, topic);
const messages = [];
const headers = maybeWithBasicAuth({}, user);
console.log(`[Api] Polling ${url}`);
for await (let line of fetchLinesIterator(url, headers)) {
console.log(`[Api, ${shortUrl}] Received message ${line}`);
messages.push(JSON.parse(line));
}
return messages;