diff --git a/goctl_template/api/context.tpl b/goctl_template/api/context.tpl index e5884b34..fdf46361 100644 --- a/goctl_template/api/context.tpl +++ b/goctl_template/api/context.tpl @@ -22,7 +22,6 @@ type ServiceContext struct { } func NewServiceContext(c {{.config}}) *ServiceContext { - initalize.InitRabbitMq(c.SourceRabbitMq, nil) return &ServiceContext{ Config: c, MysqlConn: initalize.InitMysql(c.SourceMysql), diff --git a/server/render/etc/render.yaml b/server/render/etc/render.yaml index d0f93153..86b2a6a1 100644 --- a/server/render/etc/render.yaml +++ b/server/render/etc/render.yaml @@ -6,4 +6,10 @@ Auth: AccessSecret: fusen2023 AccessExpire: 2592000 RefreshAfter: 1592000 -SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 \ No newline at end of file +SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 +AWS: + S3: + Credentials: + AccessKeyID: AKIAZB2JKUXDPNRP4YT2 + Secret: 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 + Token: \ No newline at end of file diff --git a/server/render/internal/config/config.go b/server/render/internal/config/config.go index fa950a01..71834c5d 100644 --- a/server/render/internal/config/config.go +++ b/server/render/internal/config/config.go @@ -10,4 +10,13 @@ type Config struct { SourceMysql string Auth types.Auth SourceRabbitMq string + AWS struct { + S3 struct { + Credentials struct { + AccessKeyID string + Secret string + Token string + } + } + } } diff --git a/server/render/internal/logic/rendernotifylogic.go b/server/render/internal/logic/rendernotifylogic.go index b3466aaa..6a11f4bf 100644 --- a/server/render/internal/logic/rendernotifylogic.go +++ b/server/render/internal/logic/rendernotifylogic.go @@ -6,6 +6,7 @@ import ( "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/file" "fusenapi/utils/websocket_data" "fusenapi/server/render/internal/svc" @@ -62,15 +63,31 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a if req.Sign != sign { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign") }*/ - //创建/更新资源 - + // 上传文件 + var upload = file.Upload{ + Ctx: l.ctx, + MysqlConn: l.svcCtx.MysqlConn, + AwsSession: l.svcCtx.AwsSession, + } + uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ + FileHash: req.Info.TaskId, + FileData: req.Info.Image, + UploadBucket: 1, + ApiType: 2, + UserId: req.Info.UserId, + GuestId: req.Info.GuestId, + }) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image") + } //发送消息到对应的rabbitmq data := websocket_data.RenderImageNotify{ TaskId: req.Info.TaskId, - Image: req.Info.Image, + Image: uploadRes.ResourceUrl, } d, _ := json.Marshal(data) - if err := l.svcCtx.RabbitMq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil { + if err = l.svcCtx.RabbitMq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil { logx.Error(err) return resp.SetStatus(basic.CodeServiceErr, "failed to send data") } diff --git a/server/render/internal/svc/servicecontext.go b/server/render/internal/svc/servicecontext.go index 79e04e0d..08a78653 100644 --- a/server/render/internal/svc/servicecontext.go +++ b/server/render/internal/svc/servicecontext.go @@ -4,6 +4,9 @@ import ( "errors" "fmt" "fusenapi/server/render/internal/config" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/session" "net/http" "fusenapi/initalize" @@ -14,20 +17,23 @@ import ( ) type ServiceContext struct { - Config config.Config - - MysqlConn *gorm.DB - AllModels *gmodel.AllModelsGen - RabbitMq *initalize.RabbitMqHandle + Config config.Config + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen + RabbitMq *initalize.RabbitMqHandle + AwsSession *session.Session } func NewServiceContext(c config.Config) *ServiceContext { - initalize.InitRabbitMq(c.SourceRabbitMq, nil) + config := aws.Config{ + Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token), + } return &ServiceContext{ - Config: c, - MysqlConn: initalize.InitMysql(c.SourceMysql), - AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), - RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), + Config: c, + MysqlConn: initalize.InitMysql(c.SourceMysql), + AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), + RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), + AwsSession: session.Must(session.NewSession(&config)), } } diff --git a/server/resource/internal/svc/servicecontext.go b/server/resource/internal/svc/servicecontext.go index f4b7039e..a81a0767 100644 --- a/server/resource/internal/svc/servicecontext.go +++ b/server/resource/internal/svc/servicecontext.go @@ -29,7 +29,6 @@ func NewServiceContext(c config.Config) *ServiceContext { config := aws.Config{ Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token), } - initalize.InitRabbitMq(c.SourceRabbitMq, nil) return &ServiceContext{ Config: c, MysqlConn: initalize.InitMysql(c.SourceMysql), diff --git a/server/websocket/internal/svc/servicecontext.go b/server/websocket/internal/svc/servicecontext.go index 3ca743ec..df41e0b3 100644 --- a/server/websocket/internal/svc/servicecontext.go +++ b/server/websocket/internal/svc/servicecontext.go @@ -22,7 +22,6 @@ type ServiceContext struct { } func NewServiceContext(c config.Config) *ServiceContext { - initalize.InitRabbitMq(c.SourceRabbitMq, nil) return &ServiceContext{ Config: c, MysqlConn: initalize.InitMysql(c.SourceMysql),