commit fafb2ce7fd7a140705547330b120fa1e68c0d961 from: Aleksey Ryndin date: Wed Oct 02 07:26:59 2024 UTC Fix: settings is not need commit - da7270e14b4f810371885c511c8759b8de007235 commit + fafb2ce7fd7a140705547330b120fa1e68c0d961 blob - edaab424439a0b9fa01c3353b276d9006bc1c348 blob + d110abd2c054f4b095428779a88ab0be21bcce59 --- lonk.py +++ lonk.py @@ -178,6 +178,9 @@ class LonkUrl: ("gemini", self._splitted_url.netloc, "/".join(self._base_path + page), query, "") ) + def media(self, mime, url): + return self.build("proxy", urlencode({"m": mime, "u": url})) if mime else url + @property def query(self): return self._splitted_url.query @@ -209,16 +212,6 @@ class HonkUrl: return json_loads(f.read().decode("utf8")) -def _proxy_url_factory(proxy_media_enabled, lonk_url): - def _get_proxy_url(mime, url): - return ( - lonk_url.build("proxy", urlencode({"m": mime, "u": url})) - if mime and proxy_media_enabled else - url - ) - return _get_proxy_url - - def _create_schema(db_con): db_con.execute( """ @@ -228,16 +221,6 @@ def _create_schema(db_con): cert_hash TEXT UNIQUE, honk_url TEXT NOT NULL, token TEXT NOT NULL - ) - """ - ) - db_con.execute( - """ - CREATE TABLE - client_settings ( - client_id INTEGER, - media_gemini_proxy INTEGER, - FOREIGN KEY (client_id) REFERENCES client (client_id) ) """ ) @@ -352,7 +335,7 @@ class _Collected: return rv -def lonk(db_con, client_id, lonk_url, honk_url, fn_media_url): +def lonk(db_con, client_id, lonk_url, honk_url): gethonks_answer = honk_url.do_get(action="gethonks", page="home") lonk_page = {} for honk in reversed(gethonks_answer.get("honks") or []): @@ -457,17 +440,17 @@ def lonk(db_con, client_id, lonk_url, honk_url, fn_med lines = [ f"## From {collected.honker}{collected.format_reason()} {collected.date}", f'=> {lonk_url.build("convoy", urlencode({"c": collected.convoy}))} Convoy {collected.convoy}', - HtmlToGmi(honk_url.build_url(), fn_media_url).feed(collected.html) + HtmlToGmi(honk_url.build_url(), lonk_url.media).feed(collected.html) ] for donk_url, donk_mime, donk_text in collected.iterate_donks(db_con): - lines.append(f'=> {fn_media_url(donk_mime, donk_url)}') + lines.append(f'=> {lonk_url.media(donk_mime, donk_url)}') if donk_text: lines.append(donk_text) print("\r\n".join(lines)) print("\r") -def convoy(db_con, client_id, lonk_url, honk_url, fn_media_url): +def convoy(db_con, client_id, lonk_url, honk_url): query = {pair[0]: pair[1] for pair in parse_qsl(lonk_url.query)} if "c" not in query: print("51 Not found\r") @@ -477,18 +460,18 @@ def convoy(db_con, client_id, lonk_url, honk_url, fn_m print("20 text/gemini\r") print(f"# 𝓗 onk: convoy {query['c']}\r") print("\r") - _gethonks(gethonks_answer, lonk_url, honk_url, fn_media_url) + _gethonks(gethonks_answer, lonk_url, honk_url) -def atme(db_con, client_id, lonk_url, honk_url, fn_media_url): +def atme(db_con, client_id, lonk_url, honk_url): gethonks_answer = honk_url.do_get(action="gethonks", page="atme") print("20 text/gemini\r") print("# 𝓗 onk: @me") print("\r") - _gethonks(gethonks_answer, lonk_url, honk_url, fn_media_url) + _gethonks(gethonks_answer, lonk_url, honk_url) -def _gethonks(gethonks_answer, lonk_url, honk_url, fn_media_url): +def _gethonks(gethonks_answer, lonk_url, honk_url): line = f"=> {lonk_url.build('atme')} @me" if gethonks_answer["mecount"]: line += f' ({gethonks_answer["mecount"]})' @@ -513,11 +496,11 @@ def _gethonks(gethonks_answer, lonk_url, honk_url, fn_ ] if re_url: lines.append(f'=> {re_url} Re: {re_url}') - lines.append(HtmlToGmi(honk_url.build_url(), fn_media_url).feed(honk["HTML"])) + lines.append(HtmlToGmi(honk_url.build_url(), lonk_url.media).feed(honk["HTML"])) for donk in honk.get("Donks") or []: donk_url = honk_url.build_url(path=f'/d/{donk["XID"]}') if donk.get("XID") else donk["URL"] donk_mime, donk_text = donk["Media"], donk.get("Desc") or donk.get("Name") or None - lines.append(f'=> {fn_media_url(donk_mime, donk_url)}') + lines.append(f'=> {lonk_url.media(donk_mime, donk_url)}') if donk_text: lines.append(donk_text) print("\r\n".join(lines)) @@ -576,10 +559,9 @@ def authenticated(cert_hash, lonk_url, fn_impl): if not row: print(f'30 {lonk_url.build("ask_server")}\r') return - fn_media_url = _proxy_url_factory(environ.get("LONK_PROXY_MEDIA"), lonk_url) client_id, honk_url, token = row with db_con: - fn_impl(db_con, client_id, lonk_url, HonkUrl(honk_url, token), fn_media_url) + fn_impl(db_con, client_id, lonk_url, HonkUrl(honk_url, token)) def proxy(mime, url):