upload drop to config.

This commit is contained in:
Miroslav Šedivý 2023-11-24 10:44:24 +01:00
parent b40c0778c8
commit 3dbcc41795
4 changed files with 16 additions and 0 deletions

View File

@ -16,6 +16,10 @@ import (
const maxUploadSize = 32 << 20 const maxUploadSize = 32 << 20
func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) error { 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) err := r.ParseMultipartForm(maxUploadSize)
if err != nil { if err != nil {
return utils.HttpBadRequest("failed to parse multipart form").WithInternalErr(err) return utils.HttpBadRequest("failed to parse multipart form").WithInternalErr(err)

View File

@ -20,6 +20,7 @@ type Desktop struct {
InputSocket string InputSocket string
Unminimize bool Unminimize bool
UploadDrop bool
FileChooserDialog bool FileChooserDialog bool
} }
@ -44,6 +45,11 @@ func (Desktop) Init(cmd *cobra.Command) error {
return err 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") 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 { if err := viper.BindPFlag("desktop.file_chooser_dialog", cmd.PersistentFlags().Lookup("desktop.file_chooser_dialog")); err != nil {
return err return err
@ -80,5 +86,6 @@ func (s *Desktop) Set() {
s.UseInputDriver = viper.GetBool("desktop.input.enabled") s.UseInputDriver = viper.GetBool("desktop.input.enabled")
s.InputSocket = viper.GetString("desktop.input.socket") s.InputSocket = viper.GetString("desktop.input.socket")
s.Unminimize = viper.GetBool("desktop.unminimize") s.Unminimize = viper.GetBool("desktop.unminimize")
s.UploadDrop = viper.GetBool("desktop.upload_drop")
s.FileChooserDialog = viper.GetBool("desktop.file_chooser_dialog") s.FileChooserDialog = viper.GetBool("desktop.file_chooser_dialog")
} }

View File

@ -62,3 +62,7 @@ func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
return false return false
} }
} }
func (manager *DesktopManagerCtx) IsUploadDropEnabled() bool {
return manager.config.UploadDrop
}

View File

@ -94,6 +94,7 @@ type DesktopManager interface {
// drop // drop
DropFiles(x int, y int, files []string) bool DropFiles(x int, y int, files []string) bool
IsUploadDropEnabled() bool
// filechooser // filechooser
HandleFileChooserDialog(uri string) error HandleFileChooserDialog(uri string) error