Split routes into multiple files (#2)

* split into files

* attempted path fix

* perms fix

* added missed functions

* fixed circular dependancy

* I hate splitting

* env fix

* path fix
This commit is contained in:
2025-02-18 01:27:40 +00:00
committed by GitHub
parent 4c7853fb3f
commit c1f26094de
24 changed files with 584 additions and 470 deletions
+27
View File
@@ -0,0 +1,27 @@
from flask import current_app
from datetime import datetime, timedelta
import os
import shutil
def delete_inactive_sites():
from .models import db, Site # lazy import to avoid circular dependency
with current_app.app_context():
cutoff = datetime.utcnow() - timedelta(days=30)
sites = Site.query.filter(Site.last_accessed < cutoff).all()
for site in sites:
site_dir = os.path.join(
current_app.config["UPLOAD_FOLDER"], str(site.user_id), str(site.id)
)
if os.path.exists(site_dir):
shutil.rmtree(site_dir)
db.session.delete(site)
db.session.commit()
def list_files(directory):
try:
return os.listdir(directory)
except FileNotFoundError:
return []