mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 20:07:52 +02:00
Refactor out deletion request handling to prep for #33
This commit is contained in:
parent
dd887b5a42
commit
d15376f37d
@ -3,7 +3,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -89,15 +88,7 @@ func deleteOnRemoteInstances(ctx *context.Context, historyEntries []*data.Histor
|
|||||||
for _, entry := range historyEntries {
|
for _, entry := range historyEntries {
|
||||||
deletionRequest.Messages.Ids = append(deletionRequest.Messages.Ids, shared.MessageIdentifier{Date: entry.EndTime, DeviceId: entry.DeviceId})
|
deletionRequest.Messages.Ids = append(deletionRequest.Messages.Ids, shared.MessageIdentifier{Date: entry.EndTime, DeviceId: entry.DeviceId})
|
||||||
}
|
}
|
||||||
data, err := json.Marshal(deletionRequest)
|
return lib.SendDeletionRequest(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -1255,3 +1255,15 @@ func GetDumpRequests(config hctx.ClientConfig) ([]*shared.DumpRequest, error) {
|
|||||||
err = json.Unmarshal(resp, &dumpRequests)
|
err = json.Unmarshal(resp, &dumpRequests)
|
||||||
return dumpRequests, err
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user