rmi-backend/app/protection_api/domains.py
opencode c762564d40 style(rmi-backend): complete lint cleanup — 1175→0 ruff errors
- Fix 71 invalid-syntax files (class-body newline-broken assignments)
- Add from/None chain to 307 B904 raise-without-from sites
- Add B008 ignore to ruff.toml (already in pyproject.toml)
- Noqa F401 on __init__.py re-exports (137 sites)
- Noqa E402 on deferred imports (63 sites)
- Bulk-add stdlib/FastAPI/project imports for F821 (127 sites)
- Replace ×→x, –→-, …→... in docstrings (4093 chars)
- Manual refactor of 5 SIM103/SIM116 patterns

Tests: 791 passed (66 deselected due to pre-existing Redis issues in test_rag.py)
Co-authored-by: opencode <opencode@rugmunch.io>
2026-07-06 15:43:20 +02:00

37 lines
1.2 KiB
Python

import json
import os
from fastapi import APIRouter, HTTPException
router = APIRouter()
@router.get("/", response_model=list[str])
async def get_domains():
"""Return the full domain blocklist for browser extension download.
Returns:
List[str]: List of blocked domains
"""
try:
# Load from blocklist.json in browser-extension directory
blocklist_path = "/root/browser-extension/blocklist.json"
if not os.path.exists(blocklist_path):
raise HTTPException(status_code=500, detail="Blocklist file not found")
with open(blocklist_path) as f:
blocklist = json.load(f)
# Also include RAG known scams if available
rag_scams = []
rag_path = "/root/backend/app/rag/known_scams.json"
if os.path.exists(rag_path):
with open(rag_path) as f:
rag_data = json.load(f)
rag_scams = rag_data.get("domains", [])
# Combine and deduplicate
all_domains = list(set(blocklist.get("domains", []) + rag_scams))
return all_domains
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error loading blocklist: {e!s}") from e