module_files_act_mkdir.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package modules
  2. import (
  3. "os"
  4. "strings"
  5. "golang-fave/engine/utils"
  6. "golang-fave/engine/wrapper"
  7. )
  8. func (this *Modules) RegisterAction_FilesMkdir() *Action {
  9. return this.newAction(AInfo{
  10. Mount: "files-mkdir",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_path := utils.Trim(wrap.R.FormValue("path"))
  14. pf_name := utils.Trim(wrap.R.FormValue("name"))
  15. if pf_path == "" {
  16. wrap.MsgError(`Please specify folder path`)
  17. return
  18. }
  19. if pf_name == "" {
  20. wrap.MsgError(`Please specify folder name`)
  21. return
  22. }
  23. dirname := utils.SafeFilePath(pf_path + pf_name)
  24. target := strings.Join([]string{wrap.DHtdocs, "public"}, string(os.PathSeparator)) + dirname
  25. if err := os.Mkdir(target, 0755); err != nil {
  26. emsg := err.Error()
  27. i := strings.Index(emsg, ":")
  28. if i != -1 {
  29. emsg = emsg[i+1:]
  30. }
  31. wrap.MsgError(emsg)
  32. return
  33. }
  34. path := "/"
  35. i := strings.LastIndex(dirname, string(os.PathSeparator))
  36. if i != -1 {
  37. path = dirname[:i+1]
  38. }
  39. // Set path
  40. wrap.Write(`$('#sys-modal-files-manager .dialog-path span').html('` + path + `');`)
  41. // Refresh table
  42. wrap.Write(`fave.FilesManagerLoadData('` + path + `');`)
  43. })
  44. }