Skip to content

Commit

Permalink
remove license code
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjian102621 committed May 21, 2024
1 parent 27c816c commit 4a99be2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 293 deletions.
39 changes: 3 additions & 36 deletions api/handler/admin/config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ import (
"geekai/core"
"geekai/core/types"
"geekai/handler"
"geekai/service"
"geekai/store"
"geekai/store/model"
"geekai/utils"
"geekai/utils/resp"
"github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/host"
"gorm.io/gorm"
)

type ConfigHandler struct {
handler.BaseHandler
levelDB *store.LevelDB
licenseService *service.LicenseService
levelDB *store.LevelDB
}

func NewConfigHandler(app *core.AppServer, db *gorm.DB, levelDB *store.LevelDB, licenseService *service.LicenseService) *ConfigHandler {
return &ConfigHandler{BaseHandler: handler.BaseHandler{App: app, DB: db}, levelDB: levelDB, licenseService: licenseService}
func NewConfigHandler(app *core.AppServer, db *gorm.DB, levelDB *store.LevelDB) *ConfigHandler {
return &ConfigHandler{BaseHandler: handler.BaseHandler{App: app, DB: db}, levelDB: levelDB}
}

func (h *ConfigHandler) Update(c *gin.Context) {
Expand Down Expand Up @@ -98,33 +95,3 @@ func (h *ConfigHandler) Get(c *gin.Context) {

resp.SUCCESS(c, value)
}

// Active 激活系统
func (h *ConfigHandler) Active(c *gin.Context) {
var data struct {
License string `json:"license"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
info, err := host.Info()
if err != nil {
resp.ERROR(c, err.Error())
return
}

err = h.licenseService.ActiveLicense(data.License, info.HostID)
if err != nil {
resp.ERROR(c, err.Error())
return
}

resp.SUCCESS(c, info.HostID)
}

// GetLicense 获取 License 信息
func (h *ConfigHandler) GetLicense(c *gin.Context) {
license := h.licenseService.GetLicense()
resp.SUCCESS(c, license)
}
16 changes: 4 additions & 12 deletions api/handler/admin/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ package admin
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import (
"fmt"
"geekai/core"
"geekai/core/types"
"geekai/handler"
"geekai/service"
"geekai/store/model"
"geekai/store/vo"
"geekai/utils"
"geekai/utils/resp"
"fmt"
"time"

"github.com/gin-gonic/gin"
Expand All @@ -25,11 +24,10 @@ import (

type UserHandler struct {
handler.BaseHandler
licenseService *service.LicenseService
}

func NewUserHandler(app *core.AppServer, db *gorm.DB, licenseService *service.LicenseService) *UserHandler {
return &UserHandler{BaseHandler: handler.BaseHandler{App: app, DB: db}, licenseService: licenseService}
func NewUserHandler(app *core.AppServer, db *gorm.DB) *UserHandler {
return &UserHandler{BaseHandler: handler.BaseHandler{App: app, DB: db}}
}

// List 用户列表
Expand Down Expand Up @@ -84,13 +82,7 @@ func (h *UserHandler) Save(c *gin.Context) {
resp.ERROR(c, types.InvalidArgs)
return
}
// 检测最大注册人数
var totalUser int64
h.DB.Model(&model.User{}).Count(&totalUser)
if int(totalUser) >= h.licenseService.GetLicense().UserNum {
resp.ERROR(c, "当前注册用户数已达上限,请请升级 License")
return
}

var user = model.User{}
var res *gorm.DB
var userVo vo.User
Expand Down
23 changes: 6 additions & 17 deletions api/handler/chatimpl/chat_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"geekai/core/types"
"geekai/handler"
logger2 "geekai/logger"
"geekai/service"
"geekai/service/oss"
"geekai/store/model"
"geekai/store/vo"
Expand All @@ -43,17 +42,15 @@ var logger = logger2.GetLogger()

type ChatHandler struct {
handler.BaseHandler
redis *redis.Client
uploadManager *oss.UploaderManager
licenseService *service.LicenseService
redis *redis.Client
uploadManager *oss.UploaderManager
}

func NewChatHandler(app *core.AppServer, db *gorm.DB, redis *redis.Client, manager *oss.UploaderManager, licenseService *service.LicenseService) *ChatHandler {
func NewChatHandler(app *core.AppServer, db *gorm.DB, redis *redis.Client, manager *oss.UploaderManager) *ChatHandler {
return &ChatHandler{
BaseHandler: handler.BaseHandler{App: app, DB: db},
redis: redis,
uploadManager: manager,
licenseService: licenseService,
BaseHandler: handler.BaseHandler{App: app, DB: db},
redis: redis,
uploadManager: manager,
}
}

Expand Down Expand Up @@ -491,14 +488,6 @@ func (h *ChatHandler) doRequest(ctx context.Context, req types.ApiRequest, sessi
return nil, errors.New("no available key, please import key")
}

// ONLY allow apiURL in blank list
if session.Model.Platform == types.OpenAI {
err := h.licenseService.IsValidApiURL(apiKey.ApiURL)
if err != nil {
return nil, err
}
}

var apiURL string
switch session.Model.Platform {
case types.Azure:
Expand Down
26 changes: 7 additions & 19 deletions api/handler/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ package handler
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import (
"fmt"
"geekai/core"
"geekai/core/types"
"geekai/service"
"geekai/store/model"
"geekai/store/vo"
"geekai/utils"
"geekai/utils/resp"
"fmt"
"strings"
"time"

Expand All @@ -29,22 +28,19 @@ import (

type UserHandler struct {
BaseHandler
searcher *xdb.Searcher
redis *redis.Client
licenseService *service.LicenseService
searcher *xdb.Searcher
redis *redis.Client
}

func NewUserHandler(
app *core.AppServer,
db *gorm.DB,
searcher *xdb.Searcher,
client *redis.Client,
licenseService *service.LicenseService) *UserHandler {
client *redis.Client) *UserHandler {
return &UserHandler{
BaseHandler: BaseHandler{DB: db, App: app},
searcher: searcher,
redis: client,
licenseService: licenseService,
BaseHandler: BaseHandler{DB: db, App: app},
searcher: searcher,
redis: client,
}
}

Expand All @@ -68,14 +64,6 @@ func (h *UserHandler) Register(c *gin.Context) {
return
}

// 检测最大注册人数
var totalUser int64
h.DB.Model(&model.User{}).Count(&totalUser)
if int(totalUser) >= h.licenseService.GetLicense().UserNum {
resp.ERROR(c, "当前注册用户数已达上限,请请升级 License")
return
}

// 检查验证码
var key string
if data.RegWay == "email" || data.RegWay == "mobile" {
Expand Down
6 changes: 0 additions & 6 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ func main() {
// 邮件服务
fx.Provide(service.NewSmtpService),
// License 服务
fx.Provide(service.NewLicenseService),
fx.Invoke(func(licenseService *service.LicenseService) {
licenseService.SyncLicense()
}),

// 微信机器人服务
fx.Provide(wx.NewWeChatBot),
Expand Down Expand Up @@ -300,8 +296,6 @@ func main() {
group := s.Engine.Group("/api/admin/")
group.POST("config/update", h.Update)
group.GET("config/get", h.Get)
group.POST("active", h.Active)
group.GET("config/get/license", h.GetLicense)
}),
fx.Invoke(func(s *core.AppServer, h *admin.ManagerHandler) {
group := s.Engine.Group("/api/admin/")
Expand Down
Loading

0 comments on commit 4a99be2

Please sign in to comment.