mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-25 20:31:26 -08:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
commit
7848902ee9
11 changed files with 39 additions and 37 deletions
|
@ -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>
|
<div id="initialise-database-and-setup-admin-account"></div>
|
||||||
|
|
||||||
## Initialise database, and set up admin account
|
## Initialise database, and set up admin account
|
||||||
|
`export FLASK_APP=pyfedi.py`
|
||||||
|
|
||||||
|
`flask db upgrade`
|
||||||
|
|
||||||
`flask init-db`
|
`flask init-db`
|
||||||
|
|
||||||
(choose a new username, email address, and password for your PyFedi admin account)
|
(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>
|
<div id="run-the-app"></div>
|
||||||
|
|
||||||
## Run the app
|
## Run the app
|
||||||
|
|
|
@ -892,12 +892,15 @@ def refresh_instance_profile_task(instance_id: int):
|
||||||
except requests.exceptions.JSONDecodeError as ex:
|
except requests.exceptions.JSONDecodeError as ex:
|
||||||
instance_json = {}
|
instance_json = {}
|
||||||
if 'type' in instance_json and instance_json['type'] == 'Application':
|
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':
|
if instance_json['name'].lower() == 'kbin':
|
||||||
software = 'Kbin'
|
software = 'Kbin'
|
||||||
elif instance_json['name'].lower() == 'mbin':
|
elif instance_json['name'].lower() == 'mbin':
|
||||||
software = 'Mbin'
|
software = 'Mbin'
|
||||||
elif instance_json['name'].lower() == 'piefed':
|
elif instance_json['name'].lower() == 'piefed':
|
||||||
software = 'PieFed'
|
software = 'PieFed'
|
||||||
|
elif instance_json['name'].lower() == 'system account':
|
||||||
|
software = 'Friendica'
|
||||||
else:
|
else:
|
||||||
software = 'Lemmy'
|
software = 'Lemmy'
|
||||||
instance.inbox = instance_json['inbox']
|
instance.inbox = instance_json['inbox']
|
||||||
|
|
19
app/cli.py
19
app/cli.py
|
@ -76,15 +76,13 @@ def register(app):
|
||||||
db.configure_mappers()
|
db.configure_mappers()
|
||||||
db.create_all()
|
db.create_all()
|
||||||
private_key, public_key = RsaKeys.generate_keypair()
|
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(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_nsfw', value=json.dumps(False)))
|
||||||
db.session.add(Settings(name='allow_nsfl', 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_dislike', value=json.dumps(True)))
|
||||||
db.session.add(Settings(name='allow_local_image_posts', 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='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)))
|
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',
|
banned_instances = ['anonib.al','lemmygrad.ml', 'gab.com', 'rqd2.net', 'exploding-heads.com', 'hexbear.net',
|
||||||
'threads.net', 'noauthority.social', 'pieville.net', 'links.hackliberty.org',
|
'threads.net', 'noauthority.social', 'pieville.net', 'links.hackliberty.org',
|
||||||
|
@ -95,21 +93,6 @@ def register(app):
|
||||||
db.session.add(BannedInstances(domain=bi))
|
db.session.add(BannedInstances(domain=bi))
|
||||||
print("Added banned instance", 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
|
# Load initial domain block list
|
||||||
block_list = retrieve_block_list()
|
block_list = retrieve_block_list()
|
||||||
if block_list:
|
if block_list:
|
||||||
|
|
|
@ -136,6 +136,7 @@ class CreatePostForm(FlaskForm):
|
||||||
current_user.reputation -= 1
|
current_user.reputation -= 1
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return False
|
return False
|
||||||
|
if self.communities:
|
||||||
community = Community.query.get(self.communities.data)
|
community = Community.query.get(self.communities.data)
|
||||||
if community.is_local() and g.site.allow_local_image_posts is False:
|
if community.is_local() and g.site.allow_local_image_posts is False:
|
||||||
self.communities.errors.append(_('Images cannot be posted to local communities.'))
|
self.communities.errors.append(_('Images cannot be posted to local communities.'))
|
||||||
|
|
|
@ -9,7 +9,7 @@ from sqlalchemy import or_, desc
|
||||||
|
|
||||||
from app import db, constants, cache
|
from app import db, constants, cache
|
||||||
from app.activitypub.signature import RsaKeys, post_request
|
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.chat.util import send_message
|
||||||
from app.community.forms import SearchRemoteCommunity, CreatePostForm, ReportCommunityForm, \
|
from app.community.forms import SearchRemoteCommunity, CreatePostForm, ReportCommunityForm, \
|
||||||
DeleteCommunityForm, AddCommunityForm, EditCommunityForm, AddModeratorForm, BanUserCommunityForm
|
DeleteCommunityForm, AddCommunityForm, EditCommunityForm, AddModeratorForm, BanUserCommunityForm
|
||||||
|
@ -465,6 +465,8 @@ def add_post(actor):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}"
|
post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}"
|
||||||
db.session.commit()
|
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)
|
notify_about_post(post)
|
||||||
|
|
||||||
|
|
|
@ -210,13 +210,13 @@ def save_post(form, post: Post):
|
||||||
remove_old_file(post.image_id)
|
remove_old_file(post.image_id)
|
||||||
post.image_id = None
|
post.image_id = None
|
||||||
|
|
||||||
unused, file_extension = os.path.splitext(form.link_url.data) # do not use _ here instead of 'unused'
|
unused, file_extension = os.path.splitext(form.link_url.data)
|
||||||
# this url is a link to an image - generate a thumbnail of it
|
# this url is a link to an image - turn it into a image post
|
||||||
if file_extension.lower() in allowed_extensions:
|
if file_extension.lower() in allowed_extensions:
|
||||||
file = url_to_thumbnail_file(form.link_url.data)
|
file = File(source_url=form.link_url.data)
|
||||||
if file:
|
|
||||||
post.image = file
|
post.image = file
|
||||||
db.session.add(file)
|
db.session.add(file)
|
||||||
|
post.type = POST_TYPE_IMAGE
|
||||||
else:
|
else:
|
||||||
# check opengraph tags on the page and make a thumbnail if an image is available in the og:image meta tag
|
# 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)
|
opengraph = opengraph_parse(form.link_url.data)
|
||||||
|
@ -270,13 +270,13 @@ def save_post(form, post: Post):
|
||||||
img = ImageOps.exif_transpose(img)
|
img = ImageOps.exif_transpose(img)
|
||||||
img_width = img.width
|
img_width = img.width
|
||||||
img_height = img.height
|
img_height = img.height
|
||||||
if img.width > 2000 or img.height > 2000:
|
if img.width > 512 or img.height > 512:
|
||||||
img.thumbnail((2000, 2000))
|
img.thumbnail((512, 512))
|
||||||
img.save(final_place)
|
img.save(final_place)
|
||||||
img_width = img.width
|
img_width = img.width
|
||||||
img_height = img.height
|
img_height = img.height
|
||||||
# save a second, smaller, version as a thumbnail
|
# 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)
|
img.save(final_place_thumbnail, format="WebP", quality=93)
|
||||||
thumbnail_width = img.width
|
thumbnail_width = img.width
|
||||||
thumbnail_height = img.height
|
thumbnail_height = img.height
|
||||||
|
|
|
@ -343,8 +343,8 @@ def activitypub_application():
|
||||||
'@context': default_context(),
|
'@context': default_context(),
|
||||||
'type': 'Application',
|
'type': 'Application',
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/",
|
'id': f"https://{current_app.config['SERVER_NAME']}/",
|
||||||
'name': g.site.name,
|
'name': 'PieFed',
|
||||||
'summary': g.site.description,
|
'summary': g.site.name + ' - ' + g.site.description,
|
||||||
'published': ap_datetime(g.site.created_at),
|
'published': ap_datetime(g.site.created_at),
|
||||||
'updated': ap_datetime(g.site.updated),
|
'updated': ap_datetime(g.site.updated),
|
||||||
'inbox': f"https://{current_app.config['SERVER_NAME']}/site_inbox",
|
'inbox': f"https://{current_app.config['SERVER_NAME']}/site_inbox",
|
||||||
|
|
|
@ -56,7 +56,9 @@
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -105,4 +105,5 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{{ _('There are no communities yet.') }}</p>
|
<p>{{ _('There are no communities yet.') }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<p><a href="/topics" class="btn btn-primary">{{ _('Browse topics') }}</a></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -54,7 +54,9 @@
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
urllib3==1.26.11
|
||||||
Flask==2.3.2
|
Flask==2.3.2
|
||||||
python-dotenv==1.0.0
|
python-dotenv==1.0.0
|
||||||
flask-wtf==1.1.1
|
flask-wtf==1.1.1
|
||||||
|
@ -30,4 +31,3 @@ redis==5.0.1
|
||||||
Werkzeug==2.3.3
|
Werkzeug==2.3.3
|
||||||
pytesseract==0.3.10
|
pytesseract==0.3.10
|
||||||
sentry-sdk==1.40.6
|
sentry-sdk==1.40.6
|
||||||
urllib3==1.26.1
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue