Refactor file detachment logic in ReadMessage function
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-04-01 20:56:45 +02:00
parent 8fca09d853
commit 3ac6b02e56

View File

@ -31,7 +31,6 @@ func CheckForMessages(storage_path string, job *client.RequestsJob) (int, string
count := 0 count := 0
//fmt.Println(jsonjob)
// if folder does not exist, create it // if folder does not exist, create it
if _, err := os.Stat(filepath.Join(storage_path, "inbox")); os.IsNotExist(err) { if _, err := os.Stat(filepath.Join(storage_path, "inbox")); os.IsNotExist(err) {
err := os.MkdirAll(filepath.Join(storage_path, "inbox"), 0700) err := os.MkdirAll(filepath.Join(storage_path, "inbox"), 0700)
@ -108,7 +107,7 @@ func SaveCheckJobs() (string, error) {
} }
// ReadMessage // ReadMessage
func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]string, []string, string, error) { func ReadMessage(messageFilename string) ([]string, []string, string, error) {
messagesOverview := []string{} messagesOverview := []string{}
filenames := []string{} filenames := []string{}
@ -151,8 +150,8 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]strin
// detach files // detach files
if usermsg.Files != nil { if usermsg.Files != nil {
// create files folder // create files folder
if _, err := os.Stat(filepath.Join(detachFilesStoragePath, "files")); os.IsNotExist(err) { if _, err := os.Stat(filepath.Join(client.GetConfig().StoragePath, identity.Uuid, "files")); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Join(detachFilesStoragePath, "files"), 0700) err = os.MkdirAll(filepath.Join(client.GetConfig().StoragePath, identity.Uuid, "files"), 0700)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -161,7 +160,7 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]strin
filename := uuid.New().String() + "_" + file.Filename filename := uuid.New().String() + "_" + file.Filename
filenames = append(filenames, peer.Name+" sent: "+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(client.GetConfig().StoragePath, identity.Uuid, "files", filename), file.Data, 0600)
} }
//? result["invitation finalized"] = peer.Name //? result["invitation finalized"] = peer.Name
} }