erinn makes changes

This commit is contained in:
erinn 2021-09-15 13:35:14 -07:00
parent a28896c293
commit 2bd170fb85
2 changed files with 33 additions and 27 deletions

View File

@ -2,19 +2,20 @@ package filesharing
import ( import (
"crypto/rand" "crypto/rand"
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/peer"
"cwtch.im/cwtch/protocol/files"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/log"
"io" "io"
"math" "math"
"path" "path"
"strconv" "strconv"
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/peer"
"cwtch.im/cwtch/protocol/files"
"git.openprivacy.ca/openprivacy/log"
) )
// Functionality groups some common UI triggered functions for contacts... // Functionality groups some common UI triggered functions for contacts...
@ -40,8 +41,8 @@ type OverlayMessage struct {
// DownloadFile given a profile, a conversation handle and a file sharing key, start off a download process // DownloadFile given a profile, a conversation handle and a file sharing key, start off a download process
// to downloadFilePath // to downloadFilePath
func (f *Functionality) DownloadFile(profile peer.CwtchPeer, handle string, downloadFilePath string, key string) { func (f *Functionality) DownloadFile(profile peer.CwtchPeer, handle string, downloadFilePath string, manifestFilePath string, key string) {
profile.SetAttribute(attr.GetLocalScope(key), downloadFilePath) profile.SetAttribute(attr.GetLocalScope(key), manifestFilePath)
profile.SendGetValToPeer(handle, attr.PublicScope, fmt.Sprintf("%s.manifest.size", key)) profile.SendGetValToPeer(handle, attr.PublicScope, fmt.Sprintf("%s.manifest.size", key))
} }

View File

@ -1,22 +1,23 @@
package peer package peer
import ( import (
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/protocol/connections"
"cwtch.im/cwtch/protocol/files"
"encoding/base32" "encoding/base32"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/connectivity/tor"
"git.openprivacy.ca/openprivacy/log"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/protocol/connections"
"cwtch.im/cwtch/protocol/files"
"git.openprivacy.ca/openprivacy/connectivity/tor"
"git.openprivacy.ca/openprivacy/log"
) )
const lastKnownSignature = "LastKnowSignature" const lastKnownSignature = "LastKnowSignature"
@ -159,7 +160,6 @@ type ModifyServers interface {
// SendMessages enables a caller to sender messages to a contact // SendMessages enables a caller to sender messages to a contact
type SendMessages interface { type SendMessages interface {
SendMessage(handle string, message string) error SendMessage(handle string, message string) error
SendGetValToPeer(string, string, string) SendGetValToPeer(string, string, string)
@ -837,23 +837,28 @@ func (cp *cwtchPeer) eventHandler() {
fileKey := ev.Data[event.FileKey] fileKey := ev.Data[event.FileKey]
serializedManifest := ev.Data[event.SerializedManifest] serializedManifest := ev.Data[event.SerializedManifest]
manifestFilePath, exists := cp.GetAttribute(attr.GetLocalScope(fmt.Sprintf("%v.manifest", fileKey)))
if exists {
downloadFilePath, exists := cp.GetAttribute(attr.GetLocalScope(fileKey)) downloadFilePath, exists := cp.GetAttribute(attr.GetLocalScope(fileKey))
if exists { if exists {
log.Debugf("downloading file to %v", downloadFilePath) log.Debugf("downloading manifest to %v, file to %v", manifestFilePath, downloadFilePath)
var manifest files.Manifest var manifest files.Manifest
err := json.Unmarshal([]byte(serializedManifest), &manifest) err := json.Unmarshal([]byte(serializedManifest), &manifest)
if err == nil { if err == nil {
manifest.FileName = downloadFilePath manifest.FileName = downloadFilePath
log.Debugf("saving manifest") log.Debugf("saving manifest")
err = manifest.Save(fmt.Sprintf("%v.manifest", downloadFilePath)) err = manifest.Save(manifestFilePath)
if err != nil { if err != nil {
log.Errorf("could not save manifest...") log.Errorf("could not save manifest: %v", err)
} else { } else {
cp.eventBus.Publish(event.NewEvent(event.ManifestSaved, map[event.Field]string{event.FileKey: fileKey, event.Handle: handle, event.SerializedManifest: string(manifest.Serialize())})) cp.eventBus.Publish(event.NewEvent(event.ManifestSaved, map[event.Field]string{event.FileKey: fileKey, event.Handle: handle, event.SerializedManifest: string(manifest.Serialize())}))
} }
} else { } else {
log.Errorf("error saving manifest: %v", err) log.Errorf("error saving manifest: %v", err)
} }
} else {
log.Errorf("found manifest path but not download path for %v", fileKey)
}
} else { } else {
log.Errorf("no download path found for manifest: %v", fileKey) log.Errorf("no download path found for manifest: %v", fileKey)
} }