diff --git a/files/classes/comment.py b/files/classes/comment.py index de25267d0..801ba0c4e 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -85,8 +85,8 @@ 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.twitter != 'twitter.com': + body = twitter_domain_regex.sub(rf'\1https://{v.twitter}/', 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 f229953a2..2dd7dd127 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -154,7 +154,7 @@ class User(Base): offsite_mentions = Column(Boolean) if SITE_NAME == 'WPD' and not IS_LOCALHOST: - nitter = False + twitter = 'twitter.com' imgsed = False controversial = False reddit = 'old.reddit.com' @@ -164,7 +164,7 @@ class User(Base): hidevotedon = Column(Boolean, default=False) hide_cw = Column(Boolean, default=False) else: - nitter = Column(Boolean, default=False) + twitter = Column(String, default='twitter.com') imgsed = Column(Boolean, default=False) controversial = Column(Boolean, default=False) reddit = Column(String, default='old.reddit.com') diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 4c4070879..3ccab5c77 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -38,9 +38,6 @@ 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 824e8e0db..9ca3cacfe 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -125,7 +125,7 @@ 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) +twitter_domain_regex = re.compile('(^|>|")https:\/\/twitter.com\/(?!i\/)', flags=re.A) instagram_to_imgsed_regex = re.compile('(^|>|")https:\/\/instagram.com\/(?!reel\/)', flags=re.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index ff6eda0e4..0fe08a9f5 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -728,9 +728,6 @@ domain_replacements = { "https://x.com": "https://twitter.com", "https://www.twitter.com": "https://twitter.com", "https://fxtwitter.com": "https://twitter.com", - "https://nitter.net/": "https://twitter.com/", - "https://nitter.42l.fr/": "https://twitter.com/", - "https://nitter.unixfox.eu/": "https://twitter.com/", "https://m.facebook.com": "https://facebook.com", "https://en.m.wikipedia.org": "https://en.wikipedia.org", "https://www.instagram.com": "https://instagram.com", diff --git a/files/routes/settings.py b/files/routes/settings.py index 91ac14d28..5724da09f 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -170,7 +170,6 @@ def settings_personal_post(v): updated = updated or update_flag("hide_cw", "hide_cw") 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") @@ -1029,6 +1028,20 @@ def settings_pronouns_change(v): return {"message": "Pronouns successfully updated!"} +@app.post("/settings/twitter") +@limiter.limit('1/second', scope=rpath) +@limiter.limit('1/second', scope=rpath, key_func=get_ID) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@auth_required +def settings_twitter(v): + twitter = process_settings_plaintext("twitter", v.twitter, 50, "twitter.com") + + v.twitter = twitter + g.db.add(v) + + return {"message": "Twitter domain successfully updated!"} + @app.post("/settings/checkmark_text") @limiter.limit('1/second', scope=rpath) diff --git a/files/templates/settings/advanced.html b/files/templates/settings/advanced.html index c0e3894da..c0b185f7e 100644 --- a/files/templates/settings/advanced.html +++ b/files/templates/settings/advanced.html @@ -117,8 +117,10 @@
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)}} + + {{common.line_text_section('twitter', '/settings/twitter', 'twitter', 'Twitter Domain', v.twitter, 'Limit of 50 characters', 'Change the domain you would like to view twitter posts in.', 'Save', false, 5, 50, '[A-Za-z0-9.-]+', false, 'Change the domain you would like to view twitter posts in.')}} +
diff --git a/files/templates/settings/common.html b/files/templates/settings/common.html index 8aec9f8cc..c29865aee 100644 --- a/files/templates/settings/common.html +++ b/files/templates/settings/common.html @@ -52,10 +52,13 @@
{% endmacro %} -{% macro line_text_section(id, form_action, form_name, section_title, contents, below_text, placeholder_text, button_text, show_emojis, minlength, maxlength, pattern, disabled) %} -
- -
+{% macro line_text_section(id, form_action, form_name, section_title, contents, below_text, placeholder_text, button_text, show_emojis, minlength, maxlength, pattern, disabled, extra_title) %} +
+ +
+ {% if extra_title %} +

{{extra_title}}

+ {% endif %}
diff --git a/migrations/20240303-add-twitter-fieldsql.sql b/migrations/20240303-add-twitter-fieldsql.sql new file mode 100644 index 000000000..8f4111241 --- /dev/null +++ b/migrations/20240303-add-twitter-fieldsql.sql @@ -0,0 +1,2 @@ +alter table users drop column nitter; +alter table users add column twitter varchar(50) not null default 'twitter.com'; diff --git a/schema.sql b/schema.sql index cd702b8a3..6c36adaa2 100644 --- a/schema.sql +++ b/schema.sql @@ -179,7 +179,6 @@ CREATE TABLE public.users ( extra_username character varying(30), grinch boolean NOT NULL, last_viewed_modmail_notifs integer NOT NULL, - nitter boolean DEFAULT false NOT NULL, hole_creation_notifs boolean NOT NULL, group_creation_notifs boolean NOT NULL, effortpost_notifs boolean NOT NULL, @@ -3133,4 +3132,3 @@ ALTER TABLE ONLY public.comments -- -- PostgreSQL database dump complete -- -