albumup commited on
Commit
1e9923c
·
verified ·
1 Parent(s): 983b7ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +237 -15
app.py CHANGED
@@ -215,36 +215,45 @@ async def view_album(album_id: str):
215
  for file in album['files']:
216
  file_url = f"/upload/{file['path']}"
217
  file_type = get_file_type(file['filename'])
 
218
 
219
  preview_html = ""
220
  if file_type == 'image':
221
  preview_html = f"""
222
- <div class="preview-container">
223
- <img src="{file_url}" alt="{file['filename']}" onclick="openModal('{file_url}')">
224
  </div>
225
  """
226
  elif file_type == 'video':
227
  preview_html = f"""
228
- <div class="preview-container">
229
- <video onclick="openModal('{file_url}')" style="cursor: pointer;">
230
  <source src="{file_url}" type="{file['content_type']}">
231
- Your browser does not support the video tag.
232
  </video>
 
233
  </div>
234
  """
235
  else:
236
  preview_html = f"""
237
  <div class="preview-container">
238
- <p>No preview available for {file['filename']}</p>
 
 
 
 
239
  </div>
240
  """
241
 
242
  file_list_html += f"""
243
- <div class="file-item">
244
  {preview_html}
245
- <p>{file['filename']}</p>
246
- <a href="{file_url}" class="button" onclick="openModal('{file_url}'); return false;">View</a>
247
- <a href="{file_url}?download=true" class="button" target="_blank">Download</a>
 
 
 
 
248
  </div>
249
  """
250
 
@@ -254,14 +263,227 @@ async def view_album(album_id: str):
254
  <head>
255
  <meta charset="UTF-8">
256
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
257
- <title>Album View - {album['albumName']}</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  </head>
259
  <body>
260
- <h1>{album['albumName']}</h1>
261
- <a href="/album/{album_id}/download" class="button">Download All Files as ZIP</a>
262
- <div class="file-grid">
 
 
 
263
  {file_list_html}
264
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  </body>
266
  </html>
267
  """
@@ -379,4 +601,4 @@ async def retry_upload(upload_url, file_content, content_type, max_retries=5):
379
 
380
  if __name__ == "__main__":
381
  import uvicorn
382
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
215
  for file in album['files']:
216
  file_url = f"/upload/{file['path']}"
217
  file_type = get_file_type(file['filename'])
218
+ download_url = f"{file_url}?download=true"
219
 
220
  preview_html = ""
221
  if file_type == 'image':
222
  preview_html = f"""
223
+ <div class="preview-container" onclick="openModal('{file_url}')">
224
+ <img src="{file_url}" alt="{file['filename']}" loading="lazy">
225
  </div>
226
  """
227
  elif file_type == 'video':
228
  preview_html = f"""
229
+ <div class="preview-container" onclick="openModal('{file_url}')">
230
+ <video>
231
  <source src="{file_url}" type="{file['content_type']}">
 
232
  </video>
233
+ <div class="play-icon">▶</div>
234
  </div>
235
  """
236
  else:
237
  preview_html = f"""
238
  <div class="preview-container">
239
+ <div class="file-icon">
240
+ <svg viewBox="0 0 24 24">
241
+ <path fill="currentColor" d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z"/>
242
+ </svg>
243
+ </div>
244
  </div>
245
  """
246
 
247
  file_list_html += f"""
248
+ <div class="file-card">
249
  {preview_html}
250
+ <div class="file-info">
251
+ <span class="filename">{file['filename']}</span>
252
+ <div class="actions">
253
+ <a href="{file_url}" target="_blank" class="action-btn view">View</a>
254
+ <a href="{download_url}" class="action-btn download">Download</a>
255
+ </div>
256
+ </div>
257
  </div>
258
  """
259
 
 
263
  <head>
264
  <meta charset="UTF-8">
265
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
266
+ <title>{album['albumName']}</title>
267
+ <style>
268
+ body {{
269
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
270
+ margin: 0;
271
+ padding: 20px;
272
+ background-color: #f5f5f5;
273
+ }}
274
+
275
+ .album-header {{
276
+ display: flex;
277
+ justify-content: space-between;
278
+ align-items: center;
279
+ margin-bottom: 30px;
280
+ flex-wrap: wrap;
281
+ gap: 15px;
282
+ }}
283
+
284
+ .grid-container {{
285
+ display: grid;
286
+ grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
287
+ gap: 20px;
288
+ padding: 10px;
289
+ }}
290
+
291
+ .file-card {{
292
+ background: white;
293
+ border-radius: 12px;
294
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
295
+ overflow: hidden;
296
+ transition: transform 0.2s;
297
+ }}
298
+
299
+ .file-card:hover {{
300
+ transform: translateY(-2px);
301
+ }}
302
+
303
+ .preview-container {{
304
+ position: relative;
305
+ background: #f8f9fa;
306
+ cursor: pointer;
307
+ aspect-ratio: 1;
308
+ }}
309
+
310
+ .preview-container img,
311
+ .preview-container video {{
312
+ width: 100%;
313
+ height: 100%;
314
+ object-fit: cover;
315
+ }}
316
+
317
+ .file-info {{
318
+ padding: 15px;
319
+ }}
320
+
321
+ .filename {{
322
+ display: block;
323
+ font-size: 0.9em;
324
+ color: #333;
325
+ white-space: nowrap;
326
+ overflow: hidden;
327
+ text-overflow: ellipsis;
328
+ margin-bottom: 10px;
329
+ }}
330
+
331
+ .actions {{
332
+ display: flex;
333
+ gap: 8px;
334
+ }}
335
+
336
+ .action-btn {{
337
+ flex: 1;
338
+ padding: 8px 12px;
339
+ text-align: center;
340
+ border-radius: 6px;
341
+ font-size: 0.85em;
342
+ text-decoration: none;
343
+ transition: all 0.2s;
344
+ }}
345
+
346
+ .view {{
347
+ background: #007bff;
348
+ color: white;
349
+ }}
350
+
351
+ .view:hover {{
352
+ background: #0056b3;
353
+ }}
354
+
355
+ .download {{
356
+ background: #28a745;
357
+ color: white;
358
+ }}
359
+
360
+ .download:hover {{
361
+ background: #218838;
362
+ }}
363
+
364
+ .play-icon {{
365
+ position: absolute;
366
+ top: 50%;
367
+ left: 50%;
368
+ transform: translate(-50%, -50%);
369
+ font-size: 2.5em;
370
+ color: white;
371
+ text-shadow: 0 2px 8px rgba(0,0,0,0.3);
372
+ opacity: 0.9;
373
+ }}
374
+
375
+ .file-icon {{
376
+ width: 100%;
377
+ height: 100%;
378
+ display: flex;
379
+ align-items: center;
380
+ justify-content: center;
381
+ color: #666;
382
+ }}
383
+
384
+ .file-icon svg {{
385
+ width: 50%;
386
+ height: 50%;
387
+ }}
388
+
389
+ /* Modal styles */
390
+ .modal {{
391
+ display: none;
392
+ position: fixed;
393
+ z-index: 1000;
394
+ left: 0;
395
+ top: 0;
396
+ width: 100%;
397
+ height: 100%;
398
+ background-color: rgba(0,0,0,0.9);
399
+ justify-content: center;
400
+ align-items: center;
401
+ }}
402
+
403
+ .modal-content {{
404
+ max-width: 90%;
405
+ max-height: 90%;
406
+ background: black;
407
+ }}
408
+
409
+ .modal-media {{
410
+ max-width: 100%;
411
+ max-height: 80vh;
412
+ object-fit: contain;
413
+ }}
414
+
415
+ .close-modal {{
416
+ position: absolute;
417
+ top: 20px;
418
+ right: 30px;
419
+ color: white;
420
+ font-size: 40px;
421
+ cursor: pointer;
422
+ z-index: 1001;
423
+ }}
424
+
425
+ @media (max-width: 768px) {{
426
+ .grid-container {{
427
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
428
+ }}
429
+
430
+ .album-header {{
431
+ flex-direction: column;
432
+ align-items: flex-start;
433
+ }}
434
+ }}
435
+ </style>
436
  </head>
437
  <body>
438
+ <div class="album-header">
439
+ <h1>{album['albumName']}</h1>
440
+ <a href="/album/{album_id}/download" class="download-all-btn">Download All as ZIP</a>
441
+ </div>
442
+
443
+ <div class="grid-container">
444
  {file_list_html}
445
  </div>
446
+
447
+ <div id="modal" class="modal" onclick="closeModal()">
448
+ <span class="close-modal">&times;</span>
449
+ <div class="modal-content">
450
+ <img id="modal-media" class="modal-media" src="" alt="">
451
+ <video id="modal-video" class="modal-media" controls style="display: none;"></video>
452
+ </div>
453
+ </div>
454
+
455
+ <script>
456
+ function openModal(url) {{
457
+ const modal = document.getElementById('modal');
458
+ const imgModal = document.getElementById('modal-media');
459
+ const videoModal = document.getElementById('modal-video');
460
+
461
+ if (url.includes('.mp4') || url.includes('.webm')) {{
462
+ videoModal.style.display = 'block';
463
+ imgModal.style.display = 'none';
464
+ videoModal.src = url;
465
+ }} else {{
466
+ imgModal.style.display = 'block';
467
+ videoModal.style.display = 'none';
468
+ imgModal.src = url;
469
+ }}
470
+
471
+ modal.style.display = 'flex';
472
+ }}
473
+
474
+ function closeModal() {{
475
+ document.getElementById('modal').style.display = 'none';
476
+ document.getElementById('modal-video').pause();
477
+ }}
478
+
479
+ // Close modal when clicking outside content
480
+ window.onclick = function(event) {{
481
+ const modal = document.getElementById('modal');
482
+ if (event.target === modal) {{
483
+ closeModal();
484
+ }}
485
+ }}
486
+ </script>
487
  </body>
488
  </html>
489
  """
 
601
 
602
  if __name__ == "__main__":
603
  import uvicorn
604
+ uvicorn.run(app, host="0.0.0.0", port=8000)