Files
ssw__ipass/rust/crates/plugin-apix/src/store.rs
T
admin 85ea0a1531 refactor(plugin): P4 拆 plugin-apix —— API 代理迁入独立插件,过渡期路由清空
- 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)
2026-09-13 12:16:47 +08:00

36 lines
1.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! 代理表的文件读写(复用内核 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)
}