Add ZIP contents preview showing PDFs inside uploaded ZIP files

This commit is contained in:
nmemmert committed 2025-11-06 10:37:45 -05:00
1 parent 5c6fb1e935
commit 198e57835d
1 file changed
+31 -3
+31 -3
View File
@@ -83,13 +83,27 @@ def process_job(job_id, files):
os.makedirs(episode_dir, exist_ok=True) os.makedirs(episode_dir, exist_ok=True)
job_queue[job_id]['progress'] = 'Created output directory structure' job_queue[job_id]['progress'] = 'Created output directory structure'
# Analyze ZIP contents before processing
zip_contents = {}
for file_info in files:
if file_info['name'].lower().endswith('.zip'):
try:
with zipfile.ZipFile(file_info['path'], 'r') as zip_ref:
pdf_files = [f for f in zip_ref.namelist() if f.lower().endswith('.pdf')]
zip_contents[file_info['name']] = pdf_files
except Exception as e:
zip_contents[file_info['name']] = [f"Error reading ZIP: {str(e)}"]
job_queue[job_id]['zip_contents'] = zip_contents
total_files = sum(1 for file_info in files if file_info['name'].lower().endswith('.pdf')) + \ total_files = sum(1 for file_info in files if file_info['name'].lower().endswith('.pdf')) + \
sum(len([f for f in zipfile.ZipFile(file_info['path']).namelist() sum(len(zip_contents.get(file_info['name'], []))
if f.lower().endswith('.pdf')])
for file_info in files if file_info['name'].lower().endswith('.zip')) for file_info in files if file_info['name'].lower().endswith('.zip'))
processed_count = 0 processed_count = 0
processed_count = 0
for file_info in files: for file_info in files:
filepath = file_info['path'] filepath = file_info['path']
filename = file_info['name'] filename = file_info['name']
@@ -365,8 +379,9 @@ def jobs():
.download-btn:hover { background-color: #0056b3; } .download-btn:hover { background-color: #0056b3; }
.logout { position: absolute; top: 20px; right: 20px; background-color: #dc3545; color: white; text-decoration: none; padding: 10px 20px; border-radius: 5px; } .logout { position: absolute; top: 20px; right: 20px; background-color: #dc3545; color: white; text-decoration: none; padding: 10px 20px; border-radius: 5px; }
.logout:hover { background-color: #c82333; } .logout:hover { background-color: #c82333; }
.zip-content { background-color: #f8f9fa; padding: 10px; margin: 5px 0; border-radius: 5px; border-left: 4px solid #007bff; }
ul { list-style-type: none; padding: 0; } ul { list-style-type: none; padding: 0; }
li { background-color: #f8f9fa; margin: 2px 0; padding: 5px; border-radius: 3px; } li { background-color: #ffffff; margin: 2px 0; padding: 5px; border-radius: 3px; }
</style> </style>
</head> </head>
<body> <body>
@@ -381,6 +396,19 @@ def jobs():
<p><strong>Progress:</strong> <span class="progress-text">{{ job.progress }}</span></p> <p><strong>Progress:</strong> <span class="progress-text">{{ job.progress }}</span></p>
{% endif %} {% endif %}
<p><strong>Files:</strong> {{ job.files|length }}</p> <p><strong>Files:</strong> {{ job.files|length }}</p>
{% if job.zip_contents %}
<p><strong>ZIP Contents:</strong></p>
{% for zip_name, pdf_files in job.zip_contents.items() %}
<div class="zip-content">
<strong>{{ zip_name }}:</strong>
<ul>
{% for pdf_file in pdf_files %}
<li>{{ pdf_file }}</li>
{% endfor %}
</ul>
</div>
{% endfor %}
{% endif %}
{% if job.status == 'completed' %} {% if job.status == 'completed' %}
{% if job.zip_name %} {% if job.zip_name %}
<p><a href="/download/{{ job.zip_name }}" class="download-btn">Download ZIP</a></p> <p><a href="/download/{{ job.zip_name }}" class="download-btn">Download ZIP</a></p>