Refactor out deletion request handling to prep for #33

This commit is contained in:
David Dworken 2022-12-18 00:19:52 -08:00
parent dd887b5a42
commit d15376f37d
No known key found for this signature in database
2 changed files with 13 additions and 10 deletions

View File

@ -3,7 +3,6 @@ package cmd
import (
"bufio"
"context"
"encoding/json"
"fmt"
"os"
"strings"
@ -89,15 +88,7 @@ func deleteOnRemoteInstances(ctx *context.Context, historyEntries []*data.Histor
for _, entry := range historyEntries {
deletionRequest.Messages.Ids = append(deletionRequest.Messages.Ids, shared.MessageIdentifier{Date: entry.EndTime, DeviceId: entry.DeviceId})
}
data, err := json.Marshal(deletionRequest)
if err != nil {
return err
}
_, err = lib.ApiPost("/api/v1/add-deletion-request", "application/json", data)
if err != nil {
return fmt.Errorf("failed to send deletion request to backend service, this may cause commands to not get deleted on other instances of hishtory: %v", err)
}
return nil
return lib.SendDeletionRequest(deletionRequest)
}
func init() {

View File

@ -1255,3 +1255,15 @@ func GetDumpRequests(config hctx.ClientConfig) ([]*shared.DumpRequest, error) {
err = json.Unmarshal(resp, &dumpRequests)
return dumpRequests, err
}
func SendDeletionRequest(deletionRequest shared.DeletionRequest) error {
data, err := json.Marshal(deletionRequest)
if err != nil {
return err
}
_, err = ApiPost("/api/v1/add-deletion-request", "application/json", data)
if err != nil {
return fmt.Errorf("failed to send deletion request to backend service, this may cause commands to not get deleted on other instances of hishtory: %v", err)
}
return nil
}