Spaces:
Sleeping
Sleeping
File size: 2,140 Bytes
87b646c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import sys
import subprocess
import re
def fix_html():
with open('dashboard.html', 'r', encoding='utf-8') as f:
content = f.read()
js_snippet = """
const browseBtn = document.getElementById('browseBtn');
browseBtn.addEventListener('click', (e) => {
e.preventDefault();
fileInput.click();
});
fileInput.addEventListener('change', () => {
if (fileInput.files.length > 0) {
// Provide a visual cue that a file was selected
const fileName = fileInput.files[0].name;
browseBtn.innerHTML = `<span class="material-symbols-outlined text-xl">check_circle</span> ${fileName}`;
}
});
"""
if "browseBtn.addEventListener('click', (e) => {" in content and "Provide a visual cue that a file was selected" in content:
print("Snippet already exists. Skipping injection.")
else:
# Find where the DOM elements are defined
target = "const downloadBtn = document.getElementById('downloadBtn');"
if target in content:
new_content = content.replace(target, target + "\n" + js_snippet)
with open('dashboard.html', 'w', encoding='utf-8') as f:
f.write(new_content)
print("Injected JS successfully.")
else:
print("Could not find insertion point!")
return False
# Run git commands
subprocess.run(['git', 'add', 'dashboard.html'], check=True)
try:
subprocess.run(['git', 'commit', '-m', 'Bugfix: Wire up Browse Files button to hidden input'], check=True)
except subprocess.CalledProcessError:
print("Nothing to commit")
subprocess.run(['git', 'push', '--force', 'space', 'HEAD:main'], check=True)
# Push to origin main as well
try:
subprocess.run(['git', 'push', 'origin', 'HEAD:main'], check=True)
except subprocess.CalledProcessError:
print("Push to origin failed or not needed")
print("Deployment triggered successfully.")
return True
if __name__ == '__main__':
fix_html()
|