From b556cd0361cf4984eb4a527f1b394a015981046b Mon Sep 17 00:00:00 2001 From: ycc Date: Fri, 29 Mar 2024 20:49:18 +0100 Subject: [PATCH] Add logging and create files folder for detach files --- client/helpers/backgroundHelper.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client/helpers/backgroundHelper.go b/client/helpers/backgroundHelper.go index 1d7fb81..2fb7ba1 100644 --- a/client/helpers/backgroundHelper.go +++ b/client/helpers/backgroundHelper.go @@ -2,6 +2,7 @@ package helpers import ( "errors" + "log" "os" "path/filepath" "strconv" @@ -145,19 +146,27 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]strin //fmt.Println("From:", usermsg.From) //jsonUserMessage, _ := json.Marshal(usermsg) //fmt.Println(string(jsonUserMessage)) - // detach files + peer = client.GetConfig().GetIdentity().Peers.GetFromPublicKey(usermsg.From) + // detach files if usermsg.Files != nil { + // create files folder + if _, err := os.Stat(filepath.Join(detachFilesStoragePath, "files")); os.IsNotExist(err) { + err = os.MkdirAll(filepath.Join(detachFilesStoragePath, "files"), 0700) + if err != nil { + log.Fatal(err) + } + } for _, file := range usermsg.Files { filename := uuid.New().String() + "_" + file.Filename - filenames = append(filenames, filename) + filenames = append(filenames, peer.Name+" sent: "+filename) // detach file os.WriteFile(filepath.Join(detachFilesStoragePath, "files", filename), file.Data, 0600) } //? result["invitation finalized"] = peer.Name } // user message - peer = client.GetConfig().GetIdentity().Peers.GetFromPublicKey(usermsg.From) + messagesOverview = append(messagesOverview, peer.Name+" > "+string(usermsg.Data)) // add message to storage err = peer.StoreMessage(usermsg, filenames)