updated for beter media management

This commit is contained in:
DigiServer Developer
2025-11-22 18:24:40 +02:00
parent f4df930d82
commit b73e10cde7
5 changed files with 735 additions and 70 deletions

View File

@@ -409,7 +409,7 @@ def delete_leftover_images():
try:
# Find all leftover image content
leftover_images = db.session.query(Content).filter(
Content.media_type == 'image',
Content.content_type == 'image',
~Content.id.in_(
db.session.query(playlist_content.c.content_id)
)
@@ -421,8 +421,8 @@ def delete_leftover_images():
for content in leftover_images:
try:
# Delete physical file
if content.file_path:
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], content.file_path)
if content.filename:
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], content.filename)
if os.path.exists(file_path):
os.remove(file_path)
@@ -430,7 +430,7 @@ def delete_leftover_images():
db.session.delete(content)
deleted_count += 1
except Exception as e:
errors.append(f"Error deleting {content.file_path}: {str(e)}")
errors.append(f"Error deleting {content.filename}: {str(e)}")
db.session.commit()
@@ -455,7 +455,7 @@ def delete_leftover_videos():
try:
# Find all leftover video content
leftover_videos = db.session.query(Content).filter(
Content.media_type == 'video',
Content.content_type == 'video',
~Content.id.in_(
db.session.query(playlist_content.c.content_id)
)
@@ -467,8 +467,8 @@ def delete_leftover_videos():
for content in leftover_videos:
try:
# Delete physical file
if content.file_path:
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], content.file_path)
if content.filename:
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], content.filename)
if os.path.exists(file_path):
os.remove(file_path)
@@ -476,7 +476,7 @@ def delete_leftover_videos():
db.session.delete(content)
deleted_count += 1
except Exception as e:
errors.append(f"Error deleting {content.file_path}: {str(e)}")
errors.append(f"Error deleting {content.filename}: {str(e)}")
db.session.commit()
@@ -500,8 +500,8 @@ def delete_single_leftover(content_id):
content = Content.query.get_or_404(content_id)
# Delete physical file
if content.file_path:
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], content.file_path)
if content.filename:
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], content.filename)
if os.path.exists(file_path):
os.remove(file_path)
@@ -509,7 +509,7 @@ def delete_single_leftover(content_id):
db.session.delete(content)
db.session.commit()
flash(f'Successfully deleted {content.file_path}', 'success')
flash(f'Successfully deleted {content.filename}', 'success')
except Exception as e:
db.session.rollback()