feat: append source domain fragment to alert short URLs
Short URLs now include the original source domain as a URL fragment, e.g. https://paste.mymx.me/s/foo#github.com, so the destination is visible before clicking. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import urllib.request
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from derp.http import urlopen as _urlopen
|
from derp.http import urlopen as _urlopen
|
||||||
from derp.plugin import command, event
|
from derp.plugin import command, event
|
||||||
@@ -1909,7 +1910,8 @@ async def _poll_once(bot, key: str, announce: bool = True) -> None:
|
|||||||
None, fp.shorten_url, bot, url,
|
None, fp.shorten_url, bot, url,
|
||||||
)
|
)
|
||||||
if short_url != url:
|
if short_url != url:
|
||||||
display_url = short_url
|
domain = urlparse(url).hostname or ""
|
||||||
|
display_url = f"{short_url}#{domain}" if domain else short_url
|
||||||
else:
|
else:
|
||||||
short_url = ""
|
short_url = ""
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -2104,14 +2106,17 @@ async def cmd_alert(bot, message):
|
|||||||
title = _truncate(title) if title else "(no title)"
|
title = _truncate(title) if title else "(no title)"
|
||||||
if extra:
|
if extra:
|
||||||
title = f"{title} | {extra}"
|
title = f"{title} | {extra}"
|
||||||
display_url = short_url or url
|
domain = urlparse(url).hostname or "" if url else ""
|
||||||
|
display_url = (f"{short_url}#{domain}" if short_url and domain
|
||||||
|
else short_url or url)
|
||||||
if fp and url and not short_url:
|
if fp and url and not short_url:
|
||||||
try:
|
try:
|
||||||
new_short = await loop.run_in_executor(
|
new_short = await loop.run_in_executor(
|
||||||
None, fp.shorten_url, bot, url,
|
None, fp.shorten_url, bot, url,
|
||||||
)
|
)
|
||||||
if new_short != url:
|
if new_short != url:
|
||||||
display_url = new_short
|
display_url = (f"{new_short}#{domain}" if domain
|
||||||
|
else new_short)
|
||||||
db.execute(
|
db.execute(
|
||||||
"UPDATE results SET short_url = ? WHERE id = ?",
|
"UPDATE results SET short_url = ? WHERE id = ?",
|
||||||
(new_short, row_id),
|
(new_short, row_id),
|
||||||
|
|||||||
Reference in New Issue
Block a user