Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
upload drop to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Nov 24, 2023
1 parent b40c077 commit 3dbcc41
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/api/room/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions internal/config/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Desktop struct {
InputSocket string

Unminimize bool
UploadDrop bool
FileChooserDialog bool
}

Expand All @@ -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
Expand Down Expand Up @@ -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")
}
4 changes: 4 additions & 0 deletions internal/desktop/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/types/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type DesktopManager interface {

// drop
DropFiles(x int, y int, files []string) bool
IsUploadDropEnabled() bool

// filechooser
HandleFileChooserDialog(uri string) error
Expand Down

0 comments on commit 3dbcc41

Please sign in to comment.