面包店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

68 lines
2.2 KiB

  1. package svc
  2. import (
  3. "applet/app/utils"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "strings"
  7. )
  8. // ImageFormat is 格式化 图片
  9. func ImageFormat(c *gin.Context, name string) string {
  10. if strings.Contains(name, "https:") || strings.Contains(name, "http:") {
  11. return name
  12. }
  13. scheme := SysCfgGet(c, "file_bucket_scheme")
  14. domain := SysCfgGet(c, "file_bucket_host")
  15. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  16. }
  17. // OffImageFormat is 格式化官方 图片
  18. func OffImageFormat(c *gin.Context, name string) string {
  19. if strings.Contains(name, "https:") || strings.Contains(name, "http:") {
  20. return name
  21. }
  22. return fmt.Sprintf("%s://%s/%s", "http", "ossq.izhyin.cn", name)
  23. }
  24. // ImageBucket is 获取域名
  25. func ImageBucket(c *gin.Context) (string, string) {
  26. return SysCfgGet(c, "file_bucket_scheme"), SysCfgGet(c, "file_bucket_host")
  27. }
  28. // ImageFormatWithBucket is 格式化成oss 域名
  29. func ImageFormatWithBucket(scheme, domain, name string) string {
  30. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  31. }
  32. // ImageBucketNew is 获取域名
  33. func ImageBucketNew(c *gin.Context) (string, string, string, map[string]string) {
  34. var list = make(map[string]string, 0)
  35. for i := 1; i < 10; i++ {
  36. keys := "file_bucket_sub_host" + utils.IntToStr(i)
  37. list[keys] = SysCfgGet(c, keys)
  38. }
  39. return SysCfgGet(c, "file_bucket_scheme"), SysCfgGet(c, "file_bucket_host"), SysCfgGet(c, "file_bucket_sub_host"), list
  40. }
  41. // ImageFormatWithBucket is 格式化成oss 域名
  42. func ImageFormatWithBucketNew(scheme, domain, subDomain string, moreSubDomain map[string]string, name string) string {
  43. if strings.Contains(name, "http") {
  44. return name
  45. }
  46. if strings.Contains(name, "{{subhost}}") && subDomain != "" { //读副域名 有可能是其他平台的
  47. domain = subDomain
  48. }
  49. //为了兼容一些客户自营商城导到不同系统 并且七牛云不一样
  50. for i := 1; i < 10; i++ {
  51. keys := "file_bucket_sub_host" + utils.IntToStr(i)
  52. if strings.Contains(name, "{{subhost"+utils.IntToStr(i)+"}}") && moreSubDomain[keys] != "" {
  53. domain = moreSubDomain[keys]
  54. }
  55. name = strings.ReplaceAll(name, "{{subhost"+utils.IntToStr(i)+"}}", "")
  56. }
  57. name = strings.ReplaceAll(name, "{{host}}", "")
  58. name = strings.ReplaceAll(name, "{{subhost}}", "")
  59. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  60. }