mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-19 09:46:39 +08:00
feat: update api key last_use_time after dalle3 call
This commit is contained in:
parent
ea3301c75c
commit
1ddd05302b
@ -145,26 +145,27 @@ type ModelAPIConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SystemConfig struct {
|
type SystemConfig struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
AdminTitle string `json:"admin_title"`
|
AdminTitle string `json:"admin_title"`
|
||||||
Models []string `json:"models"`
|
InitChatCalls int `json:"init_chat_calls"` // 新用户注册赠送对话次数
|
||||||
InitChatCalls int `json:"init_chat_calls"` // 新用户注册赠送对话次数
|
InitImgCalls int `json:"init_img_calls"` // 新用户注册赠送绘图次数
|
||||||
InitImgCalls int `json:"init_img_calls"` // 新用户注册赠送绘图次数
|
VipMonthCalls int `json:"vip_month_calls"` // VIP 会员每月赠送的对话次数
|
||||||
VipMonthCalls int `json:"vip_month_calls"` // VIP 会员每月赠送的对话次数
|
VipMonthImgCalls int `json:"vip_month_img_calls"` // VIP 会员每月赠送绘图次数
|
||||||
VipMonthImgCalls int `json:"vip_month_img_calls"` // VIP 会员每月赠送绘图次数
|
|
||||||
EnabledRegister bool `json:"enabled_register"` // 是否启用注册功能,关闭注册功能之后将无法注册
|
EnabledRegister bool `json:"enabled_register"` // 是否启用注册功能,关闭注册功能之后将无法注册
|
||||||
EnabledMsg bool `json:"enabled_msg"` // 是否启用短信验证码服务
|
RegisterWays []string `json:"register_ways"` // 注册方式:支持手机,邮箱注册
|
||||||
RewardImg string `json:"reward_img"` // 众筹收款二维码地址
|
|
||||||
EnabledReward bool `json:"enabled_reward"` // 启用众筹功能
|
RewardImg string `json:"reward_img"` // 众筹收款二维码地址
|
||||||
ChatCallPrice float64 `json:"chat_call_price"` // 对话单次调用费用
|
EnabledReward bool `json:"enabled_reward"` // 启用众筹功能
|
||||||
ImgCallPrice float64 `json:"img_call_price"` // 绘图单次调用费用
|
ChatCallPrice float64 `json:"chat_call_price"` // 对话单次调用费用
|
||||||
|
ImgCallPrice float64 `json:"img_call_price"` // 绘图单次调用费用
|
||||||
|
|
||||||
EnabledAlipay bool `json:"enabled_alipay"` // 是否启用支付宝支付通道
|
EnabledAlipay bool `json:"enabled_alipay"` // 是否启用支付宝支付通道
|
||||||
OrderPayTimeout int `json:"order_pay_timeout"` //订单支付超时时间
|
OrderPayTimeout int `json:"order_pay_timeout"` //订单支付超时时间
|
||||||
DefaultModels []string `json:"default_models"` // 默认开通的 AI 模型
|
DefaultModels []string `json:"default_models"` // 默认开通的 AI 模型
|
||||||
OrderPayInfoText string `json:"order_pay_info_text"` // 订单支付页面说明文字
|
OrderPayInfoText string `json:"order_pay_info_text"` // 订单支付页面说明文字
|
||||||
InviteChatCalls int `json:"invite_chat_calls"` // 邀请用户注册奖励对话次数
|
InviteChatCalls int `json:"invite_chat_calls"` // 邀请用户注册奖励对话次数
|
||||||
InviteImgCalls int `json:"invite_img_calls"` // 邀请用户注册奖励绘图次数
|
InviteImgCalls int `json:"invite_img_calls"` // 邀请用户注册奖励绘图次数
|
||||||
ForceInvite bool `json:"force_invite"` // 是否强制必须使用邀请码才能注册
|
|
||||||
|
|
||||||
ShowDemoNotice bool `json:"show_demo_notice"` // 显示演示站公告
|
ShowDemoNotice bool `json:"show_demo_notice"` // 显示演示站公告
|
||||||
}
|
}
|
||||||
|
@ -262,6 +262,8 @@ func (h *FunctionHandler) Dall3(c *gin.Context) {
|
|||||||
resp.ERROR(c, "请求 OpenAI API 失败: "+errRes.Error.Message)
|
resp.ERROR(c, "请求 OpenAI API 失败: "+errRes.Error.Message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 更新 API KEY 的最后使用时间
|
||||||
|
h.db.Model(&apiKey).UpdateColumn("last_used_at", time.Now().Unix())
|
||||||
// 存储图片
|
// 存储图片
|
||||||
imgURL, err := h.uploadManager.GetUploadHandler().PutImg(res.Data[0].Url, false)
|
imgURL, err := h.uploadManager.GetUploadHandler().PutImg(res.Data[0].Url, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,22 +61,15 @@ func (h *UserHandler) Register(c *gin.Context) {
|
|||||||
|
|
||||||
// 检查验证码
|
// 检查验证码
|
||||||
key := CodeStorePrefix + data.Mobile
|
key := CodeStorePrefix + data.Mobile
|
||||||
if h.App.SysConfig.EnabledMsg {
|
code, err := h.redis.Get(c, key).Result()
|
||||||
code, err := h.redis.Get(c, key).Result()
|
if err != nil || code != data.Code {
|
||||||
if err != nil || code != data.Code {
|
resp.ERROR(c, "短信验证码错误")
|
||||||
resp.ERROR(c, "短信验证码错误")
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证邀请码
|
// 验证邀请码
|
||||||
inviteCode := model.InviteCode{}
|
inviteCode := model.InviteCode{}
|
||||||
if data.InviteCode == "" {
|
if data.InviteCode != "" {
|
||||||
if h.App.SysConfig.ForceInvite {
|
|
||||||
resp.ERROR(c, "当前系统设定必须使用邀请码才能注册")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res := h.db.Where("code = ?", data.InviteCode).First(&inviteCode)
|
res := h.db.Where("code = ?", data.InviteCode).First(&inviteCode)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, "无效的邀请码")
|
resp.ERROR(c, "无效的邀请码")
|
||||||
@ -139,9 +132,8 @@ func (h *UserHandler) Register(c *gin.Context) {
|
|||||||
Reward: utils.JsonEncode(types.InviteReward{ChatCalls: h.App.SysConfig.InviteChatCalls, ImgCalls: h.App.SysConfig.InviteImgCalls}),
|
Reward: utils.JsonEncode(types.InviteReward{ChatCalls: h.App.SysConfig.InviteChatCalls, ImgCalls: h.App.SysConfig.InviteImgCalls}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if h.App.SysConfig.EnabledMsg {
|
|
||||||
_ = h.redis.Del(c, key) // 注册成功,删除短信验证码
|
_ = h.redis.Del(c, key) // 注册成功,删除短信验证码
|
||||||
}
|
|
||||||
|
|
||||||
// 自动登录创建 token
|
// 自动登录创建 token
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||||
@ -374,12 +366,10 @@ func (h *UserHandler) ResetPass(c *gin.Context) {
|
|||||||
|
|
||||||
// 检查验证码
|
// 检查验证码
|
||||||
key := CodeStorePrefix + data.Mobile
|
key := CodeStorePrefix + data.Mobile
|
||||||
if h.App.SysConfig.EnabledMsg {
|
code, err := h.redis.Get(c, key).Result()
|
||||||
code, err := h.redis.Get(c, key).Result()
|
if err != nil || code != data.Code {
|
||||||
if err != nil || code != data.Code {
|
resp.ERROR(c, "短信验证码错误")
|
||||||
resp.ERROR(c, "短信验证码错误")
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
password := utils.GenPassword(data.Password, user.Salt)
|
password := utils.GenPassword(data.Password, user.Salt)
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = logger2.GetLogger()
|
var logger = logger2.GetLogger()
|
||||||
@ -121,5 +122,8 @@ func OpenAIRequest(db *gorm.DB, prompt string, proxy string) (string, error) {
|
|||||||
return "", fmt.Errorf("error with http request: %v%v%s", err, r.Err, errRes.Error.Message)
|
return "", fmt.Errorf("error with http request: %v%v%s", err, r.Err, errRes.Error.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新 API KEY 的最后使用时间
|
||||||
|
db.Model(&apiKey).UpdateColumn("last_used_at", time.Now().Unix())
|
||||||
|
|
||||||
return response.Choices[0].Message.Content, nil
|
return response.Choices[0].Message.Content, nil
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,5 @@ ALTER TABLE `chatgpt_api_keys` ADD `api_url` VARCHAR(255) NULL COMMENT 'API 地
|
|||||||
ALTER TABLE `chatgpt_api_keys` DROP INDEX `value`;
|
ALTER TABLE `chatgpt_api_keys` DROP INDEX `value`;
|
||||||
ALTER TABLE `chatgpt_mj_jobs` ADD UNIQUE(`task_id`);
|
ALTER TABLE `chatgpt_mj_jobs` ADD UNIQUE(`task_id`);
|
||||||
ALTER TABLE `chatgpt_api_keys` ADD `use_proxy` TINYINT(1) NULL COMMENT '是否使用代理访问' AFTER `enabled`;
|
ALTER TABLE `chatgpt_api_keys` ADD `use_proxy` TINYINT(1) NULL COMMENT '是否使用代理访问' AFTER `enabled`;
|
||||||
ALTER TABLE `chatgpt_api_keys` ADD `name` VARCHAR(30) NULL COMMENT '名称' AFTER `platform`;
|
ALTER TABLE `chatgpt_api_keys` ADD `name` VARCHAR(30) NULL COMMENT '名称' AFTER `platform`;
|
||||||
|
ALTER TABLE `chatgpt_users` ADD `email` VARCHAR(100) NULL COMMENT '邮箱地址' AFTER `mobile`;
|
@ -30,31 +30,11 @@
|
|||||||
<el-form-item label="开放注册服务" prop="enabled_register">
|
<el-form-item label="开放注册服务" prop="enabled_register">
|
||||||
<el-switch v-model="system['enabled_register']"/>
|
<el-switch v-model="system['enabled_register']"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="强制邀请码注册" prop="force_invite">
|
<el-form-item label="注册方式" prop="register_ways">
|
||||||
<el-switch v-model="system['force_invite']"/>
|
<el-checkbox-group v-model="system['register_ways']">
|
||||||
<el-tooltip
|
<el-checkbox label="mobile">手机注册</el-checkbox>
|
||||||
effect="dark"
|
<el-checkbox label="email">邮箱注册</el-checkbox>
|
||||||
content="开启之后,用户必须使用邀请码才能注册"
|
</el-checkbox-group>
|
||||||
raw-content
|
|
||||||
placement="right"
|
|
||||||
>
|
|
||||||
<el-icon>
|
|
||||||
<InfoFilled/>
|
|
||||||
</el-icon>
|
|
||||||
</el-tooltip>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="短信服务" prop="enabled_msg">
|
|
||||||
<el-switch v-model="system['enabled_msg']"/>
|
|
||||||
<el-tooltip
|
|
||||||
effect="dark"
|
|
||||||
content="是否在注册时候开启短信验证码服务"
|
|
||||||
raw-content
|
|
||||||
placement="right"
|
|
||||||
>
|
|
||||||
<el-icon>
|
|
||||||
<InfoFilled/>
|
|
||||||
</el-icon>
|
|
||||||
</el-tooltip>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="启用众筹功能" prop="enabled_reward">
|
<el-form-item label="启用众筹功能" prop="enabled_reward">
|
||||||
|
Loading…
Reference in New Issue
Block a user