mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 11:51:27 -08:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
commit
7848902ee9
11 changed files with 39 additions and 37 deletions
10
INSTALL.md
10
INSTALL.md
|
@ -120,9 +120,17 @@ If it does not work check the log file at logs/pyfedi.log for clues.
|
|||
<div id="initialise-database-and-setup-admin-account"></div>
|
||||
|
||||
## 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.
|
||||
|
||||
<div id="run-the-app"></div>
|
||||
|
||||
## Run the app
|
||||
|
|
|
@ -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']
|
||||
|
|
19
app/cli.py
19
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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -56,7 +56,9 @@
|
|||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<p class="mt-4"><a class="btn btn-primary" href="/communities">{{ _('Explore communities') }}</a></p>
|
||||
<p class="mt-4"><a class="btn btn-primary" href="/communities">{{ _('Explore communities') }}</a>
|
||||
<a class="btn btn-primary" href="/topics">{{ _('Browse topics') }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -105,4 +105,5 @@
|
|||
{% else %}
|
||||
<p>{{ _('There are no communities yet.') }}</p>
|
||||
{% endif %}
|
||||
<p><a href="/topics" class="btn btn-primary">{{ _('Browse topics') }}</a></p>
|
||||
{% endblock %}
|
||||
|
|
|
@ -54,7 +54,9 @@
|
|||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<p class="mt-4"><a class="btn btn-primary" href="/communities">{{ _('Explore communities') }}</a></p>
|
||||
<p class="mt-4"><a class="btn btn-primary" href="/communities">{{ _('Explore communities') }}</a>
|
||||
<a class="btn btn-primary" href="/topics">{{ _('Browse topics') }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
urllib3==1.26.11
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue