commit code
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 33s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 33s
This commit is contained in:
@ -23,4 +23,6 @@ CategoryRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
Key: category.rpc
|
||||
Key: category.rpc
|
||||
|
||||
BucketName: gallery
|
||||
@ -12,4 +12,5 @@ type Config struct {
|
||||
MaxIdleConns int
|
||||
ConnMaxLifetime int
|
||||
}
|
||||
BucketName string
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"godemo/gallery/internal/svc"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@ -45,17 +46,18 @@ func (l *UploadImageLogic) UploadImage(in *gallery.UploadImageRequest) (*gallery
|
||||
Filename: in.FileName,
|
||||
Content: in.FileContent,
|
||||
Folder: getFullCategoryRpcResp.FullCategoryName,
|
||||
Bucket: "gallery",
|
||||
Bucket: l.svcCtx.Config.BucketName,
|
||||
})
|
||||
if fileUploadRpcErr != nil {
|
||||
return nil, status.Error(codes.Internal, fileUploadRpcErr.Error())
|
||||
}
|
||||
|
||||
// 3. 图片信息存入数据库
|
||||
storageKey := l.svcCtx.Config.BucketName + "/" + fileUploadRpcResp.FileId
|
||||
insertResult, insertErr := l.svcCtx.ImagesModel.Insert(l.ctx, &model.Images{
|
||||
ImageId: uuid.New().String(),
|
||||
StorageKey: *in.Title,
|
||||
FileName: fileUploadRpcResp.FileId,
|
||||
StorageKey: storageKey,
|
||||
FileName: *in.Title,
|
||||
MimeType: "image/jpeg",
|
||||
FileSize: 10,
|
||||
CategoryId: sql.NullString{String: *in.CategoryId, Valid: true},
|
||||
@ -63,9 +65,17 @@ func (l *UploadImageLogic) UploadImage(in *gallery.UploadImageRequest) (*gallery
|
||||
if insertErr != nil {
|
||||
return nil, status.Error(codes.Internal, insertErr.Error())
|
||||
}
|
||||
logc.Infof(l.ctx, "insertResult: %v", insertResult)
|
||||
|
||||
print(insertResult.LastInsertId())
|
||||
// 4. 调用 file rpc GenerateImageVersions 接口,生成缩略图和预览图 (异步)
|
||||
_, generateImageVersionsRpcErr := l.svcCtx.FileRpc.GenerateImageVersions(l.ctx, &file.GenerateImageVersionsRequest{
|
||||
FileId: storageKey,
|
||||
Versions: []file.ImageVersion{file.ImageVersion_thumbnail, file.ImageVersion_preview},
|
||||
})
|
||||
if generateImageVersionsRpcErr != nil {
|
||||
return nil, status.Error(codes.Internal, generateImageVersionsRpcErr.Error())
|
||||
}
|
||||
|
||||
// 4. 返回接口执行结果
|
||||
// 5. 返回接口执行结果
|
||||
return &gallery.UploadImageResponse{}, nil
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@ CREATE TABLE images (
|
||||
image_id VARCHAR(36) PRIMARY KEY DEFAULT gen_random_uuid()::varchar,
|
||||
|
||||
-- 存储元数据
|
||||
storage_key TEXT NOT NULL, -- 文件显示名称
|
||||
file_name TEXT NOT NULL, -- 文件存储名称,可以包含路径
|
||||
storage_key TEXT NOT NULL, -- 文件存储标识。 bucket/object_id
|
||||
file_name TEXT NOT NULL, -- 文件显示名称
|
||||
mime_type VARCHAR(32) NOT NULL CHECK (mime_type LIKE 'image/%'),
|
||||
file_size BIGINT NOT NULL CHECK (file_size > 0),
|
||||
width INT CHECK (width > 0),
|
||||
|
||||
Reference in New Issue
Block a user