面包店
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.

svc_file_img_format.go 2.3 KiB

9 月之前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package svc
  2. import (
  3. "applet/app/utils"
  4. "fmt"
  5. "strings"
  6. "github.com/gin-gonic/gin"
  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. // ImageBucketNew is 获取域名
  29. func ImageBucketNew(c *gin.Context) (string, string, string, map[string]string) {
  30. var list = make(map[string]string, 0)
  31. for i := 1; i < 10; i++ {
  32. keys := "file_bucket_sub_host" + utils.IntToStr(i)
  33. list[keys] = SysCfgGet(c, keys)
  34. }
  35. return SysCfgGet(c, "file_bucket_scheme"), SysCfgGet(c, "file_bucket_host"), SysCfgGet(c, "file_bucket_sub_host"), list
  36. }
  37. // ImageFormatWithBucket is 格式化成oss 域名
  38. func ImageFormatWithBucket(scheme, domain, name string) string {
  39. if strings.Contains(name, "http") {
  40. return name
  41. }
  42. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  43. }
  44. // ImageFormatWithBucket is 格式化成oss 域名
  45. func ImageFormatWithBucketNew(scheme, domain, subDomain string, moreSubDomain map[string]string, name string) string {
  46. if strings.Contains(name, "http") {
  47. return name
  48. }
  49. if strings.Contains(name, "{{subhost}}") && subDomain != "" { //读副域名 有可能是其他平台的
  50. domain = subDomain
  51. }
  52. //为了兼容一些客户自营商城导到不同系统 并且七牛云不一样
  53. for i := 1; i < 10; i++ {
  54. keys := "file_bucket_sub_host" + utils.IntToStr(i)
  55. if strings.Contains(name, "{{subhost"+utils.IntToStr(i)+"}}") && moreSubDomain[keys] != "" {
  56. domain = moreSubDomain[keys]
  57. }
  58. name = strings.ReplaceAll(name, "{{subhost"+utils.IntToStr(i)+"}}", "")
  59. }
  60. name = strings.ReplaceAll(name, "{{host}}", "")
  61. name = strings.ReplaceAll(name, "{{subhost}}", "")
  62. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  63. }