]> git.giacomolli.uk - onechat/blobdiff - daemon.go
Back up the daemon and restore its data
[onechat] / daemon.go
index 898de68d34ae0355a0eedb36a8dcc21fbf95556a..e534aeac96a7e1e781c3f55ba9e636848b062fb7 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -204,12 +204,24 @@ func (h *DaemonHub) read(ctx context.Context, client *DaemonClient, l *TurnLoop)
 
                err := json.Unmarshal(scanner.Bytes(), &request)
                if err == nil {
 
                err := json.Unmarshal(scanner.Bytes(), &request)
                if err == nil {
-                       err = daemonRunRequest(l, h.whatsapp, request, func(text string) {
-                               h.Send(client, Event{
-                                       Kind: "notice",
-                                       Text: text,
+                       if request.Type == "backup" {
+                               var size int64
+
+                               size, err = backupData(ctx, filepath.Dir(l.agent.dir), request.Text, h.whatsapp, l.runs.Snapshot)
+                               if err == nil {
+                                       h.Send(client, Event{
+                                               Kind: "backup",
+                                               Text: fmt.Sprintf("%s (%d bytes)", request.Text, size),
+                                       })
+                               }
+                       } else {
+                               err = daemonRunRequest(l, h.whatsapp, request, func(text string) {
+                                       h.Send(client, Event{
+                                               Kind: "notice",
+                                               Text: text,
+                                       })
                                })
                                })
-                       })
+                       }
                }
 
                if err != nil {
                }
 
                if err != nil {