image previews - dan comments
This commit is contained in:
parent
5ae269c531
commit
a392fa0cda
|
@ -17,6 +17,7 @@ import (
|
||||||
|
|
||||||
"cwtch.im/cwtch/model"
|
"cwtch.im/cwtch/model"
|
||||||
"cwtch.im/cwtch/model/attr"
|
"cwtch.im/cwtch/model/attr"
|
||||||
|
"cwtch.im/cwtch/model/constants"
|
||||||
"cwtch.im/cwtch/peer"
|
"cwtch.im/cwtch/peer"
|
||||||
"cwtch.im/cwtch/protocol/files"
|
"cwtch.im/cwtch/protocol/files"
|
||||||
"git.openprivacy.ca/openprivacy/log"
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
|
@ -29,14 +30,14 @@ type Functionality struct {
|
||||||
// FunctionalityGate returns filesharing if enabled in the given experiment map
|
// FunctionalityGate returns filesharing if enabled in the given experiment map
|
||||||
// Note: Experiment maps are currently in libcwtch-go
|
// Note: Experiment maps are currently in libcwtch-go
|
||||||
func FunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
|
func FunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
|
||||||
if experimentMap["filesharing"] {
|
if experimentMap[constants.FileSharingExperiment] {
|
||||||
return new(Functionality), nil
|
return new(Functionality), nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("filesharing is not enabled")
|
return nil, errors.New("filesharing is not enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
func PreviewFunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
|
func PreviewFunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
|
||||||
if experimentMap["filesharing"] == true && experimentMap["filesharing-images"] == true {
|
if experimentMap[constants.FileSharingExperiment] == true && experimentMap[constants.ImagePreviewsExperiment] == true {
|
||||||
return new(Functionality), nil
|
return new(Functionality), nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("image previews are not enabled")
|
return nil, errors.New("image previews are not enabled")
|
||||||
|
@ -57,8 +58,16 @@ func (om *OverlayMessage) FileKey() string {
|
||||||
|
|
||||||
// checks file size and file name. *DOES NOT* check user settings or contact state
|
// checks file size and file name. *DOES NOT* check user settings or contact state
|
||||||
func (om *OverlayMessage) ShouldAutoDL() bool {
|
func (om *OverlayMessage) ShouldAutoDL() bool {
|
||||||
|
if om.Size > constants.ImagePreviewMaxSizeInBytes {
|
||||||
|
return false
|
||||||
|
}
|
||||||
lname := strings.ToLower(om.Name)
|
lname := strings.ToLower(om.Name)
|
||||||
return om.Size <= 20971520 && (strings.HasSuffix(lname, "jpg") || strings.HasSuffix(lname, "jpeg") || strings.HasSuffix(lname, "png") || strings.HasSuffix(lname, "gif") || strings.HasSuffix(lname, "webp") || strings.HasSuffix(lname, "bmp"))
|
for _, s := range constants.AUTODL_FILE_EXTS {
|
||||||
|
if strings.HasSuffix(lname, s) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package constants
|
||||||
|
|
||||||
|
// Allows file sharing
|
||||||
|
const FileSharingExperiment = "filesharing"
|
||||||
|
|
||||||
|
// Causes images (up to ImagePreviewMaxSizeInBytes, from accepted contacts) to auto-dl and preview
|
||||||
|
// requires FileSharingExperiment to be enabled
|
||||||
|
const ImagePreviewsExperiment = "filesharing-images"
|
||||||
|
|
||||||
|
// Files up to this size will be autodownloaded using ImagePreviewsExperiment
|
||||||
|
const ImagePreviewMaxSizeInBytes = 20971520
|
||||||
|
|
||||||
|
// Files with these extensions will be autodownloaded using ImagePreviewsExperiment
|
||||||
|
var AUTODL_FILE_EXTS = [...]string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"}
|
|
@ -2,6 +2,11 @@ package filesharing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
app2 "cwtch.im/cwtch/app"
|
app2 "cwtch.im/cwtch/app"
|
||||||
"cwtch.im/cwtch/app/utils"
|
"cwtch.im/cwtch/app/utils"
|
||||||
"cwtch.im/cwtch/event"
|
"cwtch.im/cwtch/event"
|
||||||
|
@ -12,14 +17,10 @@ import (
|
||||||
"cwtch.im/cwtch/peer"
|
"cwtch.im/cwtch/peer"
|
||||||
"cwtch.im/cwtch/protocol/connections"
|
"cwtch.im/cwtch/protocol/connections"
|
||||||
"cwtch.im/cwtch/protocol/files"
|
"cwtch.im/cwtch/protocol/files"
|
||||||
"encoding/base64"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||||
"git.openprivacy.ca/openprivacy/log"
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
|
|
||||||
// Import SQL Cipher
|
// Import SQL Cipher
|
||||||
_ "github.com/mutecomm/go-sqlcipher/v4"
|
|
||||||
mrand "math/rand"
|
mrand "math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
@ -28,6 +29,8 @@ import (
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/mutecomm/go-sqlcipher/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func waitForPeerPeerConnection(t *testing.T, peera peer.CwtchPeer, peerb peer.CwtchPeer) {
|
func waitForPeerPeerConnection(t *testing.T, peera peer.CwtchPeer, peerb peer.CwtchPeer) {
|
||||||
|
@ -121,7 +124,7 @@ func TestFileSharing(t *testing.T) {
|
||||||
|
|
||||||
fmt.Println("Alice and Bob are Connected!!")
|
fmt.Println("Alice and Bob are Connected!!")
|
||||||
|
|
||||||
filesharingFunctionality, _ := filesharing.FunctionalityGate(map[string]bool{"filesharing": true})
|
filesharingFunctionality, _ := filesharing.FunctionalityGate(map[string]bool{constants.FileSharingExperiment: true})
|
||||||
|
|
||||||
err = filesharingFunctionality.ShareFile("cwtch.png", alice, 1)
|
err = filesharingFunctionality.ShareFile("cwtch.png", alice, 1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue