@@ -186,6 +186,51 @@ func (h *Handler) HandleAbortMultipart(w http.ResponseWriter, r *http.Request) {
186186 _ = json .NewEncoder (w ).Encode (response )
187187}
188188
189+ // HandleDeleteAsset handles DELETE /v1/assets/{profile}/{key_base}
190+ // Deletes the original file and all generated thumbnails for an asset.
191+ func (h * Handler ) HandleDeleteAsset (w http.ResponseWriter , r * http.Request ) {
192+ if r .Method != http .MethodDelete {
193+ h .writeError (w , http .StatusMethodNotAllowed , ErrBadRequest , "Method not allowed" , "" )
194+ return
195+ }
196+
197+ // Extract profile and key_base from URL path
198+ path := strings .TrimPrefix (r .URL .Path , "/v1/assets/" )
199+ slashIdx := strings .Index (path , "/" )
200+ if slashIdx < 1 || slashIdx == len (path )- 1 {
201+ h .writeError (w , http .StatusBadRequest , ErrBadRequest , "Invalid URL format" , "Expected /v1/assets/{profile}/{key_base}" )
202+ return
203+ }
204+
205+ profileName := path [:slashIdx ]
206+ keyBase := path [slashIdx + 1 :]
207+
208+ // Look up profile config
209+ profile := h .storageConfig .GetProfile (profileName )
210+ if profile == nil {
211+ h .writeError (w , http .StatusBadRequest , ErrBadRequest , fmt .Sprintf ("Unknown profile: %s" , profileName ), "" )
212+ return
213+ }
214+
215+ // Delete the original + thumbnails
216+ deleted , err := h .uploadService .DeleteAsset (h .ctx , profile , keyBase )
217+ if err != nil {
218+ fmt .Printf ("Delete asset error: %v\n " , err )
219+ h .writeError (w , http .StatusInternalServerError , ErrStorageDenied , fmt .Sprintf ("Failed to delete asset: %v" , err ), "" )
220+ return
221+ }
222+
223+ w .Header ().Set ("Content-Type" , "application/json" )
224+ w .WriteHeader (http .StatusOK )
225+ response := map [string ]any {
226+ "status" : "deleted" ,
227+ "profile" : profileName ,
228+ "key_base" : keyBase ,
229+ "objects_deleted" : deleted ,
230+ }
231+ _ = json .NewEncoder (w ).Encode (response )
232+ }
233+
189234// writeError writes a standardized error response
190235func (h * Handler ) writeError (w http.ResponseWriter , statusCode int , code , message , hint string ) {
191236 errorResp := ErrorResponse {
0 commit comments