bep40 commited on
Commit
5d09ad3
·
verified ·
1 Parent(s): f6736e5

v6.7: Add cache to api_livescore_date + Cache-Control headers (30s) for all livescore endpoints

Browse files
Files changed (1) hide show
  1. main.py +10 -1
main.py CHANGED
@@ -289,7 +289,7 @@ def api_livescore_results():
289
  def api_livescore_standings(league:str):
290
  tid=LEAGUE_IDS.get(league,27110);return JSONResponse({"html":_cached(f"ls_bxh_{league}",lambda:fetch_bongda_api(f"/api/league-table/home?tournament_id={tid}&is_detail=True"),ttl=_cache_ttl)})
291
  @app.get("/api/livescore/date/{date}")
292
- def api_livescore_date(date:str):return JSONResponse({"html":fetch_bongda_api(f"/api/fixtures/get-by-date?date={date}")})
293
  @app.get("/api/match/{event_id}/commentaries")
294
  def api_match_commentaries(event_id:int):return JSONResponse({"html":fetch_bongda_api(f"/api/fixtures/commentaries?event_id={event_id}")})
295
  @app.get("/api/match/{event_id}/stats")
@@ -433,6 +433,15 @@ async def api_short_action(request:Request):
433
  # ===== MyTV.com.vn Video Scraper =====
434
  import unicodedata as _ud
435
 
 
 
 
 
 
 
 
 
 
436
  def _slugify_mytv(s):
437
  """Tạo slug cho mytv URL từ tên đội"""
438
  s = _ud.normalize('NFKD', s)
 
289
  def api_livescore_standings(league:str):
290
  tid=LEAGUE_IDS.get(league,27110);return JSONResponse({"html":_cached(f"ls_bxh_{league}",lambda:fetch_bongda_api(f"/api/league-table/home?tournament_id={tid}&is_detail=True"),ttl=_cache_ttl)})
291
  @app.get("/api/livescore/date/{date}")
292
+ def api_livescore_date(date:str):return JSONResponse({"html":_cached(f"ls_date_{date}",lambda:fetch_bongda_api(f"/api/fixtures/get-by-date?date={date}"),ttl=_cache_ttl_date)})
293
  @app.get("/api/match/{event_id}/commentaries")
294
  def api_match_commentaries(event_id:int):return JSONResponse({"html":fetch_bongda_api(f"/api/fixtures/commentaries?event_id={event_id}")})
295
  @app.get("/api/match/{event_id}/stats")
 
433
  # ===== MyTV.com.vn Video Scraper =====
434
  import unicodedata as _ud
435
 
436
+ @app.middleware("http")
437
+ async def add_cache_headers(request, call_next):
438
+ response = await call_next(request)
439
+ if request.url.path.startswith("/api/livescore/"):
440
+ response.headers["Cache-Control"] = "public, max-age=30"
441
+ return response
442
+
443
+
444
+
445
  def _slugify_mytv(s):
446
  """Tạo slug cho mytv URL từ tên đội"""
447
  s = _ud.normalize('NFKD', s)