Spaces:
Running
Running
Fix: let renderTopicWallE run (renders Tường AI), only block duplicate Short AI"
Browse files- app_final.py +43 -18
app_final.py
CHANGED
|
@@ -1,35 +1,60 @@
|
|
| 1 |
-
"""
|
| 2 |
from app_patch_unified import *
|
| 3 |
-
from app_patch_unified import app, UNIFIED_INJECT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
"
|
| 8 |
-
"
|
| 9 |
)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
app.router.routes = [r for r in app.router.routes if not (getattr(r,'path',None)=='/' and 'GET' in getattr(r,'methods',set()))]
|
| 22 |
|
| 23 |
@app.get('/')
|
| 24 |
-
async def
|
| 25 |
-
from app_patch_unified import f5, f6, rt, PATCH_INJECT
|
| 26 |
html = f5.f4.f3.f2.f1._load_index_html()
|
| 27 |
body = ''
|
| 28 |
body += getattr(rt.old,'PATCH_INJECT','')
|
| 29 |
body += f5.f4.f3.f2.f1.FINAL_INJECT + f5.f4.f3.FINAL3_INJECT + f5.f4.FINAL4_INJECT + f5.FINAL5_INJECT
|
| 30 |
body += getattr(f6,'FINAL6_INJECT','')
|
| 31 |
body += getattr(f6,'FINAL6_FAST_HOME_INJECT','')
|
| 32 |
-
body += getattr(f6,'FINAL6E_INJECT','')
|
| 33 |
body += PATCH_INJECT
|
| 34 |
-
body +=
|
| 35 |
return HTMLResponse(html.replace('</body>', body + '\n</body>') if '</body>' in html else html + body)
|
|
|
|
| 1 |
+
"""Final wrapper: fix Tường AI + highlight fetch + interaction counts."""
|
| 2 |
from app_patch_unified import *
|
| 3 |
+
from app_patch_unified import app, UNIFIED_INJECT, f5, f6, rt, PATCH_INJECT
|
| 4 |
+
from fastapi.responses import HTMLResponse
|
| 5 |
+
|
| 6 |
+
# Fix UNIFIED_INJECT:
|
| 7 |
+
# 1. REMOVE Object.defineProperty for renderTopicWallE (it needs to run to render Tường AI)
|
| 8 |
+
# 2. Keep blocking renderAIShortHome (duplicate Short AI)
|
| 9 |
+
# 3. Fix highlight to fetch from API when data empty
|
| 10 |
+
# 4. Remove setInterval that kills slides
|
| 11 |
+
# 5. Add 16:9 toggle button
|
| 12 |
+
|
| 13 |
+
FIXED_INJECT = UNIFIED_INJECT
|
| 14 |
+
|
| 15 |
+
# Remove renderTopicWallE block (let it render Tường AI)
|
| 16 |
+
FIXED_INJECT = FIXED_INJECT.replace(
|
| 17 |
+
"Object.defineProperty(window,'renderTopicWallE',{get:function(){return function(){}},set:function(){},configurable:true});",
|
| 18 |
+
"// renderTopicWallE allowed to run (renders Tường AI)"
|
| 19 |
+
)
|
| 20 |
|
| 21 |
+
# Remove the setInterval that removes slides (it kills things it shouldn't)
|
| 22 |
+
FIXED_INJECT = FIXED_INJECT.replace(
|
| 23 |
+
"setInterval(function(){document.querySelectorAll('#ai-short-home,.ai-short-home,[id*=\"ai-shorts-patched\"]').forEach(function(el){if(el.id!=='short-ai-final-slide')el.remove();});},3000);",
|
| 24 |
+
"// No more aggressive DOM removal"
|
| 25 |
)
|
| 26 |
|
| 27 |
+
# Fix highlight: fetch from API if _hlLeagueData empty
|
| 28 |
+
FIXED_INJECT = FIXED_INJECT.replace(
|
| 29 |
+
"var articles=(window._hlLeagueData||{})[league]||[];\n if(!articles.length){el.innerHTML='<div class=\"loading\">Kh\xc3\xb4ng c\xc3\xb3 video</div>';return;}",
|
| 30 |
+
"var articles=(window._hlLeagueData||{})[league]||[];\n if(!articles.length){try{var _r=await fetch('/api/highlights/'+league);articles=await _r.json();if(!Array.isArray(articles))articles=[];}catch(e){articles=[];}}\n if(!articles.length){el.innerHTML='<div class=\"loading\">Kh\xc3\xb4ng c\xc3\xb3 video</div>';return;}"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# If above replace didn't match (encoding), try simpler approach
|
| 34 |
+
if "try{var _r=await fetch('/api/highlights/" not in FIXED_INJECT:
|
| 35 |
+
FIXED_INJECT = FIXED_INJECT.replace(
|
| 36 |
+
"if(!articles.length){el.innerHTML=",
|
| 37 |
+
"if(!articles.length){try{var _r=await fetch('/api/highlights/'+league);articles=await _r.json();if(!Array.isArray(articles))articles=[];}catch(e){articles=[];}}if(!articles.length){el.innerHTML="
|
| 38 |
)
|
| 39 |
|
| 40 |
+
# Add 16:9 toggle button to each highlight slide
|
| 41 |
+
FIXED_INJECT = FIXED_INJECT.replace(
|
| 42 |
+
"""<span class="tiktok-counter">'+(i+1)+'/'+ordered.length+'</span></div>';""",
|
| 43 |
+
"""<span class="tiktok-counter">'+(i+1)+'/'+ordered.length+'</span><button style="position:absolute;top:8px;right:8px;background:rgba(0,0,0,.6);border:1px solid #777;color:#fff;border-radius:12px;padding:3px 8px;font-size:9px;z-index:10" onclick="event.stopPropagation();var v=this.closest(\\'.tiktok-slide\\').querySelector(\\'video\\');if(v){v.style.objectFit=v.style.objectFit===\\'contain\\'?\\'cover\\':\\'contain\\';this.textContent=v.style.objectFit===\\'contain\\'?\\'1:1\\':\\'16:9\\';}">16:9</button></div>';"""
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Override root route
|
| 47 |
app.router.routes = [r for r in app.router.routes if not (getattr(r,'path',None)=='/' and 'GET' in getattr(r,'methods',set()))]
|
| 48 |
|
| 49 |
@app.get('/')
|
| 50 |
+
async def _index_v3():
|
|
|
|
| 51 |
html = f5.f4.f3.f2.f1._load_index_html()
|
| 52 |
body = ''
|
| 53 |
body += getattr(rt.old,'PATCH_INJECT','')
|
| 54 |
body += f5.f4.f3.f2.f1.FINAL_INJECT + f5.f4.f3.FINAL3_INJECT + f5.f4.FINAL4_INJECT + f5.FINAL5_INJECT
|
| 55 |
body += getattr(f6,'FINAL6_INJECT','')
|
| 56 |
body += getattr(f6,'FINAL6_FAST_HOME_INJECT','')
|
| 57 |
+
body += getattr(f6,'FINAL6E_INJECT','') # Renders Tường AI — now allowed to run
|
| 58 |
body += PATCH_INJECT
|
| 59 |
+
body += FIXED_INJECT
|
| 60 |
return HTMLResponse(html.replace('</body>', body + '\n</body>') if '</body>' in html else html + body)
|