This commit is contained in:
rimu 2024-02-10 11:42:18 +13:00
parent 7d99d5ea9d
commit 375600b382
3 changed files with 33 additions and 2 deletions

View file

@ -350,7 +350,7 @@ def actor_json_to_model(activity_json, address, server):
created=activity_json['published'] if 'published' in activity_json else utcnow(),
ap_id=f"{address}@{server}",
ap_public_url=activity_json['id'],
ap_profile_id=activity_json['id'],
ap_profile_id=activity_json['id'].lower(),
ap_inbox_url=activity_json['endpoints']['sharedInbox'],
ap_followers_url=activity_json['followers'] if 'followers' in activity_json else None,
ap_preferred_username=activity_json['preferredUsername'],
@ -404,7 +404,7 @@ def actor_json_to_model(activity_json, address, server):
last_active=activity_json['updated'] if 'updated' in activity_json else utcnow(),
ap_id=f"{address[1:]}@{server}" if address.startswith('!') else f"{address}@{server}",
ap_public_url=activity_json['id'],
ap_profile_id=activity_json['id'],
ap_profile_id=activity_json['id'].lower(),
ap_followers_url=activity_json['followers'],
ap_inbox_url=activity_json['endpoints']['sharedInbox'],
ap_moderators_url=mods_url,

View file

@ -249,6 +249,15 @@ def keyboard_shortcuts():
@bp.route('/test')
def test():
retval = ''
for user in User.query.all():
filesize = user.filesize()
num_content = user.num_content()
if filesize > 0 and num_content > 0:
retval += f'{user.id},"{user.ap_id}",{filesize},{num_content}\n'
return retval
return ''
deleted = 0
for user in User.query.all():
if not user.is_local():

View file

@ -118,6 +118,14 @@ class File(db.Model):
if self.thumbnail_path and os.path.isfile(self.thumbnail_path):
os.unlink(self.thumbnail_path)
def filesize(self):
size = 0
if self.file_path and os.path.exists(self.file_path):
size += os.path.getsize(self.file_path)
if self.thumbnail_path and os.path.exists(self.thumbnail_path):
size += os.path.getsize(self.thumbnail_path)
return size
class Topic(db.Model):
id = db.Column(db.Integer, primary_key=True)
@ -445,6 +453,20 @@ class User(UserMixin, db.Model):
return self.cover.source_url
return ''
def filesize(self):
size = 0
if self.avatar_id:
size += self.avatar.filesize()
if self.cover_id:
size += self.cover.filesize()
return size
def num_content(self):
content = 0
content += db.session.execute(text('SELECT COUNT(id) as c FROM "post" WHERE user_id = ' + str(self.id))).scalar()
content += db.session.execute(text('SELECT COUNT(id) as c FROM "post_reply" WHERE user_id = ' + str(self.id))).scalar()
return content
def is_local(self):
return self.ap_id is None or self.ap_profile_id.startswith('https://' + current_app.config['SERVER_NAME'])