initial commit

This commit is contained in:
2025-05-22 19:39:08 +08:00
commit 531bb42d01
103 changed files with 10291 additions and 0 deletions

View File

@ -0,0 +1,57 @@
package logic
import (
"context"
"net/url"
"strings"
"time"
"godemo/file/file"
"godemo/file/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type GetFileUrlLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetFileUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileUrlLogic {
return &GetFileUrlLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 获取文件访问链接(带签名,防盗链)
func (l *GetFileUrlLogic) GetFileUrl(in *file.GetFileUrlRequest) (*file.GetFileUrlResponse, error) {
// 假设 fileId 格式为: "bucketName/objectName"
parts := strings.SplitN(in.FileId, "/", 2)
if len(parts) != 2 {
return nil, status.Error(codes.InvalidArgument, "invalid fileId format")
}
bucketName := parts[0]
objectName := parts[1]
// 生成预签名 URL有效期 1 小时
presignedUrl, err := l.svcCtx.MinioClient.PresignedGetObject(
l.ctx,
bucketName,
objectName,
time.Hour,
url.Values{},
)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &file.GetFileUrlResponse{
Url: presignedUrl.String(),
}, nil
}