Skip to content

Commit cf0bf91

Browse files
committed
v0.4.3: fix IdC token refresh with form-urlencoded format, add debug logging
1 parent 3fac9f7 commit cf0bf91

19 files changed

Lines changed: 453 additions & 23 deletions

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"Bash(cargo test:*)",
88
"Bash(cargo build:*)",
99
"Bash(npm run check:*)",
10-
"Bash(npm run:*)"
10+
"Bash(npm run:*)",
11+
"Bash(tree:*)"
1112
],
1213
"deny": [],
1314
"ask": []

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "proxycast",
33
"private": true,
4-
"version": "0.4.2",
4+
"version": "0.4.3",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src-tauri/Cargo.lock

Lines changed: 76 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "proxycast"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
description = "AI API Proxy Desktop App"
55
authors = ["you"]
66
edition = "2021"
@@ -29,6 +29,8 @@ futures = "0.3"
2929
async-stream = "0.3"
3030
regex = "1"
3131
md5 = "0.7"
32+
urlencoding = "2"
33+
rusqlite = { version = "0.31", features = ["bundled"] }
3234

3335
[features]
3436
default = ["custom-protocol"]

src-tauri/src/database/dao/mcp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// MCP Servers DAO - 数据访问对象
2+
// TODO: 实现 mcp_servers 表的 CRUD 操作

src-tauri/src/database/dao/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod mcp;
2+
pub mod prompts;
3+
pub mod providers;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Prompts DAO - 数据访问对象
2+
// TODO: 实现 prompts 表的 CRUD 操作
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Providers DAO - 数据访问对象
2+
// TODO: 实现 providers 表的 CRUD 操作
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use rusqlite::Connection;
2+
use serde_json::Value;
3+
use std::path::PathBuf;
4+
5+
/// 从旧的 JSON 配置迁移数据到 SQLite
6+
pub fn migrate_from_json(
7+
conn: &Connection,
8+
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
9+
// 检查是否已经迁移过
10+
let migrated: bool = conn
11+
.query_row(
12+
"SELECT value FROM settings WHERE key = 'migrated_from_json'",
13+
[],
14+
|row| row.get::<_, String>(0),
15+
)
16+
.map(|v| v == "true")
17+
.unwrap_or(false);
18+
19+
if migrated {
20+
return Ok(());
21+
}
22+
23+
// 读取旧配置文件
24+
let home = dirs::home_dir().ok_or("Cannot find home directory")?;
25+
let config_path = home.join(".proxycast").join("config.json");
26+
27+
if config_path.exists() {
28+
let content = std::fs::read_to_string(&config_path)?;
29+
let config: Value = serde_json::from_str(&content)?;
30+
31+
// TODO: 解析旧配置并插入到数据库
32+
// 这里需要根据实际的旧配置格式来实现
33+
34+
// 备份旧配置
35+
let backup_path = home.join(".proxycast").join("config.json.backup");
36+
std::fs::copy(&config_path, &backup_path)?;
37+
}
38+
39+
// 标记迁移完成
40+
conn.execute(
41+
"INSERT OR REPLACE INTO settings (key, value) VALUES ('migrated_from_json', 'true')",
42+
[],
43+
)?;
44+
45+
Ok(())
46+
}

src-tauri/src/database/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
pub mod dao;
2+
pub mod migration;
3+
pub mod schema;
4+
5+
use rusqlite::Connection;
6+
use std::path::PathBuf;
7+
use std::sync::{Arc, Mutex};
8+
9+
pub type DbConnection = Arc<Mutex<Connection>>;
10+
11+
/// 获取数据库文件路径
12+
pub fn get_db_path() -> PathBuf {
13+
let home = dirs::home_dir().expect("Cannot find home directory");
14+
let db_dir = home.join(".proxycast");
15+
std::fs::create_dir_all(&db_dir).expect("Cannot create .proxycast directory");
16+
db_dir.join("proxycast.db")
17+
}
18+
19+
/// 初始化数据库连接
20+
pub fn init_database() -> Result<DbConnection, rusqlite::Error> {
21+
let db_path = get_db_path();
22+
let conn = Connection::open(&db_path)?;
23+
24+
// 创建表结构
25+
schema::create_tables(&conn)?;
26+
27+
Ok(Arc::new(Mutex::new(conn)))
28+
}

0 commit comments

Comments
 (0)