|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Photo Organizer App</title> |
| 6 | + <style> |
| 7 | + body { font-family: Arial, sans-serif; margin: 40px; } |
| 8 | + .container { max-width: 700px; margin: auto; } |
| 9 | + input, button { margin: 5px; } |
| 10 | + img { max-width: 150px; margin: 5px; border: 1px solid #ccc; } |
| 11 | + </style> |
| 12 | +</head> |
| 13 | +<body> |
| 14 | +<div class="container"> |
| 15 | + <h2>Photo Organizer App</h2> |
| 16 | + <form id="uploadForm" enctype="multipart/form-data"> |
| 17 | + <input type="file" name="photo" required /> |
| 18 | + <input type="text" name="tags" placeholder="Tags (comma separated)" /> |
| 19 | + <button type="submit">Upload</button> |
| 20 | + </form> |
| 21 | + <div> |
| 22 | + <label>Search by Tag:</label> |
| 23 | + <input type="text" id="searchTag" /> |
| 24 | + <label>Search by Date:</label> |
| 25 | + <input type="date" id="searchDate" /> |
| 26 | + <button onclick="searchPhotos()">Search</button> |
| 27 | + </div> |
| 28 | + <div id="photoGallery"></div> |
| 29 | +</div> |
| 30 | +<script> |
| 31 | +document.getElementById('uploadForm').onsubmit = function(e) { |
| 32 | + e.preventDefault(); |
| 33 | + const formData = new FormData(this); |
| 34 | + fetch('/api/upload', { method: 'POST', body: formData }) |
| 35 | + .then(() => searchPhotos()); |
| 36 | +}; |
| 37 | +function searchPhotos() { |
| 38 | + const tag = document.getElementById('searchTag').value; |
| 39 | + const date = document.getElementById('searchDate').value; |
| 40 | + let url = '/api/photos?'; |
| 41 | + if (tag) url += `tag=${tag}&`; |
| 42 | + if (date) url += `date=${date}`; |
| 43 | + fetch(url).then(r => r.json()).then(data => { |
| 44 | + const gallery = document.getElementById('photoGallery'); |
| 45 | + gallery.innerHTML = ''; |
| 46 | + data.forEach(p => { |
| 47 | + gallery.innerHTML += `<div><img src='/photos/${p.filename}' /><br/>Tags: ${p.tags.join(', ')}<br/>Date: ${p.date}</div>`; |
| 48 | + }); |
| 49 | + }); |
| 50 | +} |
| 51 | +searchPhotos(); |
| 52 | +</script> |
| 53 | +</body> |
| 54 | +</html> |
0 commit comments