feat: 接口管理代理密钥
This commit is contained in:
@@ -211,6 +211,7 @@ func (s *Server) CreateGroup(c *gin.Context) {
|
|||||||
ValidationEndpoint: validationEndpoint,
|
ValidationEndpoint: validationEndpoint,
|
||||||
ParamOverrides: req.ParamOverrides,
|
ParamOverrides: req.ParamOverrides,
|
||||||
Config: cleanedConfig,
|
Config: cleanedConfig,
|
||||||
|
ProxyKeys: strings.TrimSpace(req.ProxyKeys),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.DB.Create(&group).Error; err != nil {
|
if err := s.DB.Create(&group).Error; err != nil {
|
||||||
@@ -253,6 +254,7 @@ type GroupUpdateRequest struct {
|
|||||||
ValidationEndpoint *string `json:"validation_endpoint,omitempty"`
|
ValidationEndpoint *string `json:"validation_endpoint,omitempty"`
|
||||||
ParamOverrides map[string]any `json:"param_overrides"`
|
ParamOverrides map[string]any `json:"param_overrides"`
|
||||||
Config map[string]any `json:"config"`
|
Config map[string]any `json:"config"`
|
||||||
|
ProxyKeys *string `json:"proxy_keys,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateGroup handles updating an existing group.
|
// UpdateGroup handles updating an existing group.
|
||||||
@@ -351,6 +353,10 @@ func (s *Server) UpdateGroup(c *gin.Context) {
|
|||||||
group.Config = cleanedConfig
|
group.Config = cleanedConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.ProxyKeys != nil {
|
||||||
|
group.ProxyKeys = strings.TrimSpace(*req.ProxyKeys)
|
||||||
|
}
|
||||||
|
|
||||||
// Save the updated group object
|
// Save the updated group object
|
||||||
if err := tx.Save(&group).Error; err != nil {
|
if err := tx.Save(&group).Error; err != nil {
|
||||||
response.Error(c, app_errors.ParseDBError(err))
|
response.Error(c, app_errors.ParseDBError(err))
|
||||||
@@ -382,6 +388,7 @@ type GroupResponse struct {
|
|||||||
ValidationEndpoint string `json:"validation_endpoint"`
|
ValidationEndpoint string `json:"validation_endpoint"`
|
||||||
ParamOverrides datatypes.JSONMap `json:"param_overrides"`
|
ParamOverrides datatypes.JSONMap `json:"param_overrides"`
|
||||||
Config datatypes.JSONMap `json:"config"`
|
Config datatypes.JSONMap `json:"config"`
|
||||||
|
ProxyKeys string `json:"proxy_keys"`
|
||||||
LastValidatedAt *time.Time `json:"last_validated_at"`
|
LastValidatedAt *time.Time `json:"last_validated_at"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
@@ -412,6 +419,7 @@ func (s *Server) newGroupResponse(group *models.Group) *GroupResponse {
|
|||||||
ValidationEndpoint: group.ValidationEndpoint,
|
ValidationEndpoint: group.ValidationEndpoint,
|
||||||
ParamOverrides: group.ParamOverrides,
|
ParamOverrides: group.ParamOverrides,
|
||||||
Config: group.Config,
|
Config: group.Config,
|
||||||
|
ProxyKeys: group.ProxyKeys,
|
||||||
LastValidatedAt: group.LastValidatedAt,
|
LastValidatedAt: group.LastValidatedAt,
|
||||||
CreatedAt: group.CreatedAt,
|
CreatedAt: group.CreatedAt,
|
||||||
UpdatedAt: group.UpdatedAt,
|
UpdatedAt: group.UpdatedAt,
|
||||||
|
@@ -21,7 +21,7 @@ type SystemSettings struct {
|
|||||||
AppUrl string `json:"app_url" default:"http://localhost:3001" name:"项目地址" category:"基础参数" desc:"项目的基础 URL,用于拼接分组终端节点地址。系统配置优先于环境变量 APP_URL。"`
|
AppUrl string `json:"app_url" default:"http://localhost:3001" name:"项目地址" category:"基础参数" desc:"项目的基础 URL,用于拼接分组终端节点地址。系统配置优先于环境变量 APP_URL。"`
|
||||||
RequestLogRetentionDays int `json:"request_log_retention_days" default:"7" name:"日志保留时长(天)" category:"基础参数" desc:"请求日志在数据库中的保留天数,0为不清理日志。" validate:"min=0"`
|
RequestLogRetentionDays int `json:"request_log_retention_days" default:"7" name:"日志保留时长(天)" category:"基础参数" desc:"请求日志在数据库中的保留天数,0为不清理日志。" validate:"min=0"`
|
||||||
RequestLogWriteIntervalMinutes int `json:"request_log_write_interval_minutes" default:"1" name:"日志延迟写入周期(分钟)" category:"基础参数" desc:"请求日志从缓存写入数据库的周期(分钟),0为实时写入数据。" validate:"min=0"`
|
RequestLogWriteIntervalMinutes int `json:"request_log_write_interval_minutes" default:"1" name:"日志延迟写入周期(分钟)" category:"基础参数" desc:"请求日志从缓存写入数据库的周期(分钟),0为实时写入数据。" validate:"min=0"`
|
||||||
ProxyKeys string `json:"proxy_keys" name:"全局代理密钥" category:"基础参数" desc:"全局代理密钥,用于访问所有代理端点。多个密钥请用逗号分隔。"`
|
ProxyKeys string `json:"proxy_keys" name:"全局代理密钥" category:"基础参数" desc:"全局代理密钥,用于访问所有分组的代理端点。多个密钥请用逗号分隔。"`
|
||||||
|
|
||||||
// 请求设置
|
// 请求设置
|
||||||
RequestTimeout int `json:"request_timeout" default:"600" name:"请求超时(秒)" category:"请求设置" desc:"转发请求的完整生命周期超时(秒)等。" validate:"min=1"`
|
RequestTimeout int `json:"request_timeout" default:"600" name:"请求超时(秒)" category:"请求设置" desc:"转发请求的完整生命周期超时(秒)等。" validate:"min=1"`
|
||||||
|
@@ -59,6 +59,7 @@ interface GroupFormData {
|
|||||||
param_overrides: string;
|
param_overrides: string;
|
||||||
config: Record<string, number>;
|
config: Record<string, number>;
|
||||||
configItems: ConfigItem[];
|
configItems: ConfigItem[];
|
||||||
|
proxy_keys: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 表单数据
|
// 表单数据
|
||||||
@@ -79,6 +80,7 @@ const formData = reactive<GroupFormData>({
|
|||||||
param_overrides: "",
|
param_overrides: "",
|
||||||
config: {},
|
config: {},
|
||||||
configItems: [] as ConfigItem[],
|
configItems: [] as ConfigItem[],
|
||||||
|
proxy_keys: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const channelTypeOptions = ref<{ label: string; value: string }[]>([]);
|
const channelTypeOptions = ref<{ label: string; value: string }[]>([]);
|
||||||
@@ -269,6 +271,7 @@ function resetForm() {
|
|||||||
param_overrides: "",
|
param_overrides: "",
|
||||||
config: {},
|
config: {},
|
||||||
configItems: [],
|
configItems: [],
|
||||||
|
proxy_keys: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重置用户修改状态追踪
|
// 重置用户修改状态追踪
|
||||||
@@ -304,6 +307,7 @@ function loadGroupData() {
|
|||||||
param_overrides: JSON.stringify(props.group.param_overrides || {}, null, 2),
|
param_overrides: JSON.stringify(props.group.param_overrides || {}, null, 2),
|
||||||
config: {},
|
config: {},
|
||||||
configItems,
|
configItems,
|
||||||
|
proxy_keys: props.group.proxy_keys || "",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,6 +412,7 @@ async function handleSubmit() {
|
|||||||
validation_endpoint: formData.validation_endpoint,
|
validation_endpoint: formData.validation_endpoint,
|
||||||
param_overrides: paramOverrides,
|
param_overrides: paramOverrides,
|
||||||
config,
|
config,
|
||||||
|
proxy_keys: formData.proxy_keys,
|
||||||
};
|
};
|
||||||
|
|
||||||
let res: Group;
|
let res: Group;
|
||||||
@@ -592,6 +597,25 @@ async function handleSubmit() {
|
|||||||
<div v-else class="form-item-half" />
|
<div v-else class="form-item-half" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 代理密钥 -->
|
||||||
|
<n-form-item label="代理密钥" path="proxy_keys">
|
||||||
|
<template #label>
|
||||||
|
<div class="form-label-with-tooltip">
|
||||||
|
代理密钥
|
||||||
|
<n-tooltip trigger="hover" placement="top">
|
||||||
|
<template #trigger>
|
||||||
|
<n-icon :component="HelpCircleOutline" class="help-icon" />
|
||||||
|
</template>
|
||||||
|
分组专用代理密钥,用于访问此分组的代理端点。多个密钥请用逗号分隔。
|
||||||
|
</n-tooltip>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<n-input
|
||||||
|
v-model:value="formData.proxy_keys"
|
||||||
|
placeholder="多个密钥请用英文逗号 , 分隔"
|
||||||
|
/>
|
||||||
|
</n-form-item>
|
||||||
|
|
||||||
<!-- 描述独占一行 -->
|
<!-- 描述独占一行 -->
|
||||||
<n-form-item label="描述" path="description">
|
<n-form-item label="描述" path="description">
|
||||||
<template #label>
|
<template #label>
|
||||||
|
@@ -43,6 +43,7 @@ export interface Group {
|
|||||||
api_keys?: APIKey[];
|
api_keys?: APIKey[];
|
||||||
endpoint?: string;
|
endpoint?: string;
|
||||||
param_overrides: Record<string, unknown>;
|
param_overrides: Record<string, unknown>;
|
||||||
|
proxy_keys: string;
|
||||||
created_at?: string;
|
created_at?: string;
|
||||||
updated_at?: string;
|
updated_at?: string;
|
||||||
}
|
}
|
||||||
|
@@ -72,8 +72,12 @@ async function handleSubmit() {
|
|||||||
hoverable
|
hoverable
|
||||||
bordered
|
bordered
|
||||||
>
|
>
|
||||||
<n-grid :x-gap="24" :y-gap="24" responsive="screen" cols="1 s:2 m:2 l:3 xl:4">
|
<n-grid :x-gap="24" :y-gap="0" responsive="screen" cols="1 s:2 m:2 l:3 xl:4">
|
||||||
<n-grid-item v-for="item in category.settings" :key="item.key">
|
<n-grid-item
|
||||||
|
v-for="item in category.settings"
|
||||||
|
:key="item.key"
|
||||||
|
:span="item.key === 'proxy_keys' ? 4 : 1"
|
||||||
|
>
|
||||||
<n-form-item
|
<n-form-item
|
||||||
:path="item.key"
|
:path="item.key"
|
||||||
:rule="{ required: true, message: `请输入 ${item.name}` }"
|
:rule="{ required: true, message: `请输入 ${item.name}` }"
|
||||||
|
Reference in New Issue
Block a user