feat: add type field for api key

This commit is contained in:
RockYang 2023-11-24 18:05:59 +08:00
parent 11f3ab8dc7
commit 599ce0eade
6 changed files with 24 additions and 4 deletions

View File

@ -63,7 +63,8 @@ func (e *XXLJobExecutor) ClearOrders(cxt context.Context, param *xxl.RunReq) (ms
} }
timeout := time.Now().Unix() - int64(config.OrderPayTimeout) timeout := time.Now().Unix() - int64(config.OrderPayTimeout)
start := utils.Stamp2str(timeout) 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) return fmt.Sprintf("Clear order successfully, affect rows: %d", res.RowsAffected)
} }

View File

@ -4,6 +4,7 @@ package model
type ApiKey struct { type ApiKey struct {
BaseModel BaseModel
Platform string Platform string
Type string // 用途 chat => 聊天img => 绘图
Value string // API Key 的值 Value string // API Key 的值
LastUsedAt int64 // 最后使用时间 LastUsedAt int64 // 最后使用时间
} }

View File

@ -4,6 +4,7 @@ package vo
type ApiKey struct { type ApiKey struct {
BaseVo BaseVo
Platform string `json:"platform"` Platform string `json:"platform"`
Type string `json:"type"`
Value string `json:"value"` // API Key 的值 Value string `json:"value"` // API Key 的值
LastUsedAt int64 `json:"last_used_at"` // 最后使用时间 LastUsedAt int64 `json:"last_used_at"` // 最后使用时间
} }

View File

@ -24,3 +24,5 @@ CREATE TABLE `chatgpt_invite_codes` (
ALTER TABLE `chatgpt_invite_codes` ADD PRIMARY KEY (`id`); 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` MODIFY `id` int NOT NULL AUTO_INCREMENT;
ALTER TABLE `chatgpt_invite_codes` ADD UNIQUE(`code`); 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`;

View File

@ -145,8 +145,7 @@ httpGet("/api/admin/config/get?key=system").then(res => {
if (res.data) { if (res.data) {
enableMsg.value = res.data['enabled_msg'] enableMsg.value = res.data['enabled_msg']
enableRegister.value = res.data['enabled_register'] enableRegister.value = res.data['enabled_register']
console.log(res.data) if (res.data['force_invite'] && !formData.value.invite_code) {
if (res.data['force_invite']) {
ElNotification({ ElNotification({
title: '提示:', title: '提示:',
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,

View File

@ -9,6 +9,12 @@
<el-table :data="items" :row-key="row => row.id" table-layout="auto"> <el-table :data="items" :row-key="row => row.id" table-layout="auto">
<el-table-column prop="platform" label="所属平台"/> <el-table-column prop="platform" label="所属平台"/>
<el-table-column prop="value" label="KEY"/> <el-table-column prop="value" label="KEY"/>
<el-table-column prop="type" label="用途">
<template #default="scope">
<el-tag v-if="scope.row.type === 'chat'">聊天</el-tag>
<el-tag v-else-if="scope.row.type === 'img'" type="success">绘图</el-tag>
</template>
</el-table-column>
<el-table-column label="创建时间"> <el-table-column label="创建时间">
<template #default="scope"> <template #default="scope">
@ -58,6 +64,11 @@
<el-form-item label="API KEY" prop="value"> <el-form-item label="API KEY" prop="value">
<el-input v-model="item.value" autocomplete="off"/> <el-input v-model="item.value" autocomplete="off"/>
</el-form-item> </el-form-item>
<el-form-item label="用途:" prop="type">
<el-select v-model="item.type" placeholder="请选择用途">
<el-option v-for="item in types" :value="item.value" :key="item.value">{{ item.name }}</el-option>
</el-select>
</el-form-item>
</el-form> </el-form>
@ -84,6 +95,7 @@ const item = ref({})
const showDialog = ref(false) const showDialog = ref(false)
const rules = reactive({ const rules = reactive({
platform: [{required: true, message: '请选择平台', trigger: 'change',}], platform: [{required: true, message: '请选择平台', trigger: 'change',}],
type: [{required: true, message: '请选择用途', trigger: 'change',}],
value: [{required: true, message: '请输入 API KEY 值', trigger: 'change',}] value: [{required: true, message: '请输入 API KEY 值', trigger: 'change',}]
}) })
const loading = ref(true) const loading = ref(true)
@ -96,6 +108,10 @@ const platforms = ref([
{name: "【百度】文心一言", value: "Baidu"}, {name: "【百度】文心一言", value: "Baidu"},
{name: "【微软】Azure", value: "Azure"}, {name: "【微软】Azure", value: "Azure"},
]) ])
const types = ref([
{name: "聊天", value: "chat"},
{name: "绘画", value: "img"},
])
// //
httpGet('/api/admin/apikey/list').then((res) => { httpGet('/api/admin/apikey/list').then((res) => {