mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-09 15:15:08 +02:00
Make the reupload command more efficient by sending multiple entries at once
This commit is contained in:
@ -999,13 +999,17 @@ func ReliableDbCreate(db *gorm.DB, entry interface{}) error {
|
||||
return fmt.Errorf("failed to create DB entry even with %d retries: %v", i, err)
|
||||
}
|
||||
|
||||
func EncryptAndMarshal(config hctx.ClientConfig, entry *data.HistoryEntry) ([]byte, error) {
|
||||
encEntry, err := data.EncryptHistoryEntry(config.UserSecret, *entry)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encrypt history entry")
|
||||
func EncryptAndMarshal(config hctx.ClientConfig, entries []*data.HistoryEntry) ([]byte, error) {
|
||||
var encEntries []shared.EncHistoryEntry
|
||||
for _, entry := range entries {
|
||||
encEntry, err := data.EncryptHistoryEntry(config.UserSecret, *entry)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encrypt history entry")
|
||||
}
|
||||
encEntry.DeviceId = config.DeviceId
|
||||
encEntries = append(encEntries, encEntry)
|
||||
}
|
||||
encEntry.DeviceId = config.DeviceId
|
||||
jsonValue, err := json.Marshal([]shared.EncHistoryEntry{encEntry})
|
||||
jsonValue, err := json.Marshal(encEntries)
|
||||
if err != nil {
|
||||
return jsonValue, fmt.Errorf("failed to marshal encrypted history entry: %v", err)
|
||||
}
|
||||
@ -1074,3 +1078,20 @@ func deleteOnRemoteInstances(ctx *context.Context, historyEntries []*data.Histor
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Reupload(ctx *context.Context) error {
|
||||
config := hctx.GetConf(ctx)
|
||||
entries, err := data.Search(hctx.GetDb(ctx), "", 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to reupload due to failed search: %v", err)
|
||||
}
|
||||
jsonValue, err := EncryptAndMarshal(config, entries)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to reupload due to failed encryption: %v", err)
|
||||
}
|
||||
_, err = ApiPost("/api/v1/submit?source_device_id="+config.DeviceId, "application/json", jsonValue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to reupload due to failed POST: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user