refactor(ghost): _admin_get/_admin_headers compartidos en GhostPublisher
Build & Deploy ResearchOwl / build-and-push (push) Successful in 8s
Build & Deploy ResearchOwl / build-and-push (push) Successful in 8s
find_draft_by_title y fetch_published_menu duplicaban línea a línea el GET admin de Ghost (token, URL, ClientSession, dict de headers, status check, resp.json), y el dict Authorization/Accept-Version/Accept-Encoding estaba copiado en 3 sitios — el incidente brotli ya demostró que el fix por copia se deja sitios. Ahora los headers se construyen en un único punto (_admin_headers, con SAFE_ACCEPT_ENCODING de config) y el GET en _admin_get; publish_draft usa los mismos headers. aiohttp pasa a import de módulo en generator.py (era 'import aiohttp as _aio' repetido dentro de dos métodos). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
fbe8ae1885
commit
d31badeb5b
+7
-24
@@ -75,37 +75,20 @@ async def fetch_published_menu(lang: str) -> list[dict]:
|
||||
try:
|
||||
# Lazy import to avoid a heavy/circular import at module load.
|
||||
from src.generator.generator import GhostPublisher
|
||||
import aiohttp as _aio
|
||||
|
||||
pub = GhostPublisher(lang=lang)
|
||||
if not pub.is_configured():
|
||||
logger.warning("seo.menu: Ghost not configured for lang", lang=lang)
|
||||
return []
|
||||
|
||||
token = pub._make_token()
|
||||
url = (
|
||||
f"{pub.url}/ghost/api/admin/posts/"
|
||||
"?filter=status:published&fields=id,slug,title&limit=all"
|
||||
# _admin_get lleva los headers canónicos (auth, Accept-Version y el
|
||||
# Accept-Encoding sin br — ver KNOWN-ISSUES.md) y loguea los non-200.
|
||||
data = await pub._admin_get(
|
||||
"posts/?filter=status:published&fields=id,slug,title&limit=all",
|
||||
timeout=30,
|
||||
)
|
||||
timeout = _aio.ClientTimeout(total=30)
|
||||
async with _aio.ClientSession(timeout=timeout) as sess:
|
||||
async with sess.get(
|
||||
url,
|
||||
headers={
|
||||
"Authorization": f"Ghost {token}",
|
||||
"Accept-Version": "v5.0",
|
||||
# Explícito: sin esto, un backend brotli instalado haría
|
||||
# que aiohttp anuncie br y su decode roto tumbe el menú
|
||||
# ("using empty menu") — ver publish_draft.
|
||||
"Accept-Encoding": "gzip, deflate",
|
||||
},
|
||||
) as resp:
|
||||
if resp.status != 200:
|
||||
body = await resp.text()
|
||||
logger.warning("seo.menu: non-200 from Ghost",
|
||||
status=resp.status, body=body[:200])
|
||||
return []
|
||||
data = await resp.json()
|
||||
if data is None:
|
||||
return []
|
||||
|
||||
menu = [
|
||||
{"slug": p["slug"], "title": p.get("title", "")}
|
||||
|
||||
Reference in New Issue
Block a user