fix:资源管理

This commit is contained in:
momo 2023-09-07 11:28:06 +08:00
parent 9462856ff9
commit ba0f1e1ba2
5 changed files with 31 additions and 14 deletions

View File

@ -23,6 +23,14 @@ type FsAdminMenu struct {
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除1=是 0=否
Status *int64 `gorm:"default:2;" json:"status"` // 状态:1=启用,2=停用
Type *int64 `gorm:"default:0;" json:"type"` // 类型1=菜单2=iframe3=外链4=按钮
Alias *string `gorm:"default:'';" json:"alias"` //
Icon *string `gorm:"default:'';" json:"icon"` //
Redirect *string `gorm:"default:'';" json:"redirect"` //
Highlight *string `gorm:"default:'';" json:"highlight"` //
View *string `gorm:"default:'';" json:"view"` //
Colour *string `gorm:"default:'';" json:"colour"` //
Label *int64 `gorm:"default:0;" json:"label"` // 整页路由1=是0=否
}
type FsAdminMenuModel struct {
db *gorm.DB

View File

@ -1,8 +1,9 @@
package gmodel
import (
"gorm.io/gorm"
"time"
"gorm.io/gorm"
)
// fs_resource 资源表
@ -14,8 +15,7 @@ type FsResource struct {
ResourceUrl *string `gorm:"default:'';" json:"resource_url"` // 资源 URL
Version *string `gorm:"index;default:'0';" json:"version"` // 版本信息
UploadedAt *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"uploaded_at"` //
Metadata *string `gorm:"default:'';" json:"metadata"` // 元数据,json格式,存储图像分率
MetaKey1 *string `gorm:"default:'';" json:"meta_key1"` // 需要关键信息查询的自定义属性1,可以动态增加
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
ApiType *int64 `gorm:"default:1;" json:"api_type"` // 调用类型1=对外2=对内
BucketName *string `gorm:"default:'';" json:"bucket_name"` // 存储桶名: 1=持久 2=缓存
Source *string `gorm:"default:'';" json:"source"` // 来源

View File

@ -40,7 +40,10 @@ func NewUploadCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
var metadataB []byte
if req.Metadata != "" {
metadataB = []byte(req.Metadata)
}
var userId int64
var guestId int64
@ -81,7 +84,7 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri
fsResource.ResourceId = req.ResourceId
fsResource.ResourceType = &req.ResourceType
fsResource.ResourceUrl = &req.ResourceUrl
fsResource.Metadata = &req.Metadata
fsResource.Metadata = &metadataB
fsResource.ApiType = &req.ApiType
fsResource.Source = &req.Source
fsResource.BucketName = bucketName

View File

@ -60,8 +60,7 @@ func (d *defaultResource) UpdateMetadata(ctx context.Context, in *UpdateMetadata
logc.Errorf(ctx, "FindOneByQuery oldResource error: %v", err)
return err
}
var newResourceMetadata string
if oldResource.Metadata != nil && *oldResource.Metadata != "{}" && *oldResource.Metadata != "" {
if oldResource.Metadata != nil {
var oldResourceMetadata map[string]interface{}
err = json.Unmarshal([]byte(*oldResource.Metadata), &oldResourceMetadata)
if err != nil {
@ -83,7 +82,7 @@ func (d *defaultResource) UpdateMetadata(ctx context.Context, in *UpdateMetadata
logc.Errorf(ctx, "Marshal oldResourceMetadata error: %v", err)
return err
}
newResourceMetadata = string(oldResourceMetadataB)
oldResource.Metadata = &oldResourceMetadataB
} else {
var resourceMetadata = make(map[string]interface{}, len(in.MetadataChild))
for k, v := range in.MetadataChild {
@ -101,9 +100,8 @@ func (d *defaultResource) UpdateMetadata(ctx context.Context, in *UpdateMetadata
logc.Errorf(ctx, "Marshal oldResourceMetadata error: %v", err)
return err
}
newResourceMetadata = string(newResourceMetadataB)
oldResource.Metadata = &newResourceMetadataB
}
oldResource.Metadata = &newResourceMetadata
_, err = NewFsResourceModel.BuilderUpdate(ctx, tx, oldResource)
if err != nil {
logc.Errorf(ctx, "Transaction UpdateMetadata error: %v", err)

View File

@ -45,6 +45,10 @@ type UploadBaseRes struct {
}
func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, error) {
var metadataB []byte
if req.Metadata != "" {
metadataB = []byte(req.Metadata)
}
// 定义存储桶名称
var bucketName *string
var apiType int64 = req.ApiType
@ -136,7 +140,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
Metadata: &metadataB,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,
@ -150,7 +154,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
Metadata: &metadataB,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,
@ -176,6 +180,10 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
}
func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, error) {
var metadataB []byte
if req.Metadata != "" {
metadataB = []byte(req.Metadata)
}
// 定义存储桶名称
var bucketName *string
var apiType int64 = req.ApiType
@ -261,7 +269,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
Metadata: &metadataB,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,
@ -275,7 +283,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
Metadata: &metadataB,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,