quality
This commit is contained in:
parent
a392fa0cda
commit
158881ed9c
|
@ -36,8 +36,9 @@ func FunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
|
||||||
return nil, errors.New("filesharing is not enabled")
|
return nil, errors.New("filesharing is not enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreviewFunctionalityGate returns filesharing if image previews are enabled
|
||||||
func PreviewFunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
|
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 new(Functionality), nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("image previews are not enabled")
|
return nil, errors.New("image previews are not enabled")
|
||||||
|
@ -52,17 +53,18 @@ type OverlayMessage struct {
|
||||||
Size uint64 `json:"s"`
|
Size uint64 `json:"s"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FileKey is the unique reference to a file offer
|
||||||
func (om *OverlayMessage) FileKey() string {
|
func (om *OverlayMessage) FileKey() string {
|
||||||
return fmt.Sprintf("%s.%s", om.Hash, om.Nonce)
|
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 {
|
func (om *OverlayMessage) ShouldAutoDL() bool {
|
||||||
if om.Size > constants.ImagePreviewMaxSizeInBytes {
|
if om.Size > constants.ImagePreviewMaxSizeInBytes {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
lname := strings.ToLower(om.Name)
|
lname := strings.ToLower(om.Name)
|
||||||
for _, s := range constants.AUTODL_FILE_EXTS {
|
for _, s := range constants.AutoDLFileExts {
|
||||||
if strings.HasSuffix(lname, s) {
|
if strings.HasSuffix(lname, s) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -133,6 +135,7 @@ func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, conve
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateDownloadPath creates a file path that doesn't currently exist on the filesystem
|
||||||
func GenerateDownloadPath(basePath, fileName string) (filePath, manifestPath string) {
|
func GenerateDownloadPath(basePath, fileName string) (filePath, manifestPath string) {
|
||||||
// avoid all kina funky shit
|
// avoid all kina funky shit
|
||||||
re := regexp.MustCompile(`[^A-Za-z0-9._-]`)
|
re := regexp.MustCompile(`[^A-Za-z0-9._-]`)
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package constants
|
package constants
|
||||||
|
|
||||||
// Allows file sharing
|
// FileSharingExperiment Allows file sharing
|
||||||
const FileSharingExperiment = "filesharing"
|
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
|
// requires FileSharingExperiment to be enabled
|
||||||
const ImagePreviewsExperiment = "filesharing-images"
|
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
|
const ImagePreviewMaxSizeInBytes = 20971520
|
||||||
|
|
||||||
// Files with these extensions will be autodownloaded using ImagePreviewsExperiment
|
// AutoDLFileExts Files with these extensions will be autodownloaded using ImagePreviewsExperiment
|
||||||
var AUTODL_FILE_EXTS = [...]string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"}
|
var AutoDLFileExts = [...]string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"}
|
||||||
|
|
Loading…
Reference in New Issue