decentralized and customizable links page on top of atproto ligo.at
atproto link-in-bio python uv

refuse to serve blocked did profile

+46 -9
+4 -5
src/atproto/__init__.py
··· 1 - from dns.resolver import resolve as resolve_dns, NXDOMAIN 2 from re import match as regex_match 3 from typing import Any 4 - import httpx 5 6 from .kv import KV, nokv 7 - 8 from .validator import is_valid_authserver_meta 9 from ..security import is_safe_url 10 ··· 96 return did 97 98 try: 99 - answer = resolve_dns(f"_atproto.{handle}", "TXT") 100 - except NXDOMAIN: 101 return None 102 103 for record in answer:
··· 1 + import dns.resolver as dns 2 + import httpx 3 from re import match as regex_match 4 from typing import Any 5 6 from .kv import KV, nokv 7 from .validator import is_valid_authserver_meta 8 from ..security import is_safe_url 9 ··· 95 return did 96 97 try: 98 + answer = dns.resolve(f"_atproto.{handle}", "TXT") 99 + except dns.NXDOMAIN: 100 return None 101 102 for record in answer:
+12 -4
src/main.py
··· 45 def page_profile_with_did(did: str): 46 did = f"did:{did}" 47 if not is_valid_did(did): 48 - return "invalid did", 400 49 return page_profile(did) 50 51 ··· 55 kv = KV(app, "did_from_handle") 56 did = resolve_did_from_handle(handle, kv, reload=reload) 57 if did is None: 58 - return "did not found", 404 59 return page_profile(did, reload=reload) 60 61 62 def page_profile(did: str, reload: bool = False): 63 kv = KV(app, "pds_from_did") 64 pds = resolve_pds_from_did(did, kv, reload=reload) 65 if pds is None: 66 - return "pds not found", 404 67 profile, _ = load_profile(pds, did, reload=reload) 68 links = load_links(pds, did, reload=reload) 69 if links is None: 70 - return "profile not found", 404 71 72 if reload: 73 # remove the ?reload parameter ··· 265 ) 266 if not response or not response.is_success: 267 app.logger.warning("PDS HTTP ERROR")
··· 45 def page_profile_with_did(did: str): 46 did = f"did:{did}" 47 if not is_valid_did(did): 48 + return render_template("error.html", message="invalid did"), 400 49 return page_profile(did) 50 51 ··· 55 kv = KV(app, "did_from_handle") 56 did = resolve_did_from_handle(handle, kv, reload=reload) 57 if did is None: 58 + return render_template("error.html", message="did not found"), 404 59 return page_profile(did, reload=reload) 60 61 62 def page_profile(did: str, reload: bool = False): 63 + if _is_did_blocked(did): 64 + app.logger.debug(f"handling blocked did {did}") 65 + return render_template("error.html", message="profile not found"), 404 66 kv = KV(app, "pds_from_did") 67 pds = resolve_pds_from_did(did, kv, reload=reload) 68 if pds is None: 69 + return render_template("error.html", message="pds not found"), 404 70 profile, _ = load_profile(pds, did, reload=reload) 71 links = load_links(pds, did, reload=reload) 72 if links is None: 73 + return render_template("error.html", message="profile not found"), 404 74 75 if reload: 76 # remove the ?reload parameter ··· 268 ) 269 if not response or not response.is_success: 270 app.logger.warning("PDS HTTP ERROR") 271 + 272 + 273 + def _is_did_blocked(did: str) -> bool: 274 + kv = KV(app, "blockeddids") 275 + return kv.get(did) is not None
+4
src/static/style.css
··· 49 max-width: 25rem; 50 } 51 52 header { 53 margin: 2.5em 0; 54 text-align: center;
··· 49 max-width: 25rem; 50 } 51 52 + .wrapper.error p { 53 + text-align: center; 54 + } 55 + 56 header { 57 margin: 2.5em 0; 58 text-align: center;
+26
src/templates/error.html
···
··· 1 + <!doctype html> 2 + <html> 3 + <head> 4 + <meta charset="utf-8" /> 5 + <title>not found &mdash; ligo.at</title> 6 + <meta name="viewport" content="width=device-width, initial-scale=1" /> 7 + <link rel="stylesheet" href="{{ url_for('static', filename='inter.css') }}" /> 8 + <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" /> 9 + <link rel="icon" type="image/png" sizes="16x16" href="{{ url_for('static', filename='favicon-16.png') }}" /> 10 + <link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='favicon-32.png') }}" /> 11 + <link rel="icon" type="image/png" sizes="48x48" href="{{ url_for('static', filename='favicon-48.png') }}" /> 12 + </head> 13 + <body> 14 + <div class="wrapper error"> 15 + <header> 16 + <h1>oops!</h1> 17 + </header> 18 + <p>{{ message }}</p> 19 + <footer> 20 + <a href="/">home</a> 21 + <span>·</span> 22 + Made by <a href="/@nauta.one">@nauta.one</a> 23 + </footer> 24 + </div> 25 + </body> 26 + </html>