diff --git a/INSTALL.md b/INSTALL.md index 7543924d..1b403806 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -2,7 +2,7 @@ * [Setup Database](#setup-database) * [Install Python Libraries](#install-python-libraries) -* [Install redis-server and git](#install-redis-server-and-git) +* [Install additional requirements](#install-additional-requirements) * [Setup pyfedi](#setup-pyfedi) * [Setup .env file](#setup-env-file) * [Initialise Database and Setup Admin account](#initialise-database-and-setup-admin-account) @@ -49,13 +49,14 @@ For installation environments that use 'apt' as a package manager: `sudo apt install python3-pip python3-venv python3-dev python3-psycopg2` -
+ -## Install redis-server and git +## Install additional requirements For installation environments that use 'apt' as a package manager: `sudo apt install redis-server` -`sudo apt install git` +`sudo apt install git` +`sudo apt install tesseract-ocr` diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index c051ee51..239b416a 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -722,10 +722,12 @@ def process_inbox_request(request_json, activitypublog_id, ip_address): if user and community: join_request = CommunityJoinRequest.query.filter_by(user_id=user.id, community_id=community.id).first() if join_request: - member = CommunityMember(user_id=user.id, community_id=community.id) - db.session.add(member) - community.subscriptions_count += 1 - db.session.commit() + existing_membership = CommunityMember.query.filter_by(user_id=user.id, community_id=community.id).first() + if not existing_membership: + member = CommunityMember(user_id=user.id, community_id=community.id) + db.session.add(member) + community.subscriptions_count += 1 + db.session.commit() activity_log.result = 'success' cache.delete_memoized(community_membership, user, community) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 67be217a..efb6983c 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -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 + shorten_string, reply_already_exists, reply_is_just_link_to_gif_reaction, confidence, remove_tracking_from_link def public_key(): @@ -1227,6 +1227,7 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json post.image = image else: post.type = POST_TYPE_LINK + 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 diff --git a/app/cli.py b/app/cli.py index d37646cc..b093382e 100644 --- a/app/cli.py +++ b/app/cli.py @@ -86,16 +86,13 @@ def register(app): db.session.add(Settings(name='registration_open', value=json.dumps(True))) db.session.add(Settings(name='approve_registrations', value=json.dumps(False))) db.session.add(Settings(name='federation', value=json.dumps(True))) - db.session.add(BannedInstances(domain='lemmygrad.ml')) - db.session.add(BannedInstances(domain='gab.com')) - db.session.add(BannedInstances(domain='rqd2.net')) - db.session.add(BannedInstances(domain='exploding-heads.com')) - db.session.add(BannedInstances(domain='hexbear.net')) - db.session.add(BannedInstances(domain='threads.net')) - db.session.add(BannedInstances(domain='pieville.net')) - db.session.add(BannedInstances(domain='noauthority.social')) - db.session.add(BannedInstances(domain='pieville.net')) - db.session.add(BannedInstances(domain='links.hackliberty.org')) + banned_instances = ['anonib.al','lemmygrad.ml', 'gab.com', 'rqd2.net', 'exploding-heads.com', 'hexbear.net', 'threads.net', 'pieville.net', 'noauthority.social', 'pieville.net', 'links.hackliberty.org'] + for bi in banned_instances: + db.session.add(BannedInstances(domain=bi)) + print("Added banned instance", bi) + + print("Populating DB with instances and interests") + print("See interests.txt") interests = file_get_contents('interests.txt') db.session.add(Interest(name='🕊 Chilling', communities=parse_communities(interests, 'chilling'))) db.session.add(Interest(name='💠Interesting stuff', communities=parse_communities(interests, 'interesting stuff'))) @@ -114,12 +111,14 @@ def register(app): if block_list: for domain in block_list.split('\n'): db.session.add(Domain(name=domain.strip(), banned=True)) + print("Added 'No-QAnon' blocklist, see https://github.com/rimu/no-qanon") # Load peertube domain block list block_list = retrieve_peertube_block_list() if block_list: for domain in block_list.split('\n'): db.session.add(Domain(name=domain.strip(), banned=True)) + print("Added 'Peertube Isolation' blocklist, see https://peertube_isolation.frama.io/") # Initial roles anon_role = Role(name='Anonymous user', weight=0) diff --git a/app/community/forms.py b/app/community/forms.py index b3713012..ee514ad6 100644 --- a/app/community/forms.py +++ b/app/community/forms.py @@ -81,7 +81,7 @@ class CreatePostForm(FlaskForm): return False domain = domain_from_url(self.link_url.data, create=False) if domain and domain.banned: - self.link_url.errors.append(_(f"Links to %s are not allowed.".format(domain.name))) + self.link_url.errors.append(_("Links to %(domain)s are not allowed.", domain=domain.name)) return False elif self.post_type.data == 'image': if self.image_title.data == '': diff --git a/app/community/routes.py b/app/community/routes.py index b77cf25b..70ffdbc0 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -327,14 +327,8 @@ def unsubscribe(actor): 'id': undo_id, 'object': follow } - activity = ActivityPubLog(direction='out', activity_id=undo_id, activity_type='Undo', - activity_json=json.dumps(undo), result='processing') - db.session.add(activity) - db.session.commit() success = post_request(community.ap_inbox_url, undo, current_user.private_key, current_user.profile_id() + '#main-key') - activity.result = 'success' - db.session.commit() if not success: flash('There was a problem while trying to unsubscribe', 'error') diff --git a/app/community/util.py b/app/community/util.py index 6a6d54b9..75132ded 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -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 + 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 = 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 diff --git a/app/models.py b/app/models.py index 0bbdf1da..8d4cc870 100644 --- a/app/models.py +++ b/app/models.py @@ -207,6 +207,8 @@ class File(db.Model): os.unlink(self.file_path) if self.thumbnail_path and os.path.isfile(self.thumbnail_path): os.unlink(self.thumbnail_path) + if self.source_url and not self.source_url.startswith('http') and os.path.isfile(self.source_url): + os.unlink(self.source_url) def filesize(self): size = 0 diff --git a/app/templates/index.html b/app/templates/index.html index 63d3e26a..3d195128 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -42,7 +42,7 @@ --> -