alpha
Login
or
Join now
dunkirk.sh
/
inky
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
feat: add a delete link
author
Kieran Klukas
date
1 year ago
(Apr 11, 2025, 8:05 PM -0400)
commit
574fcb59
574fcb59f88722a7fb28f5bd2d90ccc0c2968122
parent
433d2b36
433d2b36563eac5427a25e9fae205ace5a615dc7
+47
-2
1 changed file
Expand all
Collapse all
Unified
Split
src
camera_server.py
+47
-2
src/camera_server.py
Reviewed
···
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
63
-
.photo a {{ display: block; text-align: center; margin-top: 5px; }}
63
63
+
.photo .actions {{ text-align: center; margin-top: 5px; }}
64
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
73
+
74
74
+
function deletePhoto(filename) {{
75
75
+
if(confirm('Are you sure you want to delete this photo?')) {{
76
76
+
fetch('/delete/' + filename, {{
77
77
+
method: 'POST'
78
78
+
}}).then(response => {{
79
79
+
if(response.ok) {{
80
80
+
window.location.reload();
81
81
+
}}
82
82
+
}});
83
83
+
}}
84
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
106
-
<a href="/{filename}" download>Download</a>
119
119
+
<div class="actions">
120
120
+
<a href="/{filename}" download>Download</a>
121
121
+
<a href="#" onclick="deletePhoto('{filename}'); return false;">Delete</a>
122
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
136
+
137
137
+
def do_POST(self):
138
138
+
if self.path.startswith('/delete/'):
139
139
+
filename = self.path[8:] # Remove '/delete/' prefix
140
140
+
file_path = os.path.join(Config.PHOTO_DIR, filename)
141
141
+
142
142
+
try:
143
143
+
if os.path.exists(file_path) and os.path.isfile(file_path):
144
144
+
os.remove(file_path)
145
145
+
logger.info(f"Deleted photo: {filename}")
146
146
+
self.send_response(200)
147
147
+
self.send_header('Content-type', 'text/plain')
148
148
+
self.end_headers()
149
149
+
self.wfile.write(b"File deleted successfully")
150
150
+
asyncio.run(notify_clients())
151
151
+
else:
152
152
+
self.send_response(404)
153
153
+
self.send_header('Content-type', 'text/plain')
154
154
+
self.end_headers()
155
155
+
self.wfile.write(b"File not found")
156
156
+
except Exception as e:
157
157
+
logger.error(f"Error deleting file {filename}: {str(e)}")
158
158
+
self.send_response(500)
159
159
+
self.send_header('Content-type', 'text/plain')
160
160
+
self.end_headers()
161
161
+
self.wfile.write(b"Error deleting file")
162
162
+
else:
163
163
+
self.send_response(404)
164
164
+
self.end_headers()
120
165
121
166
async def websocket_handler(websocket, path):
122
167
connected_clients.add(websocket)