keep activitypub log small

This commit is contained in:
rimu 2023-11-26 23:21:04 +13:00
parent 7395494477
commit e2b86f3caf
3 changed files with 22 additions and 2 deletions

View file

@ -1,3 +1,5 @@
from datetime import datetime, timedelta
from flask import request, flash from flask import request, flash
from flask_login import login_required, current_user from flask_login import login_required, current_user
from flask_babel import _ from flask_babel import _
@ -46,5 +48,9 @@ def admin_home():
@login_required @login_required
@permission_required('change instance settings') @permission_required('change instance settings')
def admin_activities(): def admin_activities():
db.session.query(ActivityPubLog).filter(
ActivityPubLog.created_at < datetime.utcnow() - timedelta(days=3)).delete()
db.session.commit()
return render_template('admin/activities.html', title=_('ActivityPub Log'), return render_template('admin/activities.html', title=_('ActivityPub Log'),
activities=ActivityPubLog.query.order_by(desc(ActivityPubLog.created_at)).all()) activities=ActivityPubLog.query.order_by(desc(ActivityPubLog.created_at)).all())

View file

@ -71,6 +71,7 @@ def register():
flash(_('Sorry, you cannot use that email address'), 'error') flash(_('Sorry, you cannot use that email address'), 'error')
else: else:
verification_token = random_token(16) verification_token = random_token(16)
form.user_name.data = form.user_name.data.strip()
user = User(user_name=form.user_name.data, email=form.real_email.data, user = User(user_name=form.user_name.data, email=form.real_email.data,
verification_token=verification_token) verification_token=verification_token)
user.set_password(form.password.data) user.set_password(form.password.data)
@ -146,8 +147,11 @@ def verify_email(token):
private_key, public_key = RsaKeys.generate_keypair() private_key, public_key = RsaKeys.generate_keypair()
user.private_key = private_key user.private_key = private_key
user.public_key = public_key user.public_key = public_key
user.ap_profile_id = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}"
user.ap_public_url = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}"
user.ap_inbox_url = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}/inbox"
db.session.commit() db.session.commit()
flash(_('Thank you for verifying your email address. You can now post content and vote.')) flash(_('Thank you for verifying your email address.'))
else: else:
flash(_('Email address validation failed.'), 'error') flash(_('Email address validation failed.'), 'error')
return redirect(url_for('main.index')) return redirect(url_for('main.index'))

View file

@ -1,5 +1,7 @@
# if commands in this file are not working (e.g. 'flask translate') make sure you set the FLASK_APP environment variable. # if commands in this file are not working (e.g. 'flask translate') make sure you set the FLASK_APP environment variable.
# e.g. export FLASK_APP=pyfedi.py # e.g. export FLASK_APP=pyfedi.py
from datetime import datetime, timedelta
from flask import json from flask import json
from app import db from app import db
@ -8,7 +10,7 @@ import os
from app.auth.email import send_verification_email from app.auth.email import send_verification_email
from app.auth.util import random_token from app.auth.util import random_token
from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain, ActivityPubLog
from app.utils import file_get_contents, retrieve_block_list from app.utils import file_get_contents, retrieve_block_list
@ -117,6 +119,14 @@ def register(app):
db.session.commit() db.session.commit()
print("Initial setup is finished.") print("Initial setup is finished.")
@app.cli.command('daily-maintenance')
def daily_maintenance():
with app.app_context():
"""Remove activity older than 3 days"""
db.session.query(ActivityPubLog).filter(
ActivityPubLog.created_at < datetime.utcnow() - timedelta(days=3)).delete()
db.session.commit()
def parse_communities(interests_source, segment): def parse_communities(interests_source, segment):
lines = interests_source.split("\n") lines = interests_source.split("\n")