refactor: refresh remaining lib/* crates and drop wiki/llmprovider.md
zhenyi committed
This change is very large, so some diffs are not shown. Clone the repository to see the full change.
Modified lib/config/src/app.rs lib/config/src/app.rs +3 −0 View lib/config/src/app.rs
@@ -9,6 +9,7 @@
99use crate::issues;
1010use crate::jwt;
1111use crate::live;
12use crate::lprovider;
1213use crate::mcp;
1314use crate::obs;
1415use crate::payment;
@@ -53,6 +54,7 @@
5354 pub webhook: webhook::WebhookConfig,
5455 pub obs: obs::ObsSettings,
5556 pub mcp: mcp::McpSettings,
57 pub lprovider: lprovider::LproviderConfig,
5658}
5759
5860impl AppConfig {
@@ -63,6 +65,7 @@
6365 self.webhook.is_valid()?;
6466 self.obs.is_valid()?;
6567 self.mcp.is_valid()?;
68 self.lprovider.is_valid()?;
6669 if self.chat.topic_prefix != self.gateway.topic_prefix {
6770 return Err(format!(
6871 "chat.topic_prefix ({:?}) must equal gateway.topic_prefix ({:?})",
Modified lib/config/src/auth.rs lib/config/src/auth.rs +3 −0 View lib/config/src/auth.rs
@@ -146,6 +146,8 @@
146146 pub oauth: OAuthConfig,
147147 #[serde(default)]
148148 pub agreements: AgreementsConfig,
149 #[serde(default)]
150 pub totp_encryption_key: Option<String>,
149151}
150152
151153fn default_verify_code_ttl() -> u64 {
@@ -201,6 +203,7 @@
201203 auto_register_agreements: Vec::new(),
202204 oauth: OAuthConfig::default(),
203205 agreements: AgreementsConfig::default(),
206 totp_encryption_key: None,
204207 }
205208 }
206209}
Modified lib/config/src/lib.rs lib/config/src/lib.rs +1 −0 View lib/config/src/lib.rs
@@ -11,6 +11,7 @@
1111pub mod jwt;
1212pub mod live;
1313pub mod loader;
14pub mod lprovider;
1415pub mod mcp;
1516pub mod obs;
1617pub mod payment;
Modified lib/config/src/live.rs lib/config/src/live.rs +4 −0 View lib/config/src/live.rs
@@ -1,5 +1,7 @@
11use serde::{Deserialize, Serialize};
22
3use crate::rate_limit::RateLimitConfig;
4
35#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(default, deny_unknown_fields)]
57pub struct LiveSettings {
@@ -10,6 +12,7 @@
1012 pub webhook_secret: String,
1113 pub room_token_ttl_seconds: u64,
1214 pub empty_timeout_seconds: u64,
15 pub rate_limit: RateLimitConfig,
1316}
1417
1518impl Default for LiveSettings {
@@ -22,6 +25,7 @@
2225 webhook_secret: String::new(),
2326 room_token_ttl_seconds: 600,
2427 empty_timeout_seconds: 300,
28 rate_limit: RateLimitConfig::default(),
2529 }
2630 }
2731}
Modified lib/db/lib.rs lib/db/lib.rs +1 −0 View lib/db/lib.rs
@@ -6,6 +6,7 @@
66pub mod git;
77pub mod issue;
88pub mod live;
9pub mod lprovider;
910pub mod oauth;
1011pub mod papers;
1112pub mod payment;
Modified lib/db/schema.rs lib/db/schema.rs +5 −0 View lib/db/schema.rs
@@ -19,6 +19,11 @@
1919 DROP INDEX IF EXISTS idx_project_favorites_unique;
2020 DROP INDEX IF EXISTS idx_meet_room_name;
2121 DROP INDEX IF EXISTS idx_meet_active_per_channel;
22 DROP INDEX IF EXISTS uq_llm_billing_aggregate_period;
23 DROP INDEX IF EXISTS uq_llm_wallet_owner;
24 DROP INDEX IF EXISTS uq_llm_wallet_ledger_request_kind;
25 DROP INDEX IF EXISTS uq_llm_wallet_ledger_idem;
26 DROP INDEX IF EXISTS uq_llm_tenant_quota_subject;
2227";
2328
2429pub async fn sync_schema(db: &DatabaseConnection) -> Result<(), DbError> {
Modified lib/db/schema_extras.sql lib/db/schema_extras.sql +19 −0 View lib/db/schema_extras.sql
@@ -167,3 +167,22 @@
167167 AND space_members.user_id = spaces.owner_id
168168)
169169ON CONFLICT (space_id, user_id) DO NOTHING;
170
171-- lprovider (llm 网关)
172
173CREATE INDEX IF NOT EXISTS idx_llm_call_log_tenant_created ON llm_call_log (tenant_id, created_at);
174CREATE INDEX IF NOT EXISTS idx_llm_call_log_model_created ON llm_call_log (model_alias, created_at);
175CREATE INDEX IF NOT EXISTS idx_llm_call_log_upstream_key_created ON llm_call_log (upstream_code, key_label, created_at);
176CREATE INDEX IF NOT EXISTS idx_llm_call_log_status_created ON llm_call_log (status, created_at);
177
178CREATE UNIQUE INDEX IF NOT EXISTS uq_llm_billing_aggregate_period ON llm_billing_aggregate (tenant_id, subject_type, subject_id, period_start, period_kind, model_alias, upstream_code);
179
180CREATE UNIQUE INDEX IF NOT EXISTS uq_llm_wallet_owner ON llm_wallet (owner_type, owner_id);
181
182CREATE UNIQUE INDEX IF NOT EXISTS uq_llm_wallet_ledger_request_kind ON llm_wallet_ledger (request_id, kind) WHERE request_id IS NOT NULL;
183CREATE UNIQUE INDEX IF NOT EXISTS uq_llm_wallet_ledger_idem ON llm_wallet_ledger (wallet_id, kind, idempotency_key) WHERE idempotency_key IS NOT NULL;
184
185CREATE UNIQUE INDEX IF NOT EXISTS uq_llm_tenant_quota_subject ON llm_tenant_quota (tenant_id, subject_type, subject_id);
186
187CREATE INDEX IF NOT EXISTS idx_lprovider_admin_audit_created ON lprovider_admin_audit (created_at);
188CREATE INDEX IF NOT EXISTS idx_lprovider_admin_audit_operator_created ON lprovider_admin_audit (operator, created_at);
Modified lib/export/repo/mod.rs lib/export/repo/mod.rs +1 −0 View lib/export/repo/mod.rs
@@ -1,3 +1,4 @@
1pub mod activity;
12pub mod archive;
23pub mod branch;
34pub mod branch_protection;
Modified lib/export/space/channels.rs lib/export/space/channels.rs +24 −0 View lib/export/space/channels.rs
@@ -69,6 +69,30 @@
6969 }
7070}
7171
72#[derive(Debug, Clone, Deserialize, ToSchema)]
73pub struct CreateDirectoryCmd {
74 pub name: String,
75 pub parent_id: Option<Uuid>,
76 #[serde(default)]
77 pub icon: Option<String>,
78 #[serde(default)]
79 pub color: Option<String>,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
83pub struct UpdateChannelCmd {
84 #[serde(default)]
85 pub name: Option<String>,
86 #[serde(default)]
87 pub icon: Option<Option<String>>,
88 #[serde(default)]
89 pub position: Option<i32>,
90 #[serde(default)]
91 pub color: Option<Option<String>>,
92 #[serde(default)]
93 pub parent_id: Option<Option<Uuid>>,
94}
95
7296#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
7397pub struct ChannelPage {
7498 pub items: Vec<ChannelView>,
Modified lib/repo/features/mod.rs lib/repo/features/mod.rs +1 −0 View lib/repo/features/mod.rs
@@ -1,5 +1,6 @@
11pub use crate::service::RepoService;
22
3pub mod activity;
34pub mod archive;
45pub mod authz;
56pub mod branch;
Modified lib/repo/handler/mod.rs lib/repo/handler/mod.rs +1 −0 View lib/repo/handler/mod.rs
@@ -1,3 +1,4 @@
1pub mod activity;
12pub mod archive;
23pub mod branch;
34pub mod branch_protection;
Modified lib/repo/handler/openapi.rs lib/repo/handler/openapi.rs +8 −0 View lib/repo/handler/openapi.rs
@@ -1,5 +1,6 @@
11use utoipa::OpenApi;
22
3use crate::features::activity;
34use crate::features::archive;
45use crate::features::branch;
56use crate::features::branch_protection;
@@ -95,6 +96,8 @@
9596 crate::handler::release::delete_by_tag::handler,
9697 crate::handler::release::upload_asset::handler,
9798
99 crate::handler::activity::list::handler,
100
98101 crate::handler::collab::list::handler,
99102 crate::handler::collab::is::handler,
100103 crate::handler::collab::add::handler,
@@ -210,6 +213,11 @@
210213 branch::BranchPage,
211214 branch::CommitMeta,
212215
216 activity::RepoActivity,
217 activity::RepoActivityKind,
218 activity::RepoActivityPage,
219 activity::ListActivityQuery,
220
213221 pull_request::PullRequestView,
214222 pull_request::PullRequestPage,
215223 pull_request::PrState,
Modified lib/repo/handler/routes.rs lib/repo/handler/routes.rs +4 −0 View lib/repo/handler/routes.rs
@@ -155,6 +155,10 @@
155155 get(super::release::list::handler).post(super::release::create::handler),
156156 )
157157 .route(
158 "/repos/{space_name}/{repo_id}/activity",
159 get(super::activity::list::handler),
160 )
161 .route(
158162 "/repos/{space_name}/{repo_id}/releases/latest",
159163 get(super::release::latest::handler),
160164 )
Modified lib/repo/metrics.rs lib/repo/metrics.rs +2 −0 View lib/repo/metrics.rs
@@ -116,6 +116,8 @@
116116pub const FEATURE_RELEASES_DELETE: &str = "releases_delete";
117117pub const FEATURE_RELEASES_DELETE_BY_TAG: &str = "releases_delete_by_tag";
118118
119pub const FEATURE_ACTIVITY_LIST: &str = "activity_list";
120
119121pub const FEATURE_SUBSCRIBERS_LIST: &str = "subscribers_list";
120122
121123pub const FEATURE_SYNC_GET_STATUS: &str = "sync_get_status";
Modified lib/user/features/security/usecase.rs lib/user/features/security/usecase.rs +8 −15 View lib/user/features/security/usecase.rs
@@ -479,17 +479,9 @@
479479 .totp_encryption_key
480480 .as_deref()
481481 .ok_or_else(|| UserError::Internal("totp encryption key not configured".into()))?;
482 let mut raw = vec![0u8; TOTP_SECRET_BYTES];
483 rand::rng().try_fill_bytes(&mut raw).expect("rng");
484 let secret = base32_encode(&raw);
485 let uri = format!(
486 "otpauth://totp/{issuer}:{user}?secret={secret}&issuer={issuer}&algorithm=SHA1&digits={digits}&period={period}",
487 issuer = TOTP_ISSUER,
488 user = row.username,
489 digits = TOTP_DIGITS,
490 period = TOTP_PERIOD_SECS,
491 );
492 let stored = totp_encrypt_secret(key, &secret)?;
482 let secret = totp::generate_secret();
483 let uri = totp::otpauth_uri(&secret, &row.username);
484 let stored = totp::encrypt_secret(key, &secret).map_err(map_totp)?;
493485 let now = time::OffsetDateTime::now_utc();
494486 let writer = svc.db.writer();
495487 let mut am: db::user::users::ActiveModel = row.into();
@@ -540,8 +532,9 @@
540532 .totp_encrypted_secret
541533 .as_deref()
542534 .ok_or_else(|| UserError::BadRequest("run two-factor setup first".into()))?;
543 let secret = totp_decrypt_secret(key, stored)?;
544 let (_, counter) = verify_totp_code(&secret, &cmd.code, row.totp_last_counter)?;
535 let secret = totp::decrypt_secret(key, stored).map_err(map_totp)?;
536 let (_, counter) =
537 totp::verify_totp_code(&secret, &cmd.code, row.totp_last_counter).map_err(map_totp)?;
545538 let now = time::OffsetDateTime::now_utc();
546539 let writer = svc.db.writer();
547540 let mut am: db::user::users::ActiveModel = row.into();
@@ -588,8 +581,8 @@
588581 .totp_encrypted_secret
589582 .as_deref()
590583 .ok_or_else(|| UserError::Internal("stored totp secret missing".into()))?;
591 let secret = totp_decrypt_secret(key, stored)?;
592 let _ = verify_totp_code(&secret, &cmd.code, row.totp_last_counter)?;
584 let secret = totp::decrypt_secret(key, stored).map_err(map_totp)?;
585 let _ = totp::verify_totp_code(&secret, &cmd.code, row.totp_last_counter).map_err(map_totp)?;
593586 let now = time::OffsetDateTime::now_utc();
594587 let writer = svc.db.writer();
595588 let mut am: db::user::users::ActiveModel = row.into();
Modified lib/user/Cargo.toml lib/user/Cargo.toml +1 −0 View lib/user/Cargo.toml
@@ -21,6 +21,7 @@
2121jwt.workspace = true
2222rate_limit.workspace = true
2323storage.workspace = true
24totp.workspace = true
2425tokio.workspace = true
2526axum.workspace = true
2627axum-extra.workspace = true
Modified openapi.json openapi.json View openapi.json
Diff too large to display.