Skip to content

Commit

Permalink
Merge pull request #24 from mylxsw/develop
Browse files Browse the repository at this point in the history
v1.0.7
  • Loading branch information
mylxsw authored Oct 29, 2023
2 parents 283b16a + 48e4a3b commit e1a961c
Show file tree
Hide file tree
Showing 133 changed files with 8,739 additions and 2,164 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ README.md
LICENSE
.vscode
build/*
docker-build.sh
docker-build.sh
config.local.yaml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/
config.local.yaml
coins-table.local.yaml
Makefile.local
.vscode/
.idea/
Expand Down
4 changes: 4 additions & 0 deletions api/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (inf ClientInfo) IsIOS() bool {

// IsCNLocalMode 是否启用国产化模式
func (inf ClientInfo) IsCNLocalMode(conf *config.Config) bool {
return inf.isCNLocalMode(conf) && conf.EnableVirtualModel
}

func (inf ClientInfo) isCNLocalMode(conf *config.Config) bool {
if !conf.CNLocalMode {
return false
}
Expand Down
13 changes: 7 additions & 6 deletions api/auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ type User struct {
AppleUID string `json:"apple_uid,omitempty"`
IsSetPassword bool `json:"is_set_password,omitempty"`
CreatedAt time.Time `json:"created_at"`
WithLab bool `json:"-"`
withLab bool `json:"-"`
}

func (u User) InternalUser() bool {
return u.UserType == repo.UserTypeInternal
return u.UserType == repo.UserTypeInternal || u.withLab
}

func (u User) ExtraPermissionUser() bool {
return u.UserType == repo.UserTypeExtraPermission
}

// UserOptional 用户信息,可选,如果用户未登录,则为 User 为 nil
Expand All @@ -52,9 +56,6 @@ func CreateAuthUserFromModel(user *model.Users) *User {
IsSetPassword: user.Password != "",
CreatedAt: user.CreatedAt,
// 仅限实验室用户
WithLab: array.In(user.Id, []int64{
1, /* 初始用户 */
24,
}),
withLab: array.In(user.Id, []int64{1}),
}
}
2 changes: 1 addition & 1 deletion api/controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (ctl *AuthController) Register(router web.Router) {

// minEntropyBits is the minimum entropy bits required for a password to be considered strong enough.
const minEntropyBits = 40
const emailRegex = `^([\w\.\_\-]{2,10})@(\w{1,}).([a-z]{2,8})$`
const emailRegex = `^([\w\.\_\-]{2,30})@(\w{1,}).([a-z]{2,8})$`
const phoneRegex = `^1[3456789]\d{9}$`

func isEmail(value string) bool {
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

const (
ErrQuotaNotEnough = "您的配额已用完,请续费后再试"
ErrQuotaNotEnough = "智慧果不足,请充值后再试"
ErrInvalidModel = "无效的模型"
ErrInvalidRequest = "请求参数错误"
ErrInternalError = "服务器故障,请稍后再试"
Expand Down
8 changes: 4 additions & 4 deletions api/controllers/creative-island.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (ctl *CreativeIslandController) gallery(ctx context.Context, webCtx web.Con

userId := user.ID
limit := int64(100)
if mode == "all" && user.WithLab {
if mode == "all" && user.InternalUser() {
userId = 0
limit = 500
}
Expand Down Expand Up @@ -435,7 +435,7 @@ func (ctl *CreativeIslandController) completionsDeepAI(ctx context.Context, webC
return webCtx.JSONError(common.Text(webCtx, ctl.trans, common.ErrInternalError), http.StatusInternalServerError)
}

quotaConsume := coins.GetDeepAIImageCoins(stylePreset)
quotaConsume := int64(coins.GetUnifiedImageGenCoins())

if evaluate {
return webCtx.JSON(web.M{"cost": quotaConsume, "enough": quota.Quota >= quota.Used+quotaConsume})
Expand Down Expand Up @@ -567,7 +567,7 @@ func (ctl *CreativeIslandController) completionsStabilityAI(ctx context.Context,
return webCtx.JSONError(common.Text(webCtx, ctl.trans, common.ErrInternalError), http.StatusInternalServerError)
}

quotaConsume := coins.GetStabilityAIImageCoins(item.Model, int64(steps), int64(width), int64(height)) * imageCount
quotaConsume := int64(coins.GetUnifiedImageGenCoins()) * imageCount
if evaluate {
return webCtx.JSON(web.M{"cost": quotaConsume, "enough": quota.Quota >= quota.Used+quotaConsume})
}
Expand Down Expand Up @@ -700,7 +700,7 @@ func (ctl *CreativeIslandController) completionsLeapAI(ctx context.Context, webC
return webCtx.JSONError(common.Text(webCtx, ctl.trans, common.ErrInternalError), http.StatusInternalServerError)
}

quotaConsume := coins.GetLeapAIImageCoins(item.Model) * imageCount
quotaConsume := int64(coins.GetUnifiedImageGenCoins()) * imageCount
if evaluate {
return webCtx.JSON(web.M{"cost": quotaConsume, "enough": quota.Quota >= quota.Used+quotaConsume})
}
Expand Down
11 changes: 10 additions & 1 deletion api/controllers/creative.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package controllers

import (
"context"
"github.com/mylxsw/aidea-server/api/auth"
"github.com/mylxsw/aidea-server/internal/helper"
"net/http"
"strconv"

Expand Down Expand Up @@ -58,7 +60,7 @@ func (ctl *CreativeController) Gallery(ctx context.Context, webCtx web.Context)
}

// GalleryItem 作品图库详情
func (ctl *CreativeController) GalleryItem(ctx context.Context, webCtx web.Context) web.Response {
func (ctl *CreativeController) GalleryItem(ctx context.Context, webCtx web.Context, user *auth.UserOptional, client *auth.ClientInfo) web.Response {
id, err := strconv.Atoi(webCtx.PathVar("id"))
if err != nil {
return webCtx.JSONError(common.Text(webCtx, ctl.translater, common.ErrInvalidRequest), http.StatusBadRequest)
Expand All @@ -69,5 +71,12 @@ func (ctl *CreativeController) GalleryItem(ctx context.Context, webCtx web.Conte
return webCtx.JSONError(common.Text(webCtx, ctl.translater, common.ErrInternalError), http.StatusInternalServerError)
}

if helper.VersionNewer(client.Version, "1.0.6") {
return webCtx.JSON(web.M{
"data": item,
"is_internal_user": user.User != nil && user.User.InternalUser(),
})
}

return webCtx.JSON(item)
}
177 changes: 0 additions & 177 deletions api/controllers/deepai.go

This file was deleted.

Loading

0 comments on commit e1a961c

Please sign in to comment.