Add server-generated /config.js; add error boundary
This commit is contained in:
		
							parent
							
								
									04ee6b8be2
								
							
						
					
					
						commit
						840cb5b182
					
				
					 14 changed files with 184 additions and 85 deletions
				
			
		| 
						 | 
				
			
			@ -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
									
								
							
							
						
						
									
										2
									
								
								web/src/app/config.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
const config = window.config;
 | 
			
		||||
export default config;
 | 
			
		||||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue