module_templates_act_restore_file.go 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package modules
  2. import (
  3. "io/ioutil"
  4. "os"
  5. ThemeFiles "golang-fave/engine/assets/template"
  6. "golang-fave/engine/utils"
  7. "golang-fave/engine/wrapper"
  8. )
  9. func (this *Modules) RegisterAction_TemplatesRestoreFile() *Action {
  10. return this.newAction(AInfo{
  11. Mount: "templates-restore-file",
  12. WantAdmin: true,
  13. }, func(wrap *wrapper.Wrapper) {
  14. pf_file := utils.Trim(wrap.R.FormValue("file"))
  15. if pf_file == "" {
  16. wrap.MsgError(`Please specify file name`)
  17. return
  18. }
  19. if _, ok := ThemeFiles.AllData[pf_file]; !ok {
  20. wrap.MsgError(`Template file is not defined in engine`)
  21. return
  22. }
  23. // Restore file content
  24. err := ioutil.WriteFile(wrap.DTemplate+string(os.PathSeparator)+pf_file, ThemeFiles.AllData[pf_file], 0664)
  25. if err != nil {
  26. wrap.MsgError(err.Error())
  27. return
  28. }
  29. wrap.ResetCacheBlocks()
  30. // Reload current page
  31. wrap.Write(`window.location.reload(false);`)
  32. })
  33. }