MCPcopy Create free account
hub / github.com/daodst/chat / DeleteDevices

Function DeleteDevices

clientapi/routing/device.go:244–269  ·  view source on GitHub ↗

DeleteDevices handles POST requests to /delete_devices

(
	req *http.Request, userAPI api.ClientUserAPI, device *api.Device,
)

Source from the content-addressed store, hash-verified

242
243// DeleteDevices handles POST requests to /delete_devices
244func 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"
272func stripIPPort(addr string) string {

Callers 1

SetupFunction · 0.85

Calls 4

ContextMethod · 0.80
CloseMethod · 0.65
PerformDeviceDeletionMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected