module_templates_act_restore_file_all.go 789 B

123456789101112131415161718192021222324252627282930313233343536
  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_TemplatesRestoreFileAll() *Action {
  10. return this.newAction(AInfo{
  11. Mount: "templates-restore-file-all",
  12. WantAdmin: true,
  13. }, func(wrap *wrapper.Wrapper) {
  14. pf_file := utils.Trim(wrap.R.FormValue("file"))
  15. if pf_file != "all" {
  16. wrap.MsgError(`Inner system error`)
  17. return
  18. }
  19. for file, data := range ThemeFiles.AllData {
  20. if err := ioutil.WriteFile(wrap.DTemplate+string(os.PathSeparator)+file, data, 0664); err != nil {
  21. wrap.MsgError(err.Error())
  22. return
  23. }
  24. }
  25. wrap.ResetCacheBlocks()
  26. // Reload current page
  27. wrap.Write(`window.location.reload(false);`)
  28. })
  29. }