- plugin-apix 新 crate:apix/handlers/api/config/models/store - ApiProxy/ApiProxyStore、api-proxies.json 读写、ax: 键空间与 APIX_* 常量自内核迁入 - ApiProxyHandler 与 $apix_* 六变量注册归 ApixPlugin;用量记账仍走 plugin_llm::stats(同一片键空间、单一写入口) - gateway 路由表只剩 trend 组合端点(需 users+upstreams+apix 三方名册) - 行为等价:262 项回归全绿(gateway 102 + llm 160)
36 lines
1.0 KiB
Rust
36 lines
1.0 KiB
Rust
//! 代理表的文件读写(复用内核 store 的原子写 + 全局文件写锁)。
|
||
//!
|
||
//! `data/api-proxies.json` 含供应商真 Key,**敏感级别等同 `users.json`**。
|
||
|
||
use std::path::PathBuf;
|
||
|
||
use ipass_core::{state, store};
|
||
|
||
use crate::models::ApiProxyStore;
|
||
|
||
fn api_proxies_path() -> PathBuf {
|
||
store::path_in_data("api-proxies.json")
|
||
}
|
||
|
||
pub fn read_api_proxies() -> ApiProxyStore {
|
||
store::read_json(&api_proxies_path(), ApiProxyStore::default())
|
||
}
|
||
|
||
pub fn write_api_proxies(data: &ApiProxyStore) -> Result<(), String> {
|
||
store::write_json(&api_proxies_path(), data)
|
||
}
|
||
|
||
/// 加锁「读-改-写」代理表。
|
||
///
|
||
/// 闭包返回 `Ok(T)` 表示提交,`Err(msg)` 表示放弃(不写盘)。
|
||
pub fn update_api_proxies<T, F>(f: F) -> Result<T, String>
|
||
where
|
||
F: FnOnce(&mut ApiProxyStore) -> Result<T, String>,
|
||
{
|
||
let _guard = state::file_lock().ok_or("内部错误:状态锁不可用")?;
|
||
let mut data = read_api_proxies();
|
||
let out = f(&mut data)?;
|
||
write_api_proxies(&data)?;
|
||
Ok(out)
|
||
}
|