V.AISTUDIO / fix_script.py
bep40's picture
Add fix script to restore index.html
196bb57 verified
Raw History Blame
1.63 kB
#!/usr/bin/env python3
"""Script to restore index.html from original commit and bump version."""
import urllib.request, json, os, re
token = os.environ.get('HF_TOKEN', '')
# Download original index.html from the target commit
url = 'https://huggingface.co/spaces/bep40/V.AISTUDIO/raw/30b624b1a3bd60a5dc42ae1eaff9860ca89e5715/index.html'
req = urllib.request.Request(url, headers={'Authorization': f'Bearer {token}'})
with urllib.request.urlopen(req, timeout=120) as f:
content = f.read().decode('utf-8')
print(f'Downloaded: {len(content)} bytes')
print(f'Has </html>: {"</html>" in content}')
print(f'Has order-store.js: {"order-store.js" in content}')
# Bump version v=19 -> v=20 for cache busting
new_content = content.replace('v=19', 'v=20')
v19 = content.count('v=19')
v20 = new_content.count('v=20')
print(f'Version changes: {v19} -> {v20}')
# Upload back via ndjson commit API
commit_url = 'https://huggingface.co/api/spaces/bep40/V.AISTUDIO/commit/main'
lines = []
lines.append(json.dumps({'key': 'header', 'value': {'summary': 'Restore index.html from commit 30b624b + bump v=19->v=20 for cache bust'}}))
lines.append(json.dumps({'key': 'file', 'value': {'path': 'index.html', 'content': new_content}}))
ndjson_body = '\n'.join(lines) + '\n'
req2 = urllib.request.Request(commit_url, data=ndjson_body.encode('utf-8'), method='POST')
req2.add_header('Authorization', f'Bearer {token}')
req2.add_header('Content-Type', 'application/x-ndjson')
with urllib.request.urlopen(req2, timeout=120) as f:
result = json.loads(f.read().decode())
print(f'Commit: {result.get("commitUrl", result)}')
print('SUCCESS')