Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-09-22 16:27:21 +08:00
commit b398da58e1
10 changed files with 118 additions and 48 deletions

2
go.mod
View File

@ -18,7 +18,7 @@ require (
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/streadway/amqp v1.1.0
github.com/stripe/stripe-go/v74 v74.26.0
github.com/stripe/stripe-go/v74 v74.30.0
github.com/zeromicro/go-zero v1.5.4
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
golang.org/x/oauth2 v0.10.0

7
go.sum
View File

@ -83,6 +83,7 @@ github.com/aws/aws-sdk-go v1.44.295 h1:SGjU1+MqttXfRiWHD6WU0DRhaanJgAFY+xIhEaugV
github.com/aws/aws-sdk-go v1.44.295/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@ -183,6 +184,7 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@ -344,6 +346,7 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
@ -356,6 +359,7 @@ github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0b
github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk=
@ -434,6 +438,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3 h1:sUQx4f1bXDeeOOEQZjGAitzxYApbYY9fVDbxVCaBW+I=
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3/go.mod h1:UL4U89WYdnyajgKJUMpuT1Rr6iNmbjrxOO40JRgtA00=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
@ -550,6 +555,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stripe/stripe-go/v74 v74.26.0 h1:enbhLtjKGWvJKcGM0f2CazqFSXzpHXcQ42nG2PNsWK0=
github.com/stripe/stripe-go/v74 v74.26.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw=
github.com/stripe/stripe-go/v74 v74.30.0 h1:0Kf0KkeFnY7iRhOwvTerX0Ia1BRw+eV1CVJ51mGYAUY=
github.com/stripe/stripe-go/v74 v74.30.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw=
github.com/tidwall/gjson v1.12.0 h1:61wEp/qfvFnqKH/WCI3M8HuRut+mHT6Mr82QrFmM2SY=
github.com/tidwall/gjson v1.12.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=

View File

@ -9,6 +9,7 @@ import (
"fusenapi/utils/fssql"
"time"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
@ -152,14 +153,21 @@ type SubscriptionStatus struct {
} `json:"item_map"`
}
// UserProfile 个人信息
type UserAddress struct {
}
type UserProfile struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Resetaurant string `json:"resetaurant"`
ProfileBase UserProfileBase `json:"base"`
SubStatus SubscriptionStatus `json:"sub_status"`
}
// UserProfileBase 个人信息
type UserProfileBase struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Resetaurant string `json:"resetaurant"`
}
// 自平台的注册流程
func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterToken) (user *FsUser, err error) {
@ -189,11 +197,16 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
// 继承guest_id的资源表
err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error {
userProfile := &UserProfile{
userProfileBase := UserProfileBase{
FirstName: FirstName,
LastName: LastName,
Resetaurant: Resetaurant,
}
userProfile := &UserProfile{
ProfileBase: userProfileBase,
}
metadata, err := json.Marshal(userProfile)
if err != nil {
return err
@ -209,6 +222,8 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
Utime: &now,
}
logx.Error(metadata)
err = txUserInfo.Where("module = 'profile' and user_id = ?", *uinfo.UserId).Take(nil).Error
if err != nil {
if err == gorm.ErrRecordNotFound {

View File

@ -31,9 +31,9 @@ run_server() {
# 导航到相应的目录
cd server/$server_name
go build
echo "build $server_name"
go build
# 如果之前存在相同名字的 screen 会话,先将其终止
# 首先尝试关闭已存在的screen会话
existing_session=$(screen -ls | grep -w "$server_name")

View File

@ -6,7 +6,6 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/check"
"log"
"strings"
"context"
@ -100,6 +99,18 @@ func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string
if err == gorm.ErrRecordNotFound {
logx.Error(err)
}
if v, ok := info[queryAsName]; ok {
var qinfo map[string]any
err := json.Unmarshal([]byte(v.(string)), &qinfo)
if err != nil {
logx.Error(err)
} else {
info[queryAsName] = qinfo
}
}
return info
}
@ -203,10 +214,9 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
if v, ok := metadict["userinfo.profile"]; ok {
if v == nil {
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
log.Println(info)
metadict["userinfo.profile"] = info
// log.Println(metadict)
} else {
profileDict := v.(map[string]any)
if _, ok := profileDict["logo_selected"]; !ok {
@ -220,11 +230,50 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
metadict["userinfo.profile.logo_selected"] = info
}
} else {
var info map[string]any
for k, v := range metadict {
if v == nil {
if strings.HasPrefix(k, "userinfo.profile.logo_selected") {
if info == nil {
info = QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
}
curValue, err := GetMapValueByKey(info, strings.Split(k, ".")[2:])
if err != nil {
logx.Error(err, info)
continue
// return resp.SetStatus(basic.CodeOK, metadict)
}
metadict[k] = curValue
// curValue
}
}
}
}
return resp.SetStatus(basic.CodeOK, metadict)
}
func GetMapValueByKey(info map[string]interface{}, keys []string) (interface{}, error) {
// keys := strings.Split(key, ".")[2:]
for _, k := range keys {
if cur, ok := info[k]; ok {
if curMap, ok := cur.(map[string]interface{}); ok {
info = curMap
} else {
// logx.Error(cur)
return cur, nil
}
} else {
return nil, fmt.Errorf("info keys is not exists %#v", keys)
}
}
return info, nil
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *InfoLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)

View File

@ -115,9 +115,9 @@ func TestMain(t *testing.T) {
if v, ok := metadict["userinfo.profile"]; ok {
if v == nil {
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
metadict["userinfo.profile"] = info
// log.Println(metadict)
} else {
profileDict := v.(map[string]any)
if _, ok := profileDict["logo_selected"]; !ok {
@ -131,37 +131,33 @@ func TestMain(t *testing.T) {
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
metadict["userinfo.profile.logo_selected"] = info
}
} else {
var info map[string]any
for k, v := range metadict {
if v == nil {
if strings.HasPrefix(k, "userinfo.profile.logo_selected") {
if info == nil {
info = QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
}
curValue, err := GetMapValueByKey(info, strings.Split(k, ".")[2:])
if err != nil {
logx.Error(err, info)
continue
// return resp.SetStatus(basic.CodeOK, metadict)
}
metadict[k] = curValue
// curValue
}
}
}
}
}
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {
qname := strings.Split(moduleQuery, ".")
queryAsName := qname[len(qname)-1]
sqlstr := fmt.Sprintf(
"select JSON_EXTRACT(metadata,'$.%s') as %s from %s where module = '%s' and user_id = 0 and guest_id = 0 order by ctime DESC limit 1",
moduleQuery, // logo_selected
queryAsName, // logo_selected
tname, // fs_user_info
module, // profile
)
raw := conn.Raw(sqlstr)
var info map[string]any
err := raw.Scan(&info).Error
if err == gorm.ErrRecordNotFound {
logx.Error(err)
}
return info
}
func TestCaseJSON_EXTRACT(t *testing.T) {
userProfile := &gmodel.UserProfile{
FirstName: "FirstName",
LastName: "LastName",
Resetaurant: "Resetaurant",
}
userProfile := &gmodel.UserProfile{}
metadata, err := json.Marshal(userProfile)
if err != nil {
panic(err)

View File

@ -67,9 +67,9 @@ var (
//websocket连接存储
mapConnPool = sync.Map{}
//每个websocket连接入口缓冲队列长度默认值
websocketInChanLen = 1000
websocketInChanLen = 2000
//每个websocket连接出口缓冲队列长度默认值
websocketOutChanLen = 1000
websocketOutChanLen = 2000
//是否开启debug
openDebug = true
//允许跨域的origin

View File

@ -23,7 +23,7 @@ var (
//每个websocket渲染任务缓冲队列长度默认值
renderChanLen = 500
//每个websocket渲染并发数
renderChanConcurrency = 100
renderChanConcurrency = 1
)
// 渲染处理器
@ -37,7 +37,7 @@ type extendRenderProperty struct {
// 处理分发到这里的数据
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
//logx.Info("开始处理渲染任务消息:", string(data))
logx.Info("收到渲染任务消息")
var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
@ -49,6 +49,9 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
return
case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列
return
case <-time.After(time.Millisecond * 50): //超过50毫秒丢弃
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染队列溢出,请稍后再发", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return
}
}
@ -56,7 +59,7 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
func (w *wsConnectItem) consumeRenderImageData() {
defer func() {
if err := recover(); err != nil {
logx.Error("func consumeRenderImageData err:", err)
logx.Error("func consumeRenderImageData panic:", err)
}
}()
//限制并发
@ -67,11 +70,13 @@ func (w *wsConnectItem) consumeRenderImageData() {
case <-w.closeChan: //已关闭
return
case data := <-w.extendRenderProperty.renderChan: //消费数据
logx.Info("准备执行任务。。。。。")
limitChan <- struct{}{}
logx.Info("执行任务中。。。。。")
go func(d websocket_data.RenderImageReqMsg) {
defer func() {
if err := recover(); err != nil {
logx.Error("func renderImage err:", err)
logx.Error("func renderImage panic:", err)
}
}()
defer func() {
@ -202,6 +207,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
logx.Error("failed to find render resource:", err)
return
}
logx.Info("无缓存的渲染图需要unity")
} else {
//返回给客户端
w.sendRenderResultData(websocket_data.RenderImageRspMsg{

View File

@ -318,7 +318,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
err = curl.NewClient(ctx, &curl.Config{
BaseUrl: *l.BLMServiceUrl,
Url: constants.BLMServiceUrlLogoCombine,
RequireTimeout: time.Second * 30,
RequireTimeout: time.Second * 15,
}).PostJson(postMap, &resultBLM)
logc.Infof(ctx, "合图--算法请求--合图--结束时间:%v", time.Now().UTC())

View File

@ -8,10 +8,7 @@ import (
)
func TestCase1(t *testing.T) {
u := gmodel.UserProfile{
FirstName: "h",
LastName: "sm",
}
u := gmodel.UserProfile{}
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
err := fssql.MetadataModulePATCH(conn, "profile", gmodel.FsUserInfo{}, u, "id = ?", 90)