this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add a delete link

+47 -2
+47 -2
src/camera_server.py
··· 60 60 .gallery {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }} 61 61 .photo {{ border: 1px solid #ddd; padding: 5px; }} 62 62 .photo img {{ width: 100%; height: auto; }} 63 - .photo a {{ display: block; text-align: center; margin-top: 5px; }} 63 + .photo .actions {{ text-align: center; margin-top: 5px; }} 64 + .photo .actions a {{ margin: 0 5px; }} 64 65 </style> 65 66 <script> 66 67 const ws = new WebSocket('ws://' + window.location.hostname + ':8765'); ··· 69 70 window.location.reload(); 70 71 }} 71 72 }}; 73 + 74 + function deletePhoto(filename) {{ 75 + if(confirm('Are you sure you want to delete this photo?')) {{ 76 + fetch('/delete/' + filename, {{ 77 + method: 'POST' 78 + }}).then(response => {{ 79 + if(response.ok) {{ 80 + window.location.reload(); 81 + }} 82 + }}); 83 + }} 84 + }} 72 85 </script> 73 86 </head> 74 87 <body> ··· 103 116 photo_items += f""" 104 117 <div class="photo"> 105 118 <img src="/{filename}" alt="{timestamp}"> 106 - <a href="/{filename}" download>Download</a> 119 + <div class="actions"> 120 + <a href="/{filename}" download>Download</a> 121 + <a href="#" onclick="deletePhoto('{filename}'); return false;">Delete</a> 122 + </div> 107 123 </div> 108 124 """ 109 125 ··· 117 133 self.wfile.write(html.encode()) 118 134 else: 119 135 super().do_GET() 136 + 137 + def do_POST(self): 138 + if self.path.startswith('/delete/'): 139 + filename = self.path[8:] # Remove '/delete/' prefix 140 + file_path = os.path.join(Config.PHOTO_DIR, filename) 141 + 142 + try: 143 + if os.path.exists(file_path) and os.path.isfile(file_path): 144 + os.remove(file_path) 145 + logger.info(f"Deleted photo: {filename}") 146 + self.send_response(200) 147 + self.send_header('Content-type', 'text/plain') 148 + self.end_headers() 149 + self.wfile.write(b"File deleted successfully") 150 + asyncio.run(notify_clients()) 151 + else: 152 + self.send_response(404) 153 + self.send_header('Content-type', 'text/plain') 154 + self.end_headers() 155 + self.wfile.write(b"File not found") 156 + except Exception as e: 157 + logger.error(f"Error deleting file {filename}: {str(e)}") 158 + self.send_response(500) 159 + self.send_header('Content-type', 'text/plain') 160 + self.end_headers() 161 + self.wfile.write(b"Error deleting file") 162 + else: 163 + self.send_response(404) 164 + self.end_headers() 120 165 121 166 async def websocket_handler(websocket, path): 122 167 connected_clients.add(websocket)