diff --git a/files/classes/comment.py b/files/classes/comment.py index 5b44c9e93..5b2574a93 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -65,6 +65,9 @@ def normalize_urls_runtime(body, v): if v and v.reddit != 'old.reddit.com': body = reddit_to_vreddit_regex.sub(rf'\1https://{v.reddit}/\2/', body) + if v and v.nitter: + body = twitter_to_nitter_regex.sub(r'\1https://nitter.unixfox.eu/', body) + if v and v.imgsed: body = instagram_to_imgsed_regex.sub(r'\1https://imgsed.com/', body) diff --git a/files/classes/user.py b/files/classes/user.py index 74d1dcdb9..bd3557835 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -102,6 +102,7 @@ class User(Base): newtab = Column(Boolean, default=False) newtabexternal = Column(Boolean, default=True) reddit = Column(String, default='old.reddit.com') + nitter = Column(Boolean, default=False) imgsed = Column(Boolean) frontsize = Column(Integer, default=25) controversial = Column(Boolean, default=False) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index b2cec33df..84daa0ff3 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -37,6 +37,9 @@ def _archiveorg(url): def archive_url(url): gevent.spawn(_archiveorg, url) + if url.startswith('https://twitter.com/'): + url = url.replace('https://twitter.com/', 'https://nitter.unixfox.eu/') + gevent.spawn(_archiveorg, url) if url.startswith('https://instagram.com/'): url = url.replace('https://instagram.com/', 'https://imginn.com/') gevent.spawn(_archiveorg, url) diff --git a/files/helpers/regex.py b/files/helpers/regex.py index da65f18fe..7980c87fd 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -126,6 +126,8 @@ greentext_regex = re.compile("(\n|^)>([^ >][^\n]*)", flags=re.A) allowed_domain_regex = re.compile("[a-z0-9\-.]+", flags=re.I|re.A) +twitter_to_nitter_regex = re.compile('(^|>|")https:\/\/twitter.com\/(?!i\/)', flags=re.A) + instagram_to_imgsed_regex = re.compile('(^|>|")https:\/\/instagram.com\/(?!reel\/)', flags=re.A) color_regex = re.compile("[a-f0-9]{6}", flags=re.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 2eac41820..4a11d9af3 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -766,6 +766,9 @@ def normalize_url(url): .replace("https://x.com", "https://twitter.com") \ .replace("https://www.twitter.com", "https://twitter.com") \ .replace("https://fxtwitter.com", "https://twitter.com") \ + .replace("https://nitter.unixfox.eu/", "https://twitter.com/") \ + .replace("https://nitter.42l.fr/", "https://twitter.com/") \ + .replace("https://nitter.unixfox.eu/", "https://twitter.com/") \ .replace("https://m.facebook.com", "https://facebook.com") \ .replace("https://en.m.wikipedia.org", "https://en.wikipedia.org") \ .replace("https://www.instagram.com", "https://instagram.com") \ diff --git a/files/routes/settings.py b/files/routes/settings.py index f3f8ac20f..ffeaa6800 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -169,6 +169,7 @@ def settings_personal_post(v): updated = updated or update_flag("hidevotedon", "hidevotedon") updated = updated or update_flag("newtab", "newtab") updated = updated or update_flag("newtabexternal", "newtabexternal") + updated = updated or update_flag("nitter", "nitter") updated = updated or update_flag("imgsed", "imgsed") updated = updated or update_flag("controversial", "controversial") updated = updated or update_flag("show_sigs", "show_sigs") diff --git a/files/templates/settings/advanced.html b/files/templates/settings/advanced.html index a9b09a732..9bfd3a826 100644 --- a/files/templates/settings/advanced.html +++ b/files/templates/settings/advanced.html @@ -103,6 +103,7 @@
External Services
+ {{common.toggle_section("Use Nitter for Twitter Links", "nitter", "nitter", v.nitter, "Enable if you would like to automatically convert twitter.com links to nitter.unixfox.eu links.", false)}} {{common.toggle_section("Use imgsed for Instagram Links", "imgsed", "imgsed", v.imgsed, "Enable if you would like to automatically convert instagram.com links to imgsed.com links.", false)}}
diff --git a/schema.sql b/schema.sql index c1eba1e05..06a2a7e35 100644 --- a/schema.sql +++ b/schema.sql @@ -123,6 +123,7 @@ CREATE TABLE public.users ( background character varying(167), verified character varying(100), received_award_count integer DEFAULT 0 NOT NULL, + nitter boolean NOT NULL, truescore integer DEFAULT 0 NOT NULL, frontsize integer DEFAULT 25 NOT NULL, coins_spent integer DEFAULT 0 NOT NULL, @@ -3064,4 +3065,3 @@ ALTER TABLE ONLY public.comments -- -- PostgreSQL database dump complete -- -