utils.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package oss_utils
  2. import (
  3. "context"
  4. "property-household/parser"
  5. "property-household/pb"
  6. pb_v1 "property-household/pb/v1"
  7. "regexp"
  8. "strings"
  9. )
  10. func IsFix(src string) bool {
  11. if strings.Contains(src, parser.Conf.Oss.RentObj) || strings.Contains(src, parser.Conf.Oss.EventObj) ||
  12. strings.Contains(src, parser.Conf.Oss.VoteObj) {
  13. return true
  14. }
  15. return false
  16. }
  17. func GetObjFromText(text string) []string {
  18. rule := "img src=\".*?\""
  19. reg, _ := regexp.Compile(rule)
  20. result := reg.FindAllStringSubmatch(text, -1)
  21. if len(result) == 0 {
  22. return []string{}
  23. }
  24. ret := []string{}
  25. key := "img src=\""
  26. keyLength := len(key)
  27. for _, array := range result {
  28. if len(array) == 0 {
  29. continue
  30. }
  31. str := array[0]
  32. if len(str) < keyLength+1 {
  33. continue
  34. }
  35. str = str[keyLength:]
  36. str = str[:len(str)-1]
  37. ret = append(ret, str)
  38. }
  39. return ret
  40. }
  41. func OssObjAdd(inList []string, outList []string) error {
  42. mreq := pb_v1.OssObjAddRequest{InList: inList, OutList: outList}
  43. _, err := pb.Common.OssObjAdd(context.Background(), &mreq)
  44. return err
  45. }