From 6d2b722f0e572bc9ef47c204b61a7acba9267387 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 10:17:23 +1300 Subject: [PATCH 1/8] move urllib to top this needs to already be present before flask is installed, so it is the correct version when boto3 is installed. phew --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e547eee5..cd6d90a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +urllib3==1.26.1 Flask==2.3.2 python-dotenv==1.0.0 flask-wtf==1.1.1 @@ -30,4 +31,3 @@ redis==5.0.1 Werkzeug==2.3.3 pytesseract==0.3.10 sentry-sdk==1.40.6 -urllib3==1.26.1 From ad62df7c10c8aadd8e96d608ffb326129d5e6f0c Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:00:16 +1300 Subject: [PATCH 2/8] improve consistency of image post handling when a link post is created and the link is to an image, create an image post instead --- app/community/routes.py | 4 +++- app/community/util.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index 21f5a69a..37049fcb 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -9,7 +9,7 @@ from sqlalchemy import or_, desc from app import db, constants, cache from app.activitypub.signature import RsaKeys, post_request -from app.activitypub.util import default_context, notify_about_post, find_actor_or_create +from app.activitypub.util import default_context, notify_about_post, find_actor_or_create, make_image_sizes from app.chat.util import send_message from app.community.forms import SearchRemoteCommunity, CreatePostForm, ReportCommunityForm, \ DeleteCommunityForm, AddCommunityForm, EditCommunityForm, AddModeratorForm, BanUserCommunityForm @@ -465,6 +465,8 @@ def add_post(actor): db.session.commit() post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}" db.session.commit() + if post.image_id and post.image.file_path is None: + make_image_sizes(post.image_id, 150, 512, 'posts') # the 512 sized image is for masonry view notify_about_post(post) diff --git a/app/community/util.py b/app/community/util.py index 44642fb0..b97b7661 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -210,13 +210,13 @@ def save_post(form, post: Post): remove_old_file(post.image_id) post.image_id = None - unused, file_extension = os.path.splitext(form.link_url.data) # do not use _ here instead of 'unused' - # this url is a link to an image - generate a thumbnail of it + unused, file_extension = os.path.splitext(form.link_url.data) + # this url is a link to an image - turn it into a image post if file_extension.lower() in allowed_extensions: - file = url_to_thumbnail_file(form.link_url.data) - if file: - post.image = file - db.session.add(file) + file = File(source_url=form.link_url.data) + post.image = file + db.session.add(file) + post.type = POST_TYPE_IMAGE else: # check opengraph tags on the page and make a thumbnail if an image is available in the og:image meta tag opengraph = opengraph_parse(form.link_url.data) @@ -270,13 +270,13 @@ def save_post(form, post: Post): img = ImageOps.exif_transpose(img) img_width = img.width img_height = img.height - if img.width > 2000 or img.height > 2000: - img.thumbnail((2000, 2000)) + if img.width > 512 or img.height > 512: + img.thumbnail((512, 512)) img.save(final_place) img_width = img.width img_height = img.height # save a second, smaller, version as a thumbnail - img.thumbnail((256, 256)) + img.thumbnail((150, 150)) img.save(final_place_thumbnail, format="WebP", quality=93) thumbnail_width = img.width thumbnail_height = img.height From bb3798428ef058bb2fa7fe375b6e352006188450 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 13:44:31 +1300 Subject: [PATCH 3/8] browse topics button --- app/templates/index.html | 4 +++- app/templates/list_communities.html | 1 + app/templates/search/results.html | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/templates/index.html b/app/templates/index.html index 3d195128..3e4a3ce7 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -56,7 +56,9 @@ {% endfor %} -
{{ _('Explore communities') }}
+{{ _('Explore communities') }} + {{ _('Browse topics') }} +
diff --git a/app/templates/list_communities.html b/app/templates/list_communities.html index 0bc82a4e..d3e86bc1 100644 --- a/app/templates/list_communities.html +++ b/app/templates/list_communities.html @@ -105,4 +105,5 @@ {% else %}{{ _('There are no communities yet.') }}
{% endif %} + {% endblock %} diff --git a/app/templates/search/results.html b/app/templates/search/results.html index 6ce6dd07..5b7f4c92 100644 --- a/app/templates/search/results.html +++ b/app/templates/search/results.html @@ -54,7 +54,9 @@ {% endfor %} - + From c5055cd09f99296af35391cfca5b1c93741d65a0 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 15:35:45 +1300 Subject: [PATCH 4/8] detect friendica --- app/activitypub/util.py | 3 +++ app/main/routes.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 239dedcf..3ea9040c 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -892,12 +892,15 @@ def refresh_instance_profile_task(instance_id: int): except requests.exceptions.JSONDecodeError as ex: instance_json = {} if 'type' in instance_json and instance_json['type'] == 'Application': + # 'name' is unreliable as the admin can change it to anything. todo: find better way if instance_json['name'].lower() == 'kbin': software = 'Kbin' elif instance_json['name'].lower() == 'mbin': software = 'Mbin' elif instance_json['name'].lower() == 'piefed': software = 'PieFed' + elif instance_json['name'].lower() == 'system account': + software = 'Friendica' else: software = 'Lemmy' instance.inbox = instance_json['inbox'] diff --git a/app/main/routes.py b/app/main/routes.py index 68eca138..cc2a69aa 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -343,8 +343,8 @@ def activitypub_application(): '@context': default_context(), 'type': 'Application', 'id': f"https://{current_app.config['SERVER_NAME']}/", - 'name': g.site.name, - 'summary': g.site.description, + 'name': 'PieFed', + 'summary': g.site.name + ' - ' + g.site.description, 'published': ap_datetime(g.site.created_at), 'updated': ap_datetime(g.site.updated), 'inbox': f"https://{current_app.config['SERVER_NAME']}/site_inbox", From a860ce45cd61b490130e16518a622f2d580a190c Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 19:16:02 +1300 Subject: [PATCH 5/8] urllib3 version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cd6d90a0..a1b4ae00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -urllib3==1.26.1 +urllib3==1.26.11 Flask==2.3.2 python-dotenv==1.0.0 flask-wtf==1.1.1 From 39ed5d501b4dc14718b45c5e357ad0bffaf7e617 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 19:47:51 +1300 Subject: [PATCH 6/8] update documentation to avoid future migration issues fixes #113 --- INSTALL.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 8d016d19..2cd24ac0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -120,9 +120,17 @@ If it does not work check the log file at logs/pyfedi.log for clues. ## Initialise database, and set up admin account -`flask init-db` +`export FLASK_APP=pyfedi.py` + +`flask db upgrade` + +`flask init-db` + (choose a new username, email address, and password for your PyFedi admin account) +If you see an error message "ModuleNotFoundError: No module named 'flask_babel'" then use `venv/bin/flask` instead of `flask` +for all flask commands. + ## Run the app From c0f526d70f8c4555a612de710a72947bf059d02e Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 19:48:02 +1300 Subject: [PATCH 7/8] remove unused interests --- app/cli.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/app/cli.py b/app/cli.py index 70a4a00c..7d430f98 100644 --- a/app/cli.py +++ b/app/cli.py @@ -76,15 +76,13 @@ def register(app): db.configure_mappers() db.create_all() private_key, public_key = RsaKeys.generate_keypair() - db.session.add(Site(name="PieFed", description='', public_key=public_key, private_key=private_key)) + db.session.add(Site(name="PieFed", description='Explore Anything, Discuss Everything.', public_key=public_key, private_key=private_key)) db.session.add(Instance(domain=app.config['SERVER_NAME'], software='PieFed')) # Instance 1 is always the local instance db.session.add(Settings(name='allow_nsfw', value=json.dumps(False))) db.session.add(Settings(name='allow_nsfl', value=json.dumps(False))) db.session.add(Settings(name='allow_dislike', value=json.dumps(True))) db.session.add(Settings(name='allow_local_image_posts', value=json.dumps(True))) db.session.add(Settings(name='allow_remote_image_posts', value=json.dumps(True))) - 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))) banned_instances = ['anonib.al','lemmygrad.ml', 'gab.com', 'rqd2.net', 'exploding-heads.com', 'hexbear.net', 'threads.net', 'noauthority.social', 'pieville.net', 'links.hackliberty.org', @@ -95,21 +93,6 @@ def register(app): 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'))) - db.session.add(Interest(name='📰 News & Politics', communities=parse_communities(interests, 'news & politics'))) - db.session.add(Interest(name='🎮 Gaming', communities=parse_communities(interests, 'gaming'))) - db.session.add(Interest(name='🤓 Linux', communities=parse_communities(interests, 'linux'))) - db.session.add(Interest(name='♻️ Environment', communities=parse_communities(interests, 'environment'))) - db.session.add(Interest(name='🏳🌈 LGBTQ+', communities=parse_communities(interests, 'lgbtq'))) - db.session.add(Interest(name='🛠 Programming', communities=parse_communities(interests, 'programming'))) - db.session.add(Interest(name='🖥️ Tech', communities=parse_communities(interests, 'tech'))) - db.session.add(Interest(name='🤗 Mental Health', communities=parse_communities(interests, 'mental health'))) - db.session.add(Interest(name='💊 Health', communities=parse_communities(interests, 'health'))) - # Load initial domain block list block_list = retrieve_block_list() if block_list: From 5c5c28a4a352b453e2d262a1c33110ed82f47050 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 24 Mar 2024 20:58:25 +1300 Subject: [PATCH 8/8] bug when editing post --- app/community/forms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/community/forms.py b/app/community/forms.py index 5f87147f..ca80ba6c 100644 --- a/app/community/forms.py +++ b/app/community/forms.py @@ -136,9 +136,10 @@ class CreatePostForm(FlaskForm): current_user.reputation -= 1 db.session.commit() return False - community = Community.query.get(self.communities.data) - if community.is_local() and g.site.allow_local_image_posts is False: - self.communities.errors.append(_('Images cannot be posted to local communities.')) + if self.communities: + community = Community.query.get(self.communities.data) + if community.is_local() and g.site.allow_local_image_posts is False: + self.communities.errors.append(_('Images cannot be posted to local communities.')) elif self.post_type.data == 'poll': self.discussion_title.errors.append(_('Poll not implemented yet.')) return False