diff --git a/app/cli.py b/app/cli.py index 6d3ec750..fd940aaa 100644 --- a/app/cli.py +++ b/app/cli.py @@ -12,7 +12,7 @@ from app.activitypub.signature import RsaKeys from app.auth.util import random_token from app.email import send_verification_email from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain, ActivityPubLog, \ - utcnow, Site, Instance + utcnow, Site, Instance, File from app.utils import file_get_contents, retrieve_block_list @@ -164,6 +164,22 @@ def register(app): file.file_path = '' db.session.commit() + def list_files(directory): + for root, dirs, files in os.walk(directory): + for file in files: + yield os.path.join(root, file) + + @app.cli.command("findorphanfiles") + def findorphanfiles(): + with app.app_context(): + for file_path in list_files('app/static/media/users'): + + if 'thumbnail' in file_path: + f = File.query.filter(File.thumbnail_path == file_path).first() + else: + f = File.query.filter(File.file_path == file_path).first() + if f is None: + print(file_path) def parse_communities(interests_source, segment): lines = interests_source.split("\n") diff --git a/app/main/routes.py b/app/main/routes.py index 28e48f6e..a4d8607c 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -20,7 +20,7 @@ from sqlalchemy_searchable import search from app.utils import render_template, get_setting, gibberish, request_etag_matches, return_304, blocked_domains, \ ap_datetime, ip_address, retrieve_block_list, shorten_string, markdown_to_text, user_filters_home, \ joined_communities, moderating_communities, parse_page, theme_list -from app.models import Community, CommunityMember, Post, Site, User, utcnow, Domain, Topic +from app.models import Community, CommunityMember, Post, Site, User, utcnow, Domain, Topic, File from PIL import Image import pytesseract @@ -247,8 +247,16 @@ def keyboard_shortcuts(): return render_template('keyboard_shortcuts.html') +def list_files(directory): + for root, dirs, files in os.walk(directory): + for file in files: + yield os.path.join(root, file) + + @bp.route('/test') def test(): + + return '' retval = '' for user in User.query.all(): filesize = user.filesize()