DeleteDevices handles POST requests to /delete_devices
( req *http.Request, userAPI api.ClientUserAPI, device *api.Device, )
| 242 | |
| 243 | // DeleteDevices handles POST requests to /delete_devices |
| 244 | func DeleteDevices( |
| 245 | req *http.Request, userAPI api.ClientUserAPI, device *api.Device, |
| 246 | ) util.JSONResponse { |
| 247 | ctx := req.Context() |
| 248 | payload := devicesDeleteJSON{} |
| 249 | |
| 250 | if resErr := httputil.UnmarshalJSONRequest(req, &payload); resErr != nil { |
| 251 | return *resErr |
| 252 | } |
| 253 | |
| 254 | defer req.Body.Close() // nolint: errcheck |
| 255 | |
| 256 | var res api.PerformDeviceDeletionResponse |
| 257 | if err := userAPI.PerformDeviceDeletion(ctx, &api.PerformDeviceDeletionRequest{ |
| 258 | UserID: device.UserID, |
| 259 | DeviceIDs: payload.Devices, |
| 260 | }, &res); err != nil { |
| 261 | util.GetLogger(ctx).WithError(err).Error("userAPI.PerformDeviceDeletion failed") |
| 262 | return jsonerror.InternalServerError() |
| 263 | } |
| 264 | |
| 265 | return util.JSONResponse{ |
| 266 | Code: http.StatusOK, |
| 267 | JSON: struct{}{}, |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // stripIPPort converts strings like "[::1]:12345" to "::1" |
| 272 | func stripIPPort(addr string) string { |
no test coverage detected