bfs.go 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package bfs
  2. import (
  3. "bytes"
  4. "context"
  5. "go-common/app/admin/main/feed/conf"
  6. bfsdao "go-common/app/admin/main/feed/dao/bfs"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. // Service bfs service.
  11. type Service struct {
  12. dao *bfsdao.Dao
  13. BfsMaxSize int
  14. }
  15. // New new a bfs service.
  16. func New(c *conf.Config) (s *Service) {
  17. s = &Service{
  18. dao: bfsdao.New(c),
  19. BfsMaxSize: c.Bfs.MaxFileSize,
  20. }
  21. return
  22. }
  23. // ClientUpCover client upload cover.
  24. func (s *Service) ClientUpCover(c context.Context, fileType string, body []byte) (url string, err error) {
  25. if len(body) == 0 {
  26. err = ecode.FileNotExists
  27. return
  28. }
  29. if len(body) > s.BfsMaxSize {
  30. err = ecode.FileTooLarge
  31. return
  32. }
  33. url, err = s.dao.Upload(c, fileType, bytes.NewReader(body))
  34. if err != nil {
  35. log.Error("s.bfs.Upload error(%v)", err)
  36. }
  37. return
  38. }
  39. // FileMd5 is used for calculating file md5.
  40. func (s *Service) FileMd5(content []byte) (md5Str string, err error) {
  41. return s.dao.FileMd5(content)
  42. }