custom_components/bahmcloud_store/views.py aktualisiert
This commit is contained in:
@@ -17,13 +17,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def _render_markdown_server_side(md: str) -> str | None:
|
def _render_markdown_server_side(md: str) -> str | None:
|
||||||
"""Render Markdown -> sanitized HTML (server-side)."""
|
|
||||||
text = (md or "").strip()
|
text = (md or "").strip()
|
||||||
if not text:
|
if not text:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
html: str | None = None
|
html: str | None = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import markdown as mdlib # type: ignore
|
import markdown as mdlib # type: ignore
|
||||||
|
|
||||||
@@ -181,6 +179,39 @@ class BCSApiView(HomeAssistantView):
|
|||||||
return web.json_response({"ok": False, "message": "Unknown operation"}, status=400)
|
return web.json_response({"ok": False, "message": "Unknown operation"}, status=400)
|
||||||
|
|
||||||
|
|
||||||
|
class BCSRefreshView(HomeAssistantView):
|
||||||
|
"""
|
||||||
|
Manual refresh endpoint to reload store.yaml/bcs.yaml immediately.
|
||||||
|
This avoids waiting for the auto-refresh interval.
|
||||||
|
"""
|
||||||
|
url = "/api/bcs/refresh"
|
||||||
|
name = "api:bcs_refresh"
|
||||||
|
requires_auth = True
|
||||||
|
|
||||||
|
def __init__(self, core: Any) -> None:
|
||||||
|
self.core = core
|
||||||
|
|
||||||
|
async def post(self, request: web.Request) -> web.Response:
|
||||||
|
try:
|
||||||
|
# We intentionally call a dedicated core method if present.
|
||||||
|
# Fallbacks are used to keep compatibility with older core versions.
|
||||||
|
if hasattr(self.core, "async_refresh_now"):
|
||||||
|
await self.core.async_refresh_now()
|
||||||
|
elif hasattr(self.core, "refresh_now"):
|
||||||
|
await self.core.hass.async_add_executor_job(self.core.refresh_now)
|
||||||
|
elif hasattr(self.core, "load_index"):
|
||||||
|
await self.core.hass.async_add_executor_job(self.core.load_index)
|
||||||
|
else:
|
||||||
|
_LOGGER.warning("No refresh method found on core; returning current cached data.")
|
||||||
|
except Exception as e:
|
||||||
|
_LOGGER.exception("Manual refresh failed: %s", e)
|
||||||
|
return web.json_response({"ok": False, "message": f"Refresh failed: {e}"}, status=500)
|
||||||
|
|
||||||
|
return web.json_response(
|
||||||
|
{"ok": True, "repos": self.core.list_repos_public()}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BCSCustomRepoView(HomeAssistantView):
|
class BCSCustomRepoView(HomeAssistantView):
|
||||||
url = "/api/bcs/custom_repo"
|
url = "/api/bcs/custom_repo"
|
||||||
name = "api:bcs_custom_repo"
|
name = "api:bcs_custom_repo"
|
||||||
@@ -231,10 +262,7 @@ class BCSReadmeView(HomeAssistantView):
|
|||||||
|
|
||||||
if not md or not md.strip():
|
if not md or not md.strip():
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
{
|
{"ok": False, "message": "README not found (raw endpoint returned 404)."},
|
||||||
"ok": False,
|
|
||||||
"message": "README not found (raw endpoint returned 404).",
|
|
||||||
},
|
|
||||||
status=404,
|
status=404,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user