Add logging and create files folder for detach files
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
657fdbbf48
commit
b556cd0361
@ -2,6 +2,7 @@ package helpers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -145,19 +146,27 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]strin
|
|||||||
//fmt.Println("From:", usermsg.From)
|
//fmt.Println("From:", usermsg.From)
|
||||||
//jsonUserMessage, _ := json.Marshal(usermsg)
|
//jsonUserMessage, _ := json.Marshal(usermsg)
|
||||||
//fmt.Println(string(jsonUserMessage))
|
//fmt.Println(string(jsonUserMessage))
|
||||||
// detach files
|
peer = client.GetConfig().GetIdentity().Peers.GetFromPublicKey(usermsg.From)
|
||||||
|
|
||||||
|
// detach files
|
||||||
if usermsg.Files != nil {
|
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 {
|
for _, file := range usermsg.Files {
|
||||||
filename := uuid.New().String() + "_" + file.Filename
|
filename := uuid.New().String() + "_" + file.Filename
|
||||||
filenames = append(filenames, filename)
|
filenames = append(filenames, peer.Name+" sent: "+filename)
|
||||||
// detach file
|
// detach file
|
||||||
os.WriteFile(filepath.Join(detachFilesStoragePath, "files", filename), file.Data, 0600)
|
os.WriteFile(filepath.Join(detachFilesStoragePath, "files", filename), file.Data, 0600)
|
||||||
}
|
}
|
||||||
//? result["invitation finalized"] = peer.Name
|
//? result["invitation finalized"] = peer.Name
|
||||||
}
|
}
|
||||||
// user message
|
// user message
|
||||||
peer = client.GetConfig().GetIdentity().Peers.GetFromPublicKey(usermsg.From)
|
|
||||||
messagesOverview = append(messagesOverview, peer.Name+" > "+string(usermsg.Data))
|
messagesOverview = append(messagesOverview, peer.Name+" > "+string(usermsg.Data))
|
||||||
// add message to storage
|
// add message to storage
|
||||||
err = peer.StoreMessage(usermsg, filenames)
|
err = peer.StoreMessage(usermsg, filenames)
|
||||||
|
Loading…
Reference in New Issue
Block a user