mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
remove tracking from links fixes #34
This commit is contained in:
parent
47bf0ddedb
commit
6914a47206
3 changed files with 10 additions and 7 deletions
|
@ -24,7 +24,7 @@ import pytesseract
|
|||
|
||||
from app.utils import get_request, allowlist_html, html_to_markdown, get_setting, ap_datetime, markdown_to_html, \
|
||||
is_image_url, domain_from_url, gibberish, ensure_directory_exists, markdown_to_text, head_request, post_ranking, \
|
||||
shorten_string, reply_already_exists, reply_is_just_link_to_gif_reaction, confidence, clean_link
|
||||
shorten_string, reply_already_exists, reply_is_just_link_to_gif_reaction, confidence, remove_tracking_from_link
|
||||
|
||||
|
||||
def public_key():
|
||||
|
@ -1227,7 +1227,7 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
|
|||
post.image = image
|
||||
else:
|
||||
post.type = POST_TYPE_LINK
|
||||
post.url = clean_link(post.url)
|
||||
post.url = remove_tracking_from_link(post.url)
|
||||
domain = domain_from_url(post.url)
|
||||
# notify about links to banned websites.
|
||||
already_notified = set() # often admins and mods are the same people - avoid notifying them twice
|
||||
|
|
|
@ -15,7 +15,7 @@ from app.constants import POST_TYPE_ARTICLE, POST_TYPE_LINK, POST_TYPE_IMAGE
|
|||
from app.models import Community, File, BannedInstances, PostReply, PostVote, Post, utcnow, CommunityMember, Site, \
|
||||
Instance, Notification, User
|
||||
from app.utils import get_request, gibberish, markdown_to_html, domain_from_url, allowlist_html, \
|
||||
html_to_markdown, is_image_url, ensure_directory_exists, inbox_domain, post_ranking, shorten_string, parse_page, clean_link
|
||||
html_to_markdown, is_image_url, ensure_directory_exists, inbox_domain, post_ranking, shorten_string, parse_page, remove_tracking_from_link
|
||||
from sqlalchemy import func
|
||||
import os
|
||||
|
||||
|
@ -177,7 +177,7 @@ def save_post(form, post: Post):
|
|||
post.body = form.link_body.data
|
||||
post.body_html = markdown_to_html(post.body)
|
||||
url_changed = post.id is None or form.link_url.data != post.url
|
||||
post.url = clean_link(form.link_url.data)
|
||||
post.url = remove_tracking_from_link(form.link_url.data)
|
||||
post.type = POST_TYPE_LINK
|
||||
domain = domain_from_url(form.link_url.data)
|
||||
domain.post_count += 1
|
||||
|
|
|
@ -260,9 +260,12 @@ def markdown_to_text(markdown_text) -> str:
|
|||
def domain_from_url(url: str, create=True) -> Domain:
|
||||
parsed_url = urlparse(url.lower().replace('www.', ''))
|
||||
if parsed_url and parsed_url.hostname:
|
||||
domain = Domain.query.filter_by(name=parsed_url.hostname.lower()).first()
|
||||
find_this = parsed_url.hostname.lower()
|
||||
if find_this == 'youtu.be':
|
||||
find_this = 'youtube.com'
|
||||
domain = Domain.query.filter_by(name=find_this).first()
|
||||
if create and domain is None:
|
||||
domain = Domain(name=parsed_url.hostname.lower())
|
||||
domain = Domain(name=find_this)
|
||||
db.session.add(domain)
|
||||
db.session.commit()
|
||||
return domain
|
||||
|
@ -747,7 +750,7 @@ def sha256_digest(input_string):
|
|||
return sha256_hash.hexdigest()
|
||||
|
||||
|
||||
def clean_link(url):
|
||||
def remove_tracking_from_link(url):
|
||||
# strip ?si=abcDEFgh from youtu.be links
|
||||
clean = re.search(r"(https://youtu.be/\w+)", url)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue