getfilemetalogic.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package logic
  2. import (
  3. "context"
  4. "strings"
  5. "app.yhyue.com/moapp/jyfs/rpc/internal/redis"
  6. "fmt"
  7. "app.yhyue.com/moapp/jyfs/rpc/filesystem"
  8. "app.yhyue.com/moapp/jyfs/rpc/internal/svc"
  9. "github.com/tal-tech/go-zero/core/logx"
  10. )
  11. type GetFileMetaLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewGetFileMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileMetaLogic {
  17. return &GetFileMetaLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 获取文件元数据
  24. func (l *GetFileMetaLogic) GetFileMeta(in *filesystem.LoadFileReq) (*filesystem.LoadFileMetaResp, error) {
  25. // todo: add your logic here and delete this line
  26. // // 获取存储空间。
  27. bucket, err := l.svcCtx.OssClient.Bucket(in.Domain)
  28. if err != nil {
  29. return &filesystem.LoadFileMetaResp{}, err
  30. }
  31. // 获取文件元信息。
  32. props, err := bucket.GetObjectDetailedMeta(in.FileId)
  33. if err != nil {
  34. return &filesystem.LoadFileMetaResp{}, err
  35. }
  36. fmt.Println("Object Meta:", props)
  37. for k, v := range props {
  38. vs := strings.Join(v, ",")
  39. props[k] = vs
  40. }
  41. return &filesystem.LoadFileMetaResp{Meta: props}, nil
  42. }