feat: rbac完善,file接入完成
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"errors"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CheckFileByMd5Logic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCheckFileByMd5Logic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckFileByMd5Logic {
|
||||
return &CheckFileByMd5Logic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 通过MD5检查文件是否存在
|
||||
func (l *CheckFileByMd5Logic) CheckFileByMd5(in *file.CheckFileByMd5Req) (*file.CheckFileByMd5Resp, error) {
|
||||
if in.Md5 == "" {
|
||||
return &file.CheckFileByMd5Resp{Exists: false}, nil
|
||||
}
|
||||
|
||||
var ossRecord model.SundynixOss
|
||||
err := l.svcCtx.DB.Where("md5 = ?", in.Md5).First(&ossRecord).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return &file.CheckFileByMd5Resp{Exists: false}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &file.CheckFileByMd5Resp{
|
||||
Exists: true,
|
||||
File: &file.FileInfo{
|
||||
Id: ossRecord.ID,
|
||||
Name: ossRecord.Name,
|
||||
Url: ossRecord.Url,
|
||||
Tag: ossRecord.Tag,
|
||||
Key: ossRecord.Key,
|
||||
Suffix: ossRecord.Suffix,
|
||||
Md5: ossRecord.MD5,
|
||||
CreatedAt: ossRecord.CreatedAt.Unix(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type CreateFileLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateFileLogic {
|
||||
return &CreateFileLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 创建文件记录
|
||||
func (l *CreateFileLogic) CreateFile(in *file.CreateFileReq) (*file.CreateFileResp, error) {
|
||||
ossRecord := &model.SundynixOss{
|
||||
Name: in.Name,
|
||||
Url: in.Url,
|
||||
Tag: in.Tag,
|
||||
Key: in.Key,
|
||||
Suffix: in.Suffix,
|
||||
MD5: in.Md5,
|
||||
}
|
||||
|
||||
err := l.svcCtx.DB.Create(ossRecord).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &file.CreateFileResp{
|
||||
File: &file.FileInfo{
|
||||
Id: ossRecord.ID,
|
||||
Name: ossRecord.Name,
|
||||
Url: ossRecord.Url,
|
||||
Tag: ossRecord.Tag,
|
||||
Key: ossRecord.Key,
|
||||
Suffix: ossRecord.Suffix,
|
||||
Md5: ossRecord.MD5,
|
||||
CreatedAt: ossRecord.CreatedAt.Unix(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type CreateStorageConfigLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateStorageConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateStorageConfigLogic {
|
||||
return &CreateStorageConfigLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 存储配置 ----------
|
||||
func (l *CreateStorageConfigLogic) CreateStorageConfig(in *file.CreateStorageConfigReq) (*file.CommonResp, error) {
|
||||
conf := &model.StorageConfig{
|
||||
Type: in.Type,
|
||||
Name: in.Name,
|
||||
Endpoint: in.Endpoint,
|
||||
AccessKeyId: in.AccessKeyId,
|
||||
AccessKeySecret: in.AccessKeySecret,
|
||||
BucketName: in.BucketName,
|
||||
BucketUrl: in.BucketUrl,
|
||||
Region: in.Region,
|
||||
IsDefault: 0, // 默认不激活,除非通过 setDefault
|
||||
Status: int(in.Status),
|
||||
Remark: in.Remark,
|
||||
}
|
||||
|
||||
err := l.svcCtx.DB.Create(conf).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &file.CommonResp{Code: 0, Msg: "创建成功"}, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type DeleteFilesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteFilesLogic {
|
||||
return &DeleteFilesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 删除文件记录
|
||||
func (l *DeleteFilesLogic) DeleteFiles(in *file.DeleteFilesReq) (*file.CommonResp, error) {
|
||||
if len(in.Ids) == 0 {
|
||||
return &file.CommonResp{Code: 400, Msg: "ids不能为空"}, nil
|
||||
}
|
||||
|
||||
// 这里的删除只删数据库记录,真实文件的删除由 file-api 在调用这个 RPC 之前处理
|
||||
err := l.svcCtx.DB.Where("id IN ?", in.Ids).Delete(&model.SundynixOss{}).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &file.CommonResp{Code: 0, Msg: "删除成功"}, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type DeleteStorageConfigLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteStorageConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteStorageConfigLogic {
|
||||
return &DeleteStorageConfigLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteStorageConfigLogic) DeleteStorageConfig(in *file.DeleteFilesReq) (*file.CommonResp, error) {
|
||||
if len(in.Ids) == 0 {
|
||||
return &file.CommonResp{Code: 400, Msg: "ids不能为空"}, nil
|
||||
}
|
||||
err := l.svcCtx.DB.Where("id IN ?", in.Ids).Delete(&model.StorageConfig{}).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &file.CommonResp{Code: 0, Msg: "删除成功"}, nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type GetDefaultStorageConfigLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetDefaultStorageConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDefaultStorageConfigLogic {
|
||||
return &GetDefaultStorageConfigLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetDefaultStorageConfigLogic) GetDefaultStorageConfig(in *file.GetDefaultStorageConfigReq) (*file.GetDefaultStorageConfigResp, error) {
|
||||
conf := &model.StorageConfig{}
|
||||
err := l.svcCtx.DB.Where("is_default = ?", 1).First(conf).Error
|
||||
if err != nil {
|
||||
return nil, err // let the factory handle the error
|
||||
}
|
||||
|
||||
return &file.GetDefaultStorageConfigResp{
|
||||
Config: &file.StorageConfigInfo{
|
||||
Id: conf.ID,
|
||||
Type: conf.Type,
|
||||
Name: conf.Name,
|
||||
Endpoint: conf.Endpoint,
|
||||
AccessKeyId: conf.AccessKeyId,
|
||||
AccessKeySecret: conf.AccessKeySecret,
|
||||
BucketName: conf.BucketName,
|
||||
BucketUrl: conf.BucketUrl,
|
||||
Region: conf.Region,
|
||||
IsDefault: int32(conf.IsDefault),
|
||||
Status: int32(conf.Status),
|
||||
Remark: conf.Remark,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -3,14 +3,13 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
fileModel "sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"gorm.io/gorm"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type GetFileByIdLogic struct {
|
||||
@@ -29,7 +28,7 @@ func NewGetFileByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFi
|
||||
|
||||
// 根据ID获取文件信息
|
||||
func (l *GetFileByIdLogic) GetFileById(in *file.GetFileByIdReq) (*file.GetFileByIdResp, error) {
|
||||
var oss fileModel.SundynixOss
|
||||
var oss model.SundynixOss
|
||||
err := l.svcCtx.DB.Where("id = ?", in.Id).First(&oss).Error
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
@@ -44,7 +43,7 @@ func (l *GetFileByIdLogic) GetFileById(in *file.GetFileByIdReq) (*file.GetFileBy
|
||||
}, nil
|
||||
}
|
||||
|
||||
func convertOssToProto(oss *fileModel.SundynixOss) *file.FileInfo {
|
||||
func convertOssToProto(oss *model.SundynixOss) *file.FileInfo {
|
||||
return &file.FileInfo{
|
||||
Id: oss.ID,
|
||||
Name: oss.Name,
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type GetFileListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetFileListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileListLogic {
|
||||
return &GetFileListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 获取文件列表
|
||||
func (l *GetFileListLogic) GetFileList(in *file.GetFileListReq) (*file.GetFileListResp, error) {
|
||||
var list []model.SundynixOss
|
||||
var total int64
|
||||
|
||||
db := l.svcCtx.DB.Model(&model.SundynixOss{})
|
||||
if in.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+in.Name+"%")
|
||||
}
|
||||
|
||||
db.Count(&total)
|
||||
|
||||
if in.Current > 0 && in.PageSize > 0 {
|
||||
offset := (in.Current - 1) * in.PageSize
|
||||
db = db.Offset(int(offset)).Limit(int(in.PageSize))
|
||||
}
|
||||
|
||||
if err := db.Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var respList []*file.FileInfo
|
||||
for _, item := range list {
|
||||
respList = append(respList, &file.FileInfo{
|
||||
Id: item.ID,
|
||||
Name: item.Name,
|
||||
Url: item.Url,
|
||||
Tag: item.Tag,
|
||||
Key: item.Key,
|
||||
Suffix: item.Suffix,
|
||||
Md5: item.MD5,
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
return &file.GetFileListResp{
|
||||
List: respList,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
fileModel "sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type GetFilesByIdsLogic struct {
|
||||
@@ -32,7 +31,7 @@ func (l *GetFilesByIdsLogic) GetFilesByIds(in *file.GetFilesByIdsReq) (*file.Get
|
||||
return &file.GetFilesByIdsResp{Files: []*file.FileInfo{}}, nil
|
||||
}
|
||||
|
||||
var ossList []fileModel.SundynixOss
|
||||
var ossList []model.SundynixOss
|
||||
err := l.svcCtx.DB.Where("id IN ?", in.Ids).Find(&ossList).Error
|
||||
if err != nil {
|
||||
l.Errorf("批量查询文件失败: %v", err)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type GetStorageConfigListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetStorageConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStorageConfigListLogic {
|
||||
return &GetStorageConfigListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetStorageConfigListLogic) GetStorageConfigList(in *file.StorageConfigListReq) (*file.StorageConfigListResp, error) {
|
||||
var list []model.StorageConfig
|
||||
var total int64
|
||||
|
||||
db := l.svcCtx.DB.Model(&model.StorageConfig{})
|
||||
if in.Type != "" {
|
||||
db = db.Where("type = ?", in.Type)
|
||||
}
|
||||
if in.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+in.Name+"%")
|
||||
}
|
||||
|
||||
db.Count(&total)
|
||||
|
||||
if in.Current > 0 && in.PageSize > 0 {
|
||||
offset := (in.Current - 1) * in.PageSize
|
||||
db = db.Offset(int(offset)).Limit(int(in.PageSize))
|
||||
}
|
||||
|
||||
if err := db.Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var respList []*file.StorageConfigInfo
|
||||
for _, item := range list {
|
||||
respList = append(respList, &file.StorageConfigInfo{
|
||||
Id: item.ID,
|
||||
Type: item.Type,
|
||||
Name: item.Name,
|
||||
Endpoint: item.Endpoint,
|
||||
AccessKeyId: item.AccessKeyId,
|
||||
AccessKeySecret: item.AccessKeySecret,
|
||||
BucketName: item.BucketName,
|
||||
BucketUrl: item.BucketUrl,
|
||||
Region: item.Region,
|
||||
IsDefault: int32(item.IsDefault),
|
||||
Status: int32(item.Status),
|
||||
Remark: item.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
return &file.StorageConfigListResp{
|
||||
List: respList,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type SetDefaultStorageConfigLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSetDefaultStorageConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetDefaultStorageConfigLogic {
|
||||
return &SetDefaultStorageConfigLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SetDefaultStorageConfigLogic) SetDefaultStorageConfig(in *file.SetDefaultStorageConfigReq) (*file.CommonResp, error) {
|
||||
tx := l.svcCtx.DB.Begin()
|
||||
if err := tx.Model(&model.StorageConfig{}).Where("1 = 1").Update("is_default", 0).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
if err := tx.Model(&model.StorageConfig{}).Where("id = ?", in.Id).Update("is_default", 1).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
tx.Commit()
|
||||
|
||||
return &file.CommonResp{Code: 0, Msg: "设置成功"}, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type UpdateStorageConfigLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateStorageConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateStorageConfigLogic {
|
||||
return &UpdateStorageConfigLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateStorageConfigLogic) UpdateStorageConfig(in *file.UpdateStorageConfigReq) (*file.CommonResp, error) {
|
||||
conf := &model.StorageConfig{}
|
||||
if err := l.svcCtx.DB.Where("id = ?", in.Id).First(conf).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conf.Type = in.Type
|
||||
conf.Name = in.Name
|
||||
conf.Endpoint = in.Endpoint
|
||||
conf.AccessKeyId = in.AccessKeyId
|
||||
conf.AccessKeySecret = in.AccessKeySecret
|
||||
conf.BucketName = in.BucketName
|
||||
conf.BucketUrl = in.BucketUrl
|
||||
conf.Region = in.Region
|
||||
conf.Status = int(in.Status)
|
||||
conf.Remark = in.Remark
|
||||
|
||||
if err := l.svcCtx.DB.Save(conf).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &file.CommonResp{Code: 0, Msg: "更新成功"}, nil
|
||||
}
|
||||
@@ -34,3 +34,58 @@ func (s *FileServiceServer) GetFilesByIds(ctx context.Context, in *file.GetFiles
|
||||
l := logic.NewGetFilesByIdsLogic(ctx, s.svcCtx)
|
||||
return l.GetFilesByIds(in)
|
||||
}
|
||||
|
||||
// 创建文件记录
|
||||
func (s *FileServiceServer) CreateFile(ctx context.Context, in *file.CreateFileReq) (*file.CreateFileResp, error) {
|
||||
l := logic.NewCreateFileLogic(ctx, s.svcCtx)
|
||||
return l.CreateFile(in)
|
||||
}
|
||||
|
||||
// 通过MD5检查文件是否存在
|
||||
func (s *FileServiceServer) CheckFileByMd5(ctx context.Context, in *file.CheckFileByMd5Req) (*file.CheckFileByMd5Resp, error) {
|
||||
l := logic.NewCheckFileByMd5Logic(ctx, s.svcCtx)
|
||||
return l.CheckFileByMd5(in)
|
||||
}
|
||||
|
||||
// 删除文件记录
|
||||
func (s *FileServiceServer) DeleteFiles(ctx context.Context, in *file.DeleteFilesReq) (*file.CommonResp, error) {
|
||||
l := logic.NewDeleteFilesLogic(ctx, s.svcCtx)
|
||||
return l.DeleteFiles(in)
|
||||
}
|
||||
|
||||
// 获取文件列表
|
||||
func (s *FileServiceServer) GetFileList(ctx context.Context, in *file.GetFileListReq) (*file.GetFileListResp, error) {
|
||||
l := logic.NewGetFileListLogic(ctx, s.svcCtx)
|
||||
return l.GetFileList(in)
|
||||
}
|
||||
|
||||
// ---------- 存储配置 ----------
|
||||
func (s *FileServiceServer) CreateStorageConfig(ctx context.Context, in *file.CreateStorageConfigReq) (*file.CommonResp, error) {
|
||||
l := logic.NewCreateStorageConfigLogic(ctx, s.svcCtx)
|
||||
return l.CreateStorageConfig(in)
|
||||
}
|
||||
|
||||
func (s *FileServiceServer) UpdateStorageConfig(ctx context.Context, in *file.UpdateStorageConfigReq) (*file.CommonResp, error) {
|
||||
l := logic.NewUpdateStorageConfigLogic(ctx, s.svcCtx)
|
||||
return l.UpdateStorageConfig(in)
|
||||
}
|
||||
|
||||
func (s *FileServiceServer) DeleteStorageConfig(ctx context.Context, in *file.DeleteFilesReq) (*file.CommonResp, error) {
|
||||
l := logic.NewDeleteStorageConfigLogic(ctx, s.svcCtx)
|
||||
return l.DeleteStorageConfig(in)
|
||||
}
|
||||
|
||||
func (s *FileServiceServer) SetDefaultStorageConfig(ctx context.Context, in *file.SetDefaultStorageConfigReq) (*file.CommonResp, error) {
|
||||
l := logic.NewSetDefaultStorageConfigLogic(ctx, s.svcCtx)
|
||||
return l.SetDefaultStorageConfig(in)
|
||||
}
|
||||
|
||||
func (s *FileServiceServer) GetStorageConfigList(ctx context.Context, in *file.StorageConfigListReq) (*file.StorageConfigListResp, error) {
|
||||
l := logic.NewGetStorageConfigListLogic(ctx, s.svcCtx)
|
||||
return l.GetStorageConfigList(in)
|
||||
}
|
||||
|
||||
func (s *FileServiceServer) GetDefaultStorageConfig(ctx context.Context, in *file.GetDefaultStorageConfigReq) (*file.GetDefaultStorageConfigResp, error) {
|
||||
l := logic.NewGetDefaultStorageConfigLogic(ctx, s.svcCtx)
|
||||
return l.GetDefaultStorageConfig(in)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,10 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
panic(err)
|
||||
}
|
||||
// 自动迁移
|
||||
if err := db.AutoMigrate(&fileModel.SundynixOss{}); err != nil {
|
||||
if err := db.AutoMigrate(
|
||||
&fileModel.SundynixOss{},
|
||||
&fileModel.StorageConfig{},
|
||||
); err != nil {
|
||||
logx.Errorf("数据库迁移失败: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user