From b13fb6d1e696cdab2d8e7e01819e68b4a84d90ca Mon Sep 17 00:00:00 2001 From: Hiven Date: Mon, 7 Aug 2023 16:19:54 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/upload/internal/logic/uploadfilesbackendlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/upload/internal/logic/uploadfilesbackendlogic.go b/server/upload/internal/logic/uploadfilesbackendlogic.go index 9d30f2ae..e89c91aa 100644 --- a/server/upload/internal/logic/uploadfilesbackendlogic.go +++ b/server/upload/internal/logic/uploadfilesbackendlogic.go @@ -228,7 +228,7 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq, // 返回成功的响应和上传URL return resp.SetStatus(basic.CodeOK, map[string]interface{}{ - "upload_urls": result, + "upload_data": result, }) } From 55d39ab3035ea10f1fced26f0a0bb6e27102ca20 Mon Sep 17 00:00:00 2001 From: Hiven Date: Mon, 7 Aug 2023 16:45:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/upload/internal/logic/uploadlogologic.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index b5a4ede5..50415695 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -78,6 +78,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us logoHeight = 200 } var resultStr string + var err error // apiUrl := l.svcCtx.Config.BLMService.ImageProcess.Url // var onlyScale = true @@ -113,7 +114,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us var nowTime = time.Now().Unix() // 新增记录 userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) - _, err := userMaterialModel.CreateOrUpdate(l.ctx, &gmodel.FsUserMaterial{ + _, err = userMaterialModel.CreateOrUpdate(l.ctx, &gmodel.FsUserMaterial{ Module: &module, UserId: &userId, GuestId: &guestId, From e2e28805142d8095a178882d330203b787daa3a9 Mon Sep 17 00:00:00 2001 From: Hiven Date: Mon, 7 Aug 2023 17:10:09 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_product_template_v2_gen.go | 2 ++ model/gmodel/fs_resource_gen.go | 1 + model/gmodel/fs_user_material_gen.go | 2 +- .../internal/logic/uploadcallbacklogic.go | 26 +++++++++++++++++++ .../internal/logic/uploadfilebaselogic.go | 1 + .../internal/logic/uploadfilesbackendlogic.go | 1 + server/upload/internal/types/types.go | 11 ++++---- server_api/upload.api | 11 ++++---- 8 files changed, 44 insertions(+), 11 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_gen.go b/model/gmodel/fs_product_template_v2_gen.go index 62b8bce3..5e14427f 100644 --- a/model/gmodel/fs_product_template_v2_gen.go +++ b/model/gmodel/fs_product_template_v2_gen.go @@ -22,6 +22,8 @@ type FsProductTemplateV2 struct { Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 Tag *string `gorm:"default:'';" json:"tag"` // 标签(用户自填) IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除 + GroupOptions *string `gorm:"default:'';" json:"group_options"` // 颜色分组 + Version *int64 `gorm:"default:0;" json:"version"` // } type FsProductTemplateV2Model struct { db *gorm.DB diff --git a/model/gmodel/fs_resource_gen.go b/model/gmodel/fs_resource_gen.go index 4c7d2311..af635081 100644 --- a/model/gmodel/fs_resource_gen.go +++ b/model/gmodel/fs_resource_gen.go @@ -17,6 +17,7 @@ type FsResource struct { Metadata *string `gorm:"default:'';" json:"metadata"` // 元数据,json格式,存储图像分率 MetaKey1 *string `gorm:"index;default:'';" json:"meta_key1"` // 需要关键信息查询的自定义属性1,可以动态增加 ApiType *int64 `gorm:"default:1;" json:"api_type"` // 调用类型:1=对外,2=对内 + BucketName *string `gorm:"default:'';" json:"bucket_name"` // 存储桶名 } type FsResourceModel struct { db *gorm.DB diff --git a/model/gmodel/fs_user_material_gen.go b/model/gmodel/fs_user_material_gen.go index 5f880096..d5592001 100644 --- a/model/gmodel/fs_user_material_gen.go +++ b/model/gmodel/fs_user_material_gen.go @@ -7,7 +7,7 @@ import ( // fs_user_material 用户素材表 type FsUserMaterial struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 用户 ID - Module *string `gorm:"default:'';" json:"module"` // 所属模块 + Module *string `gorm:"default:'';" json:"module"` // 所属模块:logo UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户 ID GuestId *int64 `gorm:"index;default:0;" json:"guest_id"` // 游客 ID ResourceId *string `gorm:"default:'';" json:"resource_id"` // 资源ID diff --git a/server/upload/internal/logic/uploadcallbacklogic.go b/server/upload/internal/logic/uploadcallbacklogic.go index 7c15d85f..f4e8b8e7 100644 --- a/server/upload/internal/logic/uploadcallbacklogic.go +++ b/server/upload/internal/logic/uploadcallbacklogic.go @@ -41,6 +41,29 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null + var userId int64 + var guestId int64 + + // 检查用户是否是游客 + if userinfo.IsGuest() { + // 如果是,使用游客ID和游客键名格式 + guestId = userinfo.GuestId + } else { + // 否则,使用用户ID和用户键名格式 + userId = userinfo.UserId + } + + // 定义存储桶名称 + var bucketName *string + + // 根据类别选择存储桶 + switch req.UploadBucket { + case 2: + bucketName = basic.TempfileBucketName + default: + bucketName = basic.StorageBucketName + } + resourceModel := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn) err := resourceModel.Trans(l.ctx, func(ctx context.Context, connGorm *gorm.DB) (err error) { resourceModelTS := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn) @@ -50,11 +73,14 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri } var fsResource = &gmodel.FsResource{} + fsResource.UserId = &userId + fsResource.GuestId = &guestId fsResource.ResourceId = req.ResourceId fsResource.ResourceType = &req.ResourceType fsResource.ResourceUrl = &req.ResourceUrl fsResource.Metadata = &req.Metadata fsResource.ApiType = &req.ApiType + fsResource.BucketName = bucketName if resourceInfo.ResourceId == "" { _, err = resourceModelTS.Create(ctx, fsResource) } else { diff --git a/server/upload/internal/logic/uploadfilebaselogic.go b/server/upload/internal/logic/uploadfilebaselogic.go index 46c210c0..62912c02 100644 --- a/server/upload/internal/logic/uploadfilebaselogic.go +++ b/server/upload/internal/logic/uploadfilebaselogic.go @@ -140,6 +140,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri UploadedAt: &nowTime, Metadata: &req.Metadata, ApiType: &apiType, + BucketName: bucketName, }) if err != nil { logx.Error(err) diff --git a/server/upload/internal/logic/uploadfilesbackendlogic.go b/server/upload/internal/logic/uploadfilesbackendlogic.go index e89c91aa..ac7f0e40 100644 --- a/server/upload/internal/logic/uploadfilesbackendlogic.go +++ b/server/upload/internal/logic/uploadfilesbackendlogic.go @@ -195,6 +195,7 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq, UploadedAt: &nowTime, Metadata: &uploadDataInfo.Metadata, ApiType: &uploadDataInfo.ApiType, + BucketName: bucketName, }) if err != nil { logx.Error(err) diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index c967bf42..4f083802 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -36,11 +36,12 @@ type UploadFilesReq struct { } type UploadCallbackReq struct { - ResourceId string `form:"resource_id"` // 资源ID - ResourceType string `form:"resource_type"` // 资源类型 - ResourceUrl string `form:"resource_url"` // 资源URL - Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率 - ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 + UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 + ResourceId string `form:"resource_id"` // 资源ID + ResourceType string `form:"resource_type"` // 资源类型 + ResourceUrl string `form:"resource_url"` // 资源URL + Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率 + ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 } type RequestUpFile struct { diff --git a/server_api/upload.api b/server_api/upload.api index a94830be..a44c6aca 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -79,11 +79,12 @@ type ( UploadInfo string `form:"upload_info"` // 上传信息 json } UploadCallbackReq { - ResourceId string `form:"resource_id"` // 资源ID - ResourceType string `form:"resource_type"` // 资源类型 - ResourceUrl string `form:"resource_url"` // 资源URL - Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率 - ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 + UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 + ResourceId string `form:"resource_id"` // 资源ID + ResourceType string `form:"resource_type"` // 资源类型 + ResourceUrl string `form:"resource_url"` // 资源URL + Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率 + ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 } ) From 8b42c41bc5c3e7232ee47bc86465d1d0b826868b Mon Sep 17 00:00:00 2001 From: Hiven Date: Mon, 7 Aug 2023 17:12:01 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/upload/internal/logic/uploadcallbacklogic.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/upload/internal/logic/uploadcallbacklogic.go b/server/upload/internal/logic/uploadcallbacklogic.go index f4e8b8e7..a8b93eaf 100644 --- a/server/upload/internal/logic/uploadcallbacklogic.go +++ b/server/upload/internal/logic/uploadcallbacklogic.go @@ -72,6 +72,7 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri return err } + var version string = "0.0.1" var fsResource = &gmodel.FsResource{} fsResource.UserId = &userId fsResource.GuestId = &guestId @@ -81,6 +82,7 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri fsResource.Metadata = &req.Metadata fsResource.ApiType = &req.ApiType fsResource.BucketName = bucketName + fsResource.Version = &version if resourceInfo.ResourceId == "" { _, err = resourceModelTS.Create(ctx, fsResource) } else {