12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package logic
- import (
- "context"
- "errors"
- "fmt"
- "strings"
- "app.yhyue.com/moapp/jyfs/rpc/filesystem"
- "app.yhyue.com/moapp/jyfs/rpc/internal/redis"
- "app.yhyue.com/moapp/jyfs/rpc/internal/svc"
- "github.com/aliyun/aliyun-oss-go-sdk/oss"
- "github.com/tal-tech/go-zero/core/logx"
- )
- type UpdateFileMetaLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewUpdateFileMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateFileMetaLogic {
- return &UpdateFileMetaLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 更新文件元数据
- func (l *UpdateFileMetaLogic) UpdateFileMeta(in *filesystem.UpdateFileMetaReq) (*filesystem.FileOpResp, error) {
- // todo: add your logic here and delete this line
- // 获取存储空间。
- bucket, err := l.svcCtx.OssClient.Bucket(in.Domain)
- if err != nil {
- return &filesystem.FileOpResp{}, err
- }
- meta := redis.GetStr("jyfs", "jyfs_"+in.Domain)
- if meta != "" {
- for k, _ := range in.Meta {
- if !strings.Contains(meta, k) {
- return &filesystem.FileOpResp{}, errors.New("缺少元信息")
- }
- }
- }
- // 一次修改多条元信息。
- options := []oss.Option{
- // oss.Meta("MyMeta", "MyMetaValue2"),
- // oss.Meta("MyObjectLocation", "HangZhou"),
- }
- for k, v := range in.Meta {
- options = append(options, oss.Meta(k, v))
- }
- err = bucket.SetObjectMeta(in.FileId, options...)
- if err != nil {
- return &filesystem.FileOpResp{State: false}, err
- }
- // 获取文件元信息。
- props, err := bucket.GetObjectDetailedMeta(in.FileId)
- if err != nil {
- return &filesystem.FileOpResp{}, err
- }
- fmt.Println("Object Meta:", props)
- return &filesystem.FileOpResp{State: true}, nil
- }
|