sso

ueditor_controller.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "log"
  7. "os"
  8. "regexp"
  9. "SSO/enums"
  10. "SSO/service"
  11. )
  12. type UeditorController struct {
  13. BaseController
  14. }
  15. //处理百度富文本配置文件,如果不加上这些处理,无法上传图片
  16. func (this *UeditorController) GetUeditorConfig() {
  17. op := this.Input().Get("action")
  18. switch op {
  19. case "config":
  20. file, err := os.Open("conf/config.json")
  21. if err != nil {
  22. log.Fatal(err)
  23. os.Exit(1)
  24. }
  25. defer file.Close()
  26. fd, err := ioutil.ReadAll(file)
  27. src := string(fd)
  28. re, _ := regexp.Compile("\\/\\*[\\S\\s]+?\\*\\/")
  29. src = re.ReplaceAllString(src, "")
  30. tt := []byte(src)
  31. var r interface{}
  32. json.Unmarshal(tt, &r)
  33. this.Data["json"] = r
  34. this.ServeJSON()
  35. }
  36. }
  37. func (this *UeditorController) GetQNToken() {
  38. redisClient := service.RedisClient()
  39. defer redisClient.Close()
  40. token, err := redisClient.Get("qn_token").Result()
  41. if err == nil {
  42. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  43. "token": token,
  44. })
  45. this.ServeJSON()
  46. } else {
  47. fmt.Println("redis获取七牛token错误: ", err.Error())
  48. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  49. this.ServeJSON()
  50. }
  51. }