custom_components/bahmcloud_store/core.py aktualisiert
This commit is contained in:
@@ -88,6 +88,16 @@ class BCSCore:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async def full_refresh(self, source: str = "manual") -> None:
|
||||
"""Run a full store refresh and notify listeners.
|
||||
|
||||
This is the single entry-point used by both the periodic timer and
|
||||
the manual refresh button.
|
||||
"""
|
||||
_LOGGER.info("BCS full refresh triggered (source=%s)", source)
|
||||
await self.refresh()
|
||||
self.signal_updated()
|
||||
|
||||
async def register_http_views(self) -> None:
|
||||
self.hass.http.register_view(StaticAssetsView())
|
||||
self.hass.http.register_view(BCSApiView(self))
|
||||
@@ -157,7 +167,6 @@ class BCSCore:
|
||||
await asyncio.gather(*(process_one(r) for r in merged.values()), return_exceptions=True)
|
||||
|
||||
def _add_cache_buster(self, url: str) -> str:
|
||||
"""Append a timestamp query parameter safely (works with existing query params)."""
|
||||
parts = urlsplit(url)
|
||||
q = dict(parse_qsl(parts.query, keep_blank_values=True))
|
||||
q["t"] = str(int(time.time()))
|
||||
@@ -165,9 +174,6 @@ class BCSCore:
|
||||
return urlunsplit((parts.scheme, parts.netloc, parts.path, new_query, parts.fragment))
|
||||
|
||||
def _gitea_src_to_raw(self, url: str) -> str:
|
||||
"""If the URL points to a Gitea 'src' page, convert it to a raw file URL."""
|
||||
# Example:
|
||||
# /owner/repo/src/branch/main/store.yaml -> /owner/repo/raw/branch/main/store.yaml
|
||||
parts = urlsplit(url)
|
||||
path = parts.path
|
||||
path2 = path.replace("/src/branch/", "/raw/branch/")
|
||||
@@ -191,7 +197,6 @@ class BCSCore:
|
||||
return await resp.text()
|
||||
|
||||
async def _load_index_repos(self) -> tuple[list[RepoItem], int]:
|
||||
# ---- Phase B: force an actual remote reload of store.yaml ----
|
||||
store_url = (self.config.store_url or "").strip()
|
||||
if not store_url:
|
||||
raise BCSError("store_url is empty")
|
||||
@@ -201,8 +206,6 @@ class BCSCore:
|
||||
try:
|
||||
raw = await self._fetch_store_text(url)
|
||||
|
||||
# If we accidentally fetched a HTML "src" page, try converting to raw.
|
||||
# This makes the system robust even if someone configures a /src/branch/ URL.
|
||||
if "<html" in raw.lower() or "<!doctype html" in raw.lower():
|
||||
fallback = self._add_cache_buster(self._gitea_src_to_raw(store_url))
|
||||
if fallback != url:
|
||||
@@ -211,7 +214,6 @@ class BCSCore:
|
||||
|
||||
except Exception as e:
|
||||
raise BCSError(f"Failed fetching store index: {e}") from e
|
||||
# ---- end Phase B fix ----
|
||||
|
||||
try:
|
||||
data = ha_yaml.parse_yaml(raw)
|
||||
|
||||
Reference in New Issue
Block a user