custom_components/bahmcloud_store/views.py aktualisiert

This commit is contained in:
2026-01-15 16:04:59 +00:00
parent 38730cdd31
commit bcfbf7151c

View File

@@ -161,7 +161,6 @@ def _extract_text_recursive(obj: Any, depth: int = 0) -> str | None:
# content may already be plain text # content may already be plain text
if isinstance(content, str) and (not isinstance(encoding, str) or not encoding.strip()): if isinstance(content, str) and (not isinstance(encoding, str) or not encoding.strip()):
# Heuristic: treat as markdown if it has typical markdown chars, otherwise still return
return content return content
# 2) direct text keys (readme/markdown/text/body/data) # 2) direct text keys (readme/markdown/text/body/data)
@@ -247,7 +246,7 @@ class BCSApiView(HomeAssistantView):
requires_auth = True requires_auth = True
def __init__(self, core: Any) -> None: def __init__(self, core: Any) -> None:
self.core = core self.core: BCSCore = core
async def get(self, request: web.Request) -> web.Response: async def get(self, request: web.Request) -> web.Response:
return web.json_response( return web.json_response(
@@ -255,7 +254,40 @@ class BCSApiView(HomeAssistantView):
) )
async def post(self, request: web.Request) -> web.Response: async def post(self, request: web.Request) -> web.Response:
data = await request.json() """
Supported operations:
1) Full refresh:
POST /api/bcs?action=refresh
2) JSON operations (body based):
{
"op": "add_custom_repo",
"url": "...",
"name": "..."
}
"""
# --- Phase B: Manual full refresh trigger ---
action = request.query.get("action")
if action == "refresh":
_LOGGER.info("BCS manual refresh triggered via API")
try:
await self.core.refresh()
self.core.signal_updated()
return web.json_response({"ok": True})
except Exception as e:
_LOGGER.error("BCS manual refresh failed: %s", e)
return web.json_response(
{"ok": False, "message": "Refresh failed"}, status=500
)
# --- Existing JSON based operations ---
try:
data = await request.json()
except Exception:
data = {}
op = data.get("op") op = data.get("op")
if op == "add_custom_repo": if op == "add_custom_repo":
@@ -276,7 +308,7 @@ class BCSCustomRepoView(HomeAssistantView):
requires_auth = True requires_auth = True
def __init__(self, core: Any) -> None: def __init__(self, core: Any) -> None:
self.core = core self.core: BCSCore = core
async def delete(self, request: web.Request) -> web.Response: async def delete(self, request: web.Request) -> web.Response:
repo_id = request.query.get("id") repo_id = request.query.get("id")
@@ -292,7 +324,7 @@ class BCSReadmeView(HomeAssistantView):
requires_auth = True requires_auth = True
def __init__(self, core: Any) -> None: def __init__(self, core: Any) -> None:
self.core = core self.core: BCSCore = core
async def get(self, request: web.Request) -> web.Response: async def get(self, request: web.Request) -> web.Response:
repo_id = request.query.get("repo_id") repo_id = request.query.get("repo_id")
@@ -309,7 +341,6 @@ class BCSReadmeView(HomeAssistantView):
status=404, status=404,
) )
# Ensure strict JSON string output (avoid accidental objects)
md_str = str(md) md_str = str(md)
html = _render_markdown_server_side(md_str) html = _render_markdown_server_side(md_str)