Browse Source

quality

pull/413/head
erinn 4 weeks ago
parent
commit
158881ed9c
  1. 9
      functionality/filesharing/filesharing_functionality.go
  2. 10
      model/constants/experiments.go

9
functionality/filesharing/filesharing_functionality.go

@ -36,8 +36,9 @@ func FunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
return nil, errors.New("filesharing is not enabled")
}
// PreviewFunctionalityGate returns filesharing if image previews are enabled
func PreviewFunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
if experimentMap[constants.FileSharingExperiment] == true && experimentMap[constants.ImagePreviewsExperiment] == true {
if experimentMap[constants.FileSharingExperiment] && experimentMap[constants.ImagePreviewsExperiment] {
return new(Functionality), nil
}
return nil, errors.New("image previews are not enabled")
@ -52,17 +53,18 @@ type OverlayMessage struct {
Size uint64 `json:"s"`
}
// FileKey is the unique reference to a file offer
func (om *OverlayMessage) FileKey() string {
return fmt.Sprintf("%s.%s", om.Hash, om.Nonce)
}
// checks file size and file name. *DOES NOT* check user settings or contact state
// ShouldAutoDL checks file size and file name. *DOES NOT* check user settings or contact state
func (om *OverlayMessage) ShouldAutoDL() bool {
if om.Size > constants.ImagePreviewMaxSizeInBytes {
return false
}
lname := strings.ToLower(om.Name)
for _, s := range constants.AUTODL_FILE_EXTS {
for _, s := range constants.AutoDLFileExts {
if strings.HasSuffix(lname, s) {
return true
}
@ -133,6 +135,7 @@ func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, conve
return nil
}
// GenerateDownloadPath creates a file path that doesn't currently exist on the filesystem
func GenerateDownloadPath(basePath, fileName string) (filePath, manifestPath string) {
// avoid all kina funky shit
re := regexp.MustCompile(`[^A-Za-z0-9._-]`)

10
model/constants/experiments.go

@ -1,14 +1,14 @@
package constants
// Allows file sharing
// FileSharingExperiment Allows file sharing
const FileSharingExperiment = "filesharing"
// Causes images (up to ImagePreviewMaxSizeInBytes, from accepted contacts) to auto-dl and preview
// ImagePreviewsExperiment 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
// ImagePreviewMaxSizeInBytes 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"}
// AutoDLFileExts Files with these extensions will be autodownloaded using ImagePreviewsExperiment
var AutoDLFileExts = [...]string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"}
Loading…
Cancel
Save