Skip to content

Commit 03cfd13

Browse files
committed
fix(security): resolve IP whitelist deletion failure by unifying parameter naming to camelCase (Issue #1797)
1 parent e51a12b commit 03cfd13

File tree

7 files changed

+17
-7
lines changed

7 files changed

+17
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ response = client.chat.completions.create(
390390
- **[i18n] 完善 Settings 与 ApiProxy 国际化支持 (PR #1789)**:
391391
- **重构**: 将 `Settings.tsx``ApiProxy.tsx` 中硬编码的中文字符串替换为 `t()` 国际化调用。
392392
- **翻译补全**: 同步更新了韩语、缅甸语、葡萄牙语、俄语、土耳其语、越南语、繁体中文和简体中文的本地化词条。
393+
- **[核心修复] 修复 IP 白名单删除失败问题 (Issue #1797)**:
394+
- **参数规范化**: 修复了由于前端与后端参数命名风格 (snake_case vs camelCase) 不一致导致无法删除白名单 IP 的问题。同时统一了黑名单管理与 IP 访问日志的相关参数,确保全系统参数传递的一致性。
393395
* **v4.1.12 (2026-02-10)**:
394396
- **[核心功能] OpenCode CLI 深度集成 (PR #1739)**:
395397
- **自动探测**: 新增了对 OpenCode CLI 的自动检测与环境变量配置同步支持。

README_EN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ print(response.choices[0].message.content)
274274
- **[i18n] Enhanced Internationalization for Settings and ApiProxy (PR #1789)**:
275275
- **Refactoring**: Replaced hardcoded Chinese strings in `Settings.tsx` and `ApiProxy.tsx` with `t()` internationalization calls.
276276
- **Translation Expansion**: Synchronized localization entries for Korean, Myanmar, Portuguese, Russian, Turkish, Vietnamese, Traditional Chinese, and Simplified Chinese.
277+
- **[Core Fix] Resolve IP Whitelist Deletion Failure (Issue #1797)**:
278+
- **Parameter Normalization**: Fixed the issue where whitelisted IPs could not be deleted due to parameter naming convention mismatches (snake_case vs camelCase) between the frontend and backend. Also unified parameters for blacklist management and IP access logs to ensure system-wide consistency.
277279
* **v4.1.12 (2026-02-10)**:
278280
- **[Core Feature] OpenCode CLI Deep Integration (PR #1739)**:
279281
- **Auto Detection**: Added automatic detection and configuration sync support for OpenCode CLI environment variables.

src-tauri/src/commands/security.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::modules::security_db;
55
// ==================== 请求/响应结构 ====================
66

77
#[derive(Debug, Serialize, Deserialize)]
8+
#[serde(rename_all = "camelCase")]
89
pub struct IpAccessLogQuery {
910
pub page: usize,
1011
pub page_size: usize,
@@ -19,13 +20,15 @@ pub struct IpAccessLogResponse {
1920
}
2021

2122
#[derive(Debug, Serialize, Deserialize)]
23+
#[serde(rename_all = "camelCase")]
2224
pub struct AddBlacklistRequest {
2325
pub ip_pattern: String,
2426
pub reason: Option<String>,
2527
pub expires_at: Option<i64>, // Unix timestamp
2628
}
2729

2830
#[derive(Debug, Serialize, Deserialize)]
31+
#[serde(rename_all = "camelCase")]
2932
pub struct AddWhitelistRequest {
3033
pub ip_pattern: String,
3134
pub description: Option<String>,

src-tauri/src/proxy/server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,7 @@ async fn admin_get_ip_blacklist() -> Result<impl IntoResponse, (StatusCode, Json
31453145
}
31463146

31473147
#[derive(Deserialize)]
3148+
#[serde(rename_all = "camelCase")]
31483149
struct AddBlacklistRequest {
31493150
ip_pattern: String,
31503151
reason: Option<String>,
@@ -3165,6 +3166,7 @@ async fn admin_add_ip_to_blacklist(
31653166
}
31663167

31673168
#[derive(Deserialize)]
3169+
#[serde(rename_all = "camelCase")]
31683170
struct RemoveIpRequest {
31693171
ip_pattern: String,
31703172
}
@@ -3216,6 +3218,7 @@ async fn admin_get_ip_whitelist() -> Result<impl IntoResponse, (StatusCode, Json
32163218
}
32173219

32183220
#[derive(Deserialize)]
3221+
#[serde(rename_all = "camelCase")]
32193222
struct AddWhitelistRequest {
32203223
ip_pattern: String,
32213224
description: Option<String>,

src/components/security/BlacklistManager.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export const BlacklistManager: React.FC<Props> = ({ refreshKey }) => {
5757

5858
await invoke('add_ip_to_blacklist', {
5959
request: {
60-
ip_pattern: newIp,
60+
ipPattern: newIp,
6161
reason: newReason || null,
62-
expires_at: expiresAt
62+
expiresAt: expiresAt
6363
}
6464
});
6565
setIsAddOpen(false);
@@ -85,7 +85,7 @@ export const BlacklistManager: React.FC<Props> = ({ refreshKey }) => {
8585
setEntries(prev => prev.filter(e => e.ip_pattern !== ipPattern));
8686

8787
try {
88-
await invoke('remove_ip_from_blacklist', { ip_pattern: ipPattern });
88+
await invoke('remove_ip_from_blacklist', { ipPattern: ipPattern });
8989
} catch (e) {
9090
console.error('Failed to remove from blacklist', e);
9191
// 如果删除失败,重新加载数据恢复UI

src/components/security/IpAccessLogs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export const IpAccessLogs: React.FC<Props> = ({ refreshKey }) => {
4242
try {
4343
const res = await invoke<IpAccessLogResponse>('get_ip_access_logs', {
4444
page,
45-
page_size: pageSize,
45+
pageSize: pageSize,
4646
search: search || undefined,
47-
blocked_only: blockedOnly,
47+
blockedOnly: blockedOnly,
4848
});
4949
setLogs(res.logs);
5050
setTotal(res.total);

src/components/security/WhitelistManager.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const WhitelistManager: React.FC<Props> = ({ refreshKey }) => {
4545
try {
4646
await invoke('add_ip_to_whitelist', {
4747
request: {
48-
ip_pattern: newIp,
48+
ipPattern: newIp,
4949
description: newDescription || null,
5050
}
5151
});
@@ -64,7 +64,7 @@ export const WhitelistManager: React.FC<Props> = ({ refreshKey }) => {
6464
setEntries(prev => prev.filter(e => e.ip_pattern !== ipPattern));
6565

6666
try {
67-
await invoke('remove_ip_from_whitelist', { ip_pattern: ipPattern });
67+
await invoke('remove_ip_from_whitelist', { ipPattern: ipPattern });
6868
} catch (e) {
6969
console.error('Failed to remove from whitelist', e);
7070
// 如果删除失败,重新加载数据恢复UI

0 commit comments

Comments
 (0)