1 from fastapi import FastAPI
5 app = FastAPI(docs_url=base_url+"/docs", redoc_url=base_url+"/redoc")
7 @app.get(base_url+"/info")
9 conn = sqlite3.connect("blocks.db")
11 c.execute("select (select count(domain) from instances), (select count(domain) from instances where software in ('pleroma', 'mastodon')), (select count(blocker) from blocks)")
12 known, indexed, blocks = c.fetchone()
15 "known_instances": known,
16 "indexed_instances": indexed,
17 "blocks_recorded": blocks,
18 "source_code": "https://gitlab.com/EnjuAihara/fedi-block-api",
21 @app.get(base_url+"/domain/{domain}")
22 def blocked(domain: str):
23 conn = sqlite3.connect("blocks.db")
25 c.execute("select blocker, block_level, reason from blocks where blocked = ?", (domain,))
32 for domain, block_level, reason in blocks:
33 if block_level in result:
34 result[block_level].append(domain)
36 result[block_level] = [domain]
39 if block_level in reasons:
40 reasons[block_level][domain] = reason
42 reasons[block_level] = {domain: reason}
44 return {"blocks": result, "reasons": reasons}