1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-09-11 06:11:04 +02:00

Add server-generated /config.js; add error boundary

This commit is contained in:
Philipp Heckel 2022-03-09 23:28:55 -05:00
parent 04ee6b8be2
commit 840cb5b182
14 changed files with 184 additions and 85 deletions

View file

@ -17,12 +17,11 @@ class SubscriptionManager {
return await db.subscriptions.get(subscriptionId)
}
async add(baseUrl, topic, ephemeral) {
async add(baseUrl, topic) {
const subscription = {
id: topicUrl(baseUrl, topic),
baseUrl: baseUrl,
topic: topic,
ephemeral: ephemeral,
mutedUntil: 0,
last: null
};

2
web/src/app/config.js Normal file
View file

@ -0,0 +1,2 @@
const config = window.config;
export default config;

View file

@ -6,6 +6,7 @@ import ding from "../sounds/ding.mp3";
import dadum from "../sounds/dadum.mp3";
import pop from "../sounds/pop.mp3";
import popSwoosh from "../sounds/pop-swoosh.mp3";
import config from "./config";
export const topicUrl = (baseUrl, topic) => `${baseUrl}/${topic}`;
export const topicUrlWs = (baseUrl, topic) => `${topicUrl(baseUrl, topic)}/ws`
@ -25,9 +26,16 @@ export const validUrl = (url) => {
}
export const validTopic = (topic) => {
if (disallowedTopic(topic)) {
return false;
}
return topic.match(/^([-_a-zA-Z0-9]{1,64})$/); // Regex must match Go & Android app!
}
export const disallowedTopic = (topic) => {
return config.disallowedTopics.includes(topic);
}
// Format emojis (see emoji.js)
const emojis = {};
rawEmojis.forEach(emoji => {
@ -122,13 +130,6 @@ export const openUrl = (url) => {
window.open(url, "_blank", "noopener,noreferrer");
};
export const subscriptionRoute = (subscription) => {
if (subscription.baseUrl !== window.location.origin) {
return `/${shortUrl(subscription.baseUrl)}/${subscription.topic}`;
}
return `/${subscription.topic}`;
}
export const sounds = {
"beep": beep,
"juntos": juntos,