diff --git a/internal/api/room/upload.go b/internal/api/room/upload.go index bc25ef3..f2fadd2 100644 --- a/internal/api/room/upload.go +++ b/internal/api/room/upload.go @@ -16,6 +16,10 @@ import ( const maxUploadSize = 32 << 20 func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) error { + if !h.desktop.IsUploadDropEnabled() { + return utils.HttpBadRequest("upload drop is disabled") + } + err := r.ParseMultipartForm(maxUploadSize) if err != nil { return utils.HttpBadRequest("failed to parse multipart form").WithInternalErr(err) diff --git a/internal/config/desktop.go b/internal/config/desktop.go index 10bcec9..a021ddf 100644 --- a/internal/config/desktop.go +++ b/internal/config/desktop.go @@ -20,6 +20,7 @@ type Desktop struct { InputSocket string Unminimize bool + UploadDrop bool FileChooserDialog bool } @@ -44,6 +45,11 @@ func (Desktop) Init(cmd *cobra.Command) error { return err } + cmd.PersistentFlags().Bool("desktop.upload_drop", true, "whether drop upload is enabled") + if err := viper.BindPFlag("desktop.upload_drop", cmd.PersistentFlags().Lookup("desktop.upload_drop")); err != nil { + return err + } + cmd.PersistentFlags().Bool("desktop.file_chooser_dialog", false, "whether to handle file chooser dialog externally") if err := viper.BindPFlag("desktop.file_chooser_dialog", cmd.PersistentFlags().Lookup("desktop.file_chooser_dialog")); err != nil { return err @@ -80,5 +86,6 @@ func (s *Desktop) Set() { s.UseInputDriver = viper.GetBool("desktop.input.enabled") s.InputSocket = viper.GetString("desktop.input.socket") s.Unminimize = viper.GetBool("desktop.unminimize") + s.UploadDrop = viper.GetBool("desktop.upload_drop") s.FileChooserDialog = viper.GetBool("desktop.file_chooser_dialog") } diff --git a/internal/desktop/drop.go b/internal/desktop/drop.go index 3cb13bc..cee81a6 100644 --- a/internal/desktop/drop.go +++ b/internal/desktop/drop.go @@ -62,3 +62,7 @@ func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool { return false } } + +func (manager *DesktopManagerCtx) IsUploadDropEnabled() bool { + return manager.config.UploadDrop +} diff --git a/pkg/types/desktop.go b/pkg/types/desktop.go index bd38da0..b769909 100644 --- a/pkg/types/desktop.go +++ b/pkg/types/desktop.go @@ -94,6 +94,7 @@ type DesktopManager interface { // drop DropFiles(x int, y int, files []string) bool + IsUploadDropEnabled() bool // filechooser HandleFileChooserDialog(uri string) error