bep40 commited on
Commit
e26bab9
·
verified ·
1 Parent(s): 3ae926a

Fix: let renderTopicWallE run (renders Tường AI), only block duplicate Short AI"

Browse files
Files changed (1) hide show
  1. app_final.py +43 -18
app_final.py CHANGED
@@ -1,35 +1,60 @@
1
- """Wrapper that patches openLeaguePlayer to fetch league data from API when empty."""
2
  from app_patch_unified import *
3
- from app_patch_unified import app, UNIFIED_INJECT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- # Patch UNIFIED_INJECT to fix highlight "no video" issue
6
- UNIFIED_INJECT_FIXED = UNIFIED_INJECT.replace(
7
- "var articles=(window._hlLeagueData||{})[league]||[];\n if(!articles.length){el.innerHTML='<div class=\"loading\">Không có video</div>';return;}",
8
- "var articles=(window._hlLeagueData||{})[league]||[];\n if(!articles.length){try{var resp=await fetch('/api/highlights/'+league);articles=await resp.json();if(!Array.isArray(articles))articles=[];}catch(e){articles=[];}}\n if(!articles.length){el.innerHTML='<div class=\"loading\">Không video</div>';return;}"
9
  )
10
 
11
- # If replace didn't work (string mismatch), use a different approach
12
- if UNIFIED_INJECT_FIXED == UNIFIED_INJECT:
13
- # Fallback: just replace the check
14
- UNIFIED_INJECT_FIXED = UNIFIED_INJECT.replace(
15
- "if(!articles.length){el.innerHTML='<div class=\"loading\">Kh",
16
- "if(!articles.length){try{var resp=await fetch('/api/highlights/'+league);articles=await resp.json();if(!Array.isArray(articles))articles=[];}catch(e){articles=[];}}if(!articles.length){el.innerHTML='<div class=\"loading\">Kh"
 
 
 
 
 
17
  )
18
 
19
- from fastapi.responses import HTMLResponse
20
- # Override root route with fixed inject
 
 
 
 
 
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 _index_fixed():
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 += UNIFIED_INJECT_FIXED
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)