Enhance upload functionality: add channel selection, display duration, and fix media file visibility

This commit is contained in:
ske087
2025-08-19 13:08:09 +03:00
parent 4ea27fa76c
commit 0974b33785
2 changed files with 66 additions and 18 deletions

View File

@@ -199,13 +199,19 @@ def admin():
@app.route('/user')
@login_required
def user_dashboard():
# Get user's files
user_files = MediaFile.query.filter_by(uploaded_by=current_user.id, is_active=True).order_by(MediaFile.upload_date.desc()).all()
# Get all active files (for signage systems, users should see all available media)
user_files = MediaFile.query.filter_by(is_active=True).order_by(MediaFile.upload_date.desc()).all()
# Get all active channels
channels = StreamingChannel.query.filter_by(is_active=True).order_by(StreamingChannel.name).all()
# Get all users for display in file info
users = User.query.all()
# Get user's activity
user_activity = ActivityLog.query.filter_by(user_id=current_user.id).order_by(ActivityLog.timestamp.desc()).limit(10).all()
return render_template('user.html', user_files=user_files, user_activity=user_activity)
return render_template('user.html', user_files=user_files, user_activity=user_activity, channels=channels, users=users)
# File Management Routes
@app.route('/upload', methods=['POST'])
@@ -243,8 +249,39 @@ def upload_file():
db.session.add(media_file)
db.session.commit()
# If channel is selected, add to channel
channel_id = request.form.get('channel_id')
display_duration = request.form.get('display_duration', 10)
if channel_id and channel_id.strip():
try:
channel_id = int(channel_id)
channel = StreamingChannel.query.get(channel_id)
if channel and channel.is_active:
# Get next order number for this channel
max_order = db.session.query(db.func.max(ChannelContent.order)).filter_by(channel_id=channel_id).scalar() or 0
# Add to channel
channel_content = ChannelContent(
channel_id=channel_id,
media_file_id=media_file.id,
duration=int(display_duration),
order=max_order + 1
)
db.session.add(channel_content)
db.session.commit()
log_activity('Content added to channel', f'Added {file.filename} to channel {channel.name}')
flash(f'File "{file.filename}" uploaded and added to channel "{channel.name}"!', 'success')
else:
flash(f'File "{file.filename}" uploaded but channel not found!', 'warning')
except (ValueError, TypeError):
flash(f'File "{file.filename}" uploaded but invalid channel selected!', 'warning')
else:
flash(f'File "{file.filename}" uploaded successfully!', 'success')
log_activity('File uploaded', f'Uploaded: {file.filename}')
flash(f'File "{file.filename}" uploaded successfully!', 'success')
else:
flash('Invalid file type. Please upload images, videos, PDFs, or JSON files.', 'error')

View File

@@ -74,18 +74,29 @@
</div>
<div class="card-body">
<form method="post" enctype="multipart/form-data" action="/upload" class="row g-3">
<div class="col-md-8">
<div class="input-group">
<input type="file" class="form-control" name="file" accept=".png,.jpg,.jpeg,.gif,.mp4,.avi,.mov,.pdf" required>
<button type="submit" class="btn btn-success">
<i class="bi bi-upload"></i> Upload
</button>
</div>
<div class="col-md-12">
<label for="file" class="form-label">Select Media File</label>
<input type="file" class="form-control" name="file" id="file" accept=".png,.jpg,.jpeg,.gif,.mp4,.avi,.mov,.pdf" required>
<small class="text-muted">Supported: Images, Videos, PDFs</small>
</div>
<div class="col-md-4">
<small class="text-muted">
Supported: Images, Videos, PDFs
</small>
<div class="col-md-6">
<label for="channel_id" class="form-label">Add to Channel (Optional)</label>
<select class="form-select" name="channel_id" id="channel_id">
<option value="">Select Channel...</option>
{% for channel in channels %}
<option value="{{ channel.id }}">{{ channel.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-md-6">
<label for="display_duration" class="form-label">Display Duration (seconds)</label>
<input type="number" class="form-control" name="display_duration" id="display_duration" min="1" max="300" value="10" placeholder="10">
<small class="text-muted">How long to display this media (1-300 seconds)</small>
</div>
<div class="col-12">
<button type="submit" class="btn btn-success">
<i class="bi bi-upload"></i> Upload Media
</button>
</div>
</form>
</div>
@@ -99,12 +110,12 @@
<div class="card">
<div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
<h5 class="mb-0"><i class="bi bi-file-earmark-image"></i> All Media Files</h5>
<span class="badge bg-light text-dark">{{ files|length }} files</span>
<span class="badge bg-light text-dark">{{ user_files|length }} files</span>
</div>
<div class="card-body">
{% if files %}
{% if user_files %}
<div class="media-grid">
{% for file in files %}
{% for file in user_files %}
<div class="card media-card">
<div class="file-preview">
{% if file.file_type in ['jpg', 'jpeg', 'png', 'gif'] %}