import re with open("static/js/bottom-bar.js", "r") as f: text = f.read() # Replace the static select with a dynamic fetch container events_html = """ const replyBox = document.createElement('div'); replyBox.className = 'mt-2 border-top pt-2 border-primary-subtle'; replyBox.innerHTML = `
`; chatContainer.appendChild(ul); chatContainer.appendChild(replyBox); innerContent.appendChild(chatContainer); // Fetch users dynamically fetch('/api/v1/users?is_active=true', { credentials: 'include' }) .then(r => r.json()) .then(users => { const sel = document.getElementById('chatRecipient'); if (sel) { sel.innerHTML = ''; users.forEach(u => { sel.innerHTML += ``; }); } }) .catch(e => console.error("Error fetching users for chat:", e)); } else { innerContent.appendChild(ul); } """ # Find the block we inserted earlier and replace it pattern = r" const replyBox = document\.createElement\('div'\);\n replyBox\.className = 'mt-2 border-top pt-2 border-primary-subtle';\n replyBox\.innerHTML = `[\s\S]*?innerContent\.appendChild\(chatContainer\);\n \} else \{\n innerContent\.appendChild\(ul\);\n \}" # print(re.search(pattern, text)) text = re.sub(pattern, events_html, text) # Then bump the cache version with open("static/js/bottom-bar.js", "w") as f: f.write(text) with open("app/shared/frontend/base.html", "r") as f: bt = f.read() bt = re.sub(r'bottom-bar\.js\?v=\d+\.\d+', 'bottom-bar.js?v=2.00', bt) with open("app/shared/frontend/base.html", "w") as f2: f2.write(bt)