|
4 | 4 | from loguru import logger |
5 | 5 |
|
6 | 6 | from app.api.endpoints.manifest import get_config_id |
| 7 | +from app.core.config import settings |
7 | 8 | from app.core.security import redact_token |
8 | 9 | from app.core.settings import UserSettings, get_default_settings |
9 | | -from app.services.catalog_updater import refresh_catalogs_for_credentials |
| 10 | +from app.services.catalog_updater import catalog_updater |
10 | 11 | from app.services.recommendation.engine import RecommendationEngine |
11 | 12 | from app.services.stremio.service import StremioBundle |
12 | 13 | from app.services.token_store import token_store |
@@ -80,6 +81,10 @@ async def get_catalog(type: str, id: str, response: Response, token: str): |
80 | 81 | if not credentials: |
81 | 82 | raise HTTPException(status_code=401, detail="Invalid or expired token. Please reconfigure the addon.") |
82 | 83 |
|
| 84 | + # Trigger lazy update if needed |
| 85 | + if settings.AUTO_UPDATE_CATALOGS: |
| 86 | + await catalog_updater.trigger_update(token, credentials) |
| 87 | + |
83 | 88 | bundle = StremioBundle() |
84 | 89 | try: |
85 | 90 | # 1. Resolve Auth Key (with potential fallback to login) |
@@ -200,17 +205,3 @@ def _get_limits() -> tuple[int, int]: |
200 | 205 | raise HTTPException(status_code=500, detail=str(e)) |
201 | 206 | finally: |
202 | 207 | await bundle.close() |
203 | | - |
204 | | - |
205 | | -@router.get("/{token}/catalog/update") |
206 | | -async def update_catalogs(token: str): |
207 | | - """ |
208 | | - Update the catalogs for the addon. This is a manual endpoint to update the catalogs. |
209 | | - """ |
210 | | - # Decode credentials from path |
211 | | - credentials = await token_store.get_user_data(token) |
212 | | - |
213 | | - logger.info(f"[{redact_token(token)}] Updating catalogs in response to manual request") |
214 | | - updated = await refresh_catalogs_for_credentials(token, credentials) |
215 | | - logger.info(f"Manual catalog update completed: {updated}") |
216 | | - return {"success": updated} |
0 commit comments