From 599ce0eade3b2a6e68aaf056c1b54e68f3f9aac7 Mon Sep 17 00:00:00 2001 From: RockYang Date: Fri, 24 Nov 2023 18:05:59 +0800 Subject: [PATCH] feat: add type field for api key --- api/service/xxl_job_service.go | 3 ++- api/store/model/api_key.go | 1 + api/store/vo/api_key.go | 1 + database/update-v3.2.0.sql | 4 +++- web/src/views/Register.vue | 3 +-- web/src/views/admin/ApiKey.vue | 16 ++++++++++++++++ 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/api/service/xxl_job_service.go b/api/service/xxl_job_service.go index 7120f9fc..b8982053 100644 --- a/api/service/xxl_job_service.go +++ b/api/service/xxl_job_service.go @@ -63,7 +63,8 @@ func (e *XXLJobExecutor) ClearOrders(cxt context.Context, param *xxl.RunReq) (ms } timeout := time.Now().Unix() - int64(config.OrderPayTimeout) start := utils.Stamp2str(timeout) - res = e.db.Where("status != ? AND created_at < ?", types.OrderPaidSuccess, start).Delete(&model.Order{}) + // 这里不是用软删除,而是永久删除订单 + res = e.db.Unscoped().Where("status != ? AND created_at < ?", types.OrderPaidSuccess, start).Delete(&model.Order{}) return fmt.Sprintf("Clear order successfully, affect rows: %d", res.RowsAffected) } diff --git a/api/store/model/api_key.go b/api/store/model/api_key.go index 80f8d44e..b09d6566 100644 --- a/api/store/model/api_key.go +++ b/api/store/model/api_key.go @@ -4,6 +4,7 @@ package model type ApiKey struct { BaseModel Platform string + Type string // 用途 chat => 聊天,img => 绘图 Value string // API Key 的值 LastUsedAt int64 // 最后使用时间 } diff --git a/api/store/vo/api_key.go b/api/store/vo/api_key.go index 77403e74..7091370b 100644 --- a/api/store/vo/api_key.go +++ b/api/store/vo/api_key.go @@ -4,6 +4,7 @@ package vo type ApiKey struct { BaseVo Platform string `json:"platform"` + Type string `json:"type"` Value string `json:"value"` // API Key 的值 LastUsedAt int64 `json:"last_used_at"` // 最后使用时间 } diff --git a/database/update-v3.2.0.sql b/database/update-v3.2.0.sql index 51cacd55..6b86674b 100644 --- a/database/update-v3.2.0.sql +++ b/database/update-v3.2.0.sql @@ -23,4 +23,6 @@ CREATE TABLE `chatgpt_invite_codes` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户邀请码'; ALTER TABLE `chatgpt_invite_codes` ADD PRIMARY KEY (`id`); ALTER TABLE `chatgpt_invite_codes` MODIFY `id` int NOT NULL AUTO_INCREMENT; -ALTER TABLE `chatgpt_invite_codes` ADD UNIQUE(`code`); \ No newline at end of file +ALTER TABLE `chatgpt_invite_codes` ADD UNIQUE(`code`); + +ALTER TABLE `chatgpt_api_keys` ADD `type` VARCHAR(10) NOT NULL DEFAULT 'chat' COMMENT '用途(chat=>聊天,img=>图片)' AFTER `value`; \ No newline at end of file diff --git a/web/src/views/Register.vue b/web/src/views/Register.vue index fe32612d..7a776093 100644 --- a/web/src/views/Register.vue +++ b/web/src/views/Register.vue @@ -145,8 +145,7 @@ httpGet("/api/admin/config/get?key=system").then(res => { if (res.data) { enableMsg.value = res.data['enabled_msg'] enableRegister.value = res.data['enabled_register'] - console.log(res.data) - if (res.data['force_invite']) { + if (res.data['force_invite'] && !formData.value.invite_code) { ElNotification({ title: '提示:', dangerouslyUseHTMLString: true, diff --git a/web/src/views/admin/ApiKey.vue b/web/src/views/admin/ApiKey.vue index 50a0a2f0..ee783f6f 100644 --- a/web/src/views/admin/ApiKey.vue +++ b/web/src/views/admin/ApiKey.vue @@ -9,6 +9,12 @@ + + +