updated to upload pictures

This commit is contained in:
2025-05-19 22:05:13 +03:00
parent 7eb8f088f4
commit aab05e6117
6 changed files with 63 additions and 44 deletions

30
app.py
View File

@@ -23,6 +23,9 @@ app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'Ana_Are_Multe_Mere-Si_Nu_Are
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.instance_path, 'dashboard.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Set maximum content length to 1GB
app.config['MAX_CONTENT_LENGTH'] = 2048 * 2048 * 2048 # 1GB, adjust as needed
# Ensure the instance folder exists
os.makedirs(app.instance_path, exist_ok=True)
@@ -56,9 +59,22 @@ def admin_required(f):
return f(*args, **kwargs)
return decorated_function
def convert_ppt_to_pdf(input_file, output_file):
command = ['libreoffice', '--headless', '--convert-to', 'pdf', '--outdir', os.path.dirname(output_file), input_file]
subprocess.run(command, check=True)
def add_image_to_playlist(file, filename, duration, target_type, target_id):
"""
Save the image file and add it to the playlist database.
"""
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
# Only save if file does not already exist (prevents double-saving)
if not os.path.exists(file_path):
file.save(file_path)
if target_type == 'group':
group = Group.query.get_or_404(target_id)
for player in group.players:
new_content = Content(file_name=filename, duration=duration, player_id=player.id)
db.session.add(new_content)
elif target_type == 'player':
new_content = Content(file_name=filename, duration=duration, player_id=target_id)
db.session.add(new_content)
def convert_ppt_to_images(input_file, output_folder):
"""
@@ -174,7 +190,8 @@ def upload_content():
filename = secure_filename(file.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(file_path)
filename = secure_filename(file.filename)
file_ext = os.path.splitext(filename)[1].lower()
# Handle PDF files
if media_type == 'pdf':
print(f"Processing PDF file: {file_path}")
@@ -193,7 +210,10 @@ def upload_content():
if image_file.startswith(os.path.splitext(filename)[0]) and image_file.endswith('.jpg'):
new_content = Content(file_name=image_file, duration=duration, player_id=target_id)
db.session.add(new_content)
# --- Add this block for images ---
elif media_type in ['jpg', 'jpeg', 'png'] or (media_type == 'image' and file_ext in ['.jpg', '.jpeg', '.png']):
add_image_to_playlist(file, filename, duration, target_type, target_id)
# Handle video files
elif media_type == 'video':
# Add the video file to the playlist