repo stringlengths 6 65 | file_url stringlengths 81 311 | file_path stringlengths 6 227 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:31:58 2026-01-04 20:25:31 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/proxy/providers/models/anthropic.rs | src-tauri/src/proxy/providers/models/anthropic.rs | //! Anthropic API 数据模型
//!
//! 用于 Anthropic Messages API 的请求/响应格式转换
use serde::{Deserialize, Serialize};
use serde_json::Value;
/// Anthropic 请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnthropicRequest {
pub model: String,
pub messages: Vec<AnthropicMessage>,
pub max_tokens: u32,
#[... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/proxy/providers/models/mod.rs | src-tauri/src/proxy/providers/models/mod.rs | //! API 数据模型
//!
//! 定义 Anthropic 和 OpenAI API 的请求/响应结构
pub mod anthropic;
pub mod openai;
| rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/proxy/usage/parser.rs | src-tauri/src/proxy/usage/parser.rs | //! Response Parser - 从 API 响应中提取 token 使用量
//!
//! 支持多种 API 格式:
//! - Claude API (非流式和流式)
//! - OpenRouter (OpenAI 格式)
//! - Codex API (非流式和流式)
//! - Gemini API (非流式和流式)
use serde::{Deserialize, Serialize};
use serde_json::Value;
/// Token 使用量统计
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Tok... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/proxy/usage/logger.rs | src-tauri/src/proxy/usage/logger.rs | //! Usage Logger - 记录 API 请求使用情况
use super::calculator::{CostBreakdown, CostCalculator, ModelPricing};
use super::parser::TokenUsage;
use crate::database::Database;
use crate::error::AppError;
use crate::services::usage_stats::find_model_pricing_row;
use rust_decimal::Decimal;
use std::time::SystemTime;
/// 请求日志
#[de... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/proxy/usage/mod.rs | src-tauri/src/proxy/usage/mod.rs | //! Proxy Usage Tracking Module
//!
//! 提供 API 请求的使用量跟踪、成本计算和日志记录功能
pub mod calculator;
pub mod logger;
pub mod parser;
// 仅导出内部使用的类型,避免未使用警告
#[allow(unused_imports)]
pub use calculator::{CostBreakdown, CostCalculator, ModelPricing};
#[allow(unused_imports)]
pub use logger::{RequestLog, UsageLogger};
#[allow(unused_i... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/proxy/usage/calculator.rs | src-tauri/src/proxy/usage/calculator.rs | //! Cost Calculator - 计算 API 请求成本
//!
//! 使用高精度 Decimal 类型避免浮点数精度问题
use super::parser::TokenUsage;
use rust_decimal::Decimal;
use std::str::FromStr;
/// 成本明细
#[derive(Debug, Clone)]
pub struct CostBreakdown {
pub input_cost: Decimal,
pub output_cost: Decimal,
pub cache_read_cost: Decimal,
pub cache_cr... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/config.rs | src-tauri/src/commands/config.rs | #![allow(non_snake_case)]
use tauri::AppHandle;
use tauri_plugin_dialog::DialogExt;
use tauri_plugin_opener::OpenerExt;
use crate::app_config::AppType;
use crate::codex_config;
use crate::config::{self, get_claude_settings_path, ConfigStatus};
use crate::settings;
/// 获取 Claude Code 配置状态
#[tauri::command]
pub async ... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/misc.rs | src-tauri/src/commands/misc.rs | #![allow(non_snake_case)]
use crate::init_status::{InitErrorPayload, SkillsMigrationPayload};
use tauri::AppHandle;
use tauri_plugin_opener::OpenerExt;
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
#[cfg(target_os = "windows")]
const CREATE_NO_WINDOW: u32 = 0x08000000;
/// 打开外部链接
#[tauri:... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/settings.rs | src-tauri/src/commands/settings.rs | #![allow(non_snake_case)]
use tauri::AppHandle;
/// 获取设置
#[tauri::command]
pub async fn get_settings() -> Result<crate::settings::AppSettings, String> {
Ok(crate::settings::get_settings())
}
/// 保存设置
#[tauri::command]
pub async fn save_settings(settings: crate::settings::AppSettings) -> Result<bool, String> {
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/mcp.rs | src-tauri/src/commands/mcp.rs | #![allow(non_snake_case)]
use indexmap::IndexMap;
use std::collections::HashMap;
use serde::Serialize;
use tauri::State;
use crate::app_config::AppType;
use crate::claude_mcp;
use crate::services::McpService;
use crate::store::AppState;
/// 获取 Claude MCP 状态
#[tauri::command]
pub async fn get_claude_mcp_status() -> ... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/deeplink.rs | src-tauri/src/commands/deeplink.rs | use crate::deeplink::{
import_mcp_from_deeplink, import_prompt_from_deeplink, import_provider_from_deeplink,
import_skill_from_deeplink, parse_deeplink_url, DeepLinkImportRequest,
};
use crate::store::AppState;
use tauri::State;
/// Parse a deep link URL and return the parsed request for frontend confirmation
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/stream_check.rs | src-tauri/src/commands/stream_check.rs | //! 流式健康检查命令
use crate::app_config::AppType;
use crate::error::AppError;
use crate::services::stream_check::{
HealthStatus, StreamCheckConfig, StreamCheckResult, StreamCheckService,
};
use crate::store::AppState;
use std::collections::HashSet;
use tauri::State;
/// 流式健康检查(单个供应商)
#[tauri::command]
pub async fn str... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/env.rs | src-tauri/src/commands/env.rs | use crate::services::env_checker::{check_env_conflicts as check_conflicts, EnvConflict};
use crate::services::env_manager::{
delete_env_vars as delete_vars, restore_from_backup, BackupInfo,
};
/// Check environment variable conflicts for a specific app
#[tauri::command]
pub fn check_env_conflicts(app: String) -> R... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/prompt.rs | src-tauri/src/commands/prompt.rs | use indexmap::IndexMap;
use std::str::FromStr;
use tauri::State;
use crate::app_config::AppType;
use crate::prompt::Prompt;
use crate::services::PromptService;
use crate::store::AppState;
#[tauri::command]
pub async fn get_prompts(
app: String,
state: State<'_, AppState>,
) -> Result<IndexMap<String, Prompt>... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/skill.rs | src-tauri/src/commands/skill.rs | //! Skills 命令层
//!
//! v3.10.0+ 统一管理架构:
//! - 支持三应用开关(Claude/Codex/Gemini)
//! - SSOT 存储在 ~/.cc-switch/skills/
use crate::app_config::{AppType, InstalledSkill, UnmanagedSkill};
use crate::error::format_skill_error;
use crate::services::skill::{DiscoverableSkill, Skill, SkillRepo, SkillService};
use crate::store::AppSt... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/mod.rs | src-tauri/src/commands/mod.rs | #![allow(non_snake_case)]
mod config;
mod deeplink;
mod env;
mod failover;
mod import_export;
mod mcp;
mod misc;
mod plugin;
mod prompt;
mod provider;
mod proxy;
mod settings;
pub mod skill;
mod stream_check;
mod usage;
pub use config::*;
pub use deeplink::*;
pub use env::*;
pub use failover::*;
pub use import_export... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/failover.rs | src-tauri/src/commands/failover.rs | //! 故障转移队列命令
//!
//! 管理代理模式下的故障转移队列(基于 providers 表的 in_failover_queue 字段)
use crate::database::FailoverQueueItem;
use crate::provider::Provider;
use crate::store::AppState;
/// 获取故障转移队列
#[tauri::command]
pub async fn get_failover_queue(
state: tauri::State<'_, AppState>,
app_type: String,
) -> Result<Vec<Fail... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/import_export.rs | src-tauri/src/commands/import_export.rs | #![allow(non_snake_case)]
use serde_json::{json, Value};
use std::path::PathBuf;
use tauri::State;
use tauri_plugin_dialog::DialogExt;
use crate::error::AppError;
use crate::services::provider::ProviderService;
use crate::store::AppState;
/// 导出数据库为 SQL 备份
#[tauri::command]
pub async fn export_config_to_file(
#[... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/proxy.rs | src-tauri/src/commands/proxy.rs | //! 代理服务相关的 Tauri 命令
//!
//! 提供前端调用的 API 接口
use crate::proxy::types::*;
use crate::proxy::{CircuitBreakerConfig, CircuitBreakerStats};
use crate::store::AppState;
/// 启动代理服务器(仅启动服务,不接管 Live 配置)
#[tauri::command]
pub async fn start_proxy_server(
state: tauri::State<'_, AppState>,
) -> Result<ProxyServerInfo, Strin... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/provider.rs | src-tauri/src/commands/provider.rs | use indexmap::IndexMap;
use tauri::State;
use crate::app_config::AppType;
use crate::error::AppError;
use crate::provider::Provider;
use crate::services::{EndpointLatency, ProviderService, ProviderSortUpdate, SpeedtestService};
use crate::store::AppState;
use std::str::FromStr;
/// 获取所有供应商
#[tauri::command]
pub fn ge... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/usage.rs | src-tauri/src/commands/usage.rs | //! 使用统计相关命令
use crate::error::AppError;
use crate::services::usage_stats::*;
use crate::store::AppState;
use tauri::State;
/// 获取使用量汇总
#[tauri::command]
pub fn get_usage_summary(
state: State<'_, AppState>,
start_date: Option<i64>,
end_date: Option<i64>,
) -> Result<UsageSummary, AppError> {
state.db... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/commands/plugin.rs | src-tauri/src/commands/plugin.rs | #![allow(non_snake_case)]
use crate::config::ConfigStatus;
/// Claude 插件:获取 ~/.claude/config.json 状态
#[tauri::command]
pub async fn get_claude_plugin_status() -> Result<ConfigStatus, String> {
crate::claude_plugin::claude_config_status()
.map(|(exists, path)| ConfigStatus {
exists,
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/tests.rs | src-tauri/src/database/tests.rs | //! 数据库模块测试
//!
//! 包含 Schema 迁移和基本功能的测试。
use super::*;
use crate::app_config::MultiAppConfig;
use crate::provider::{Provider, ProviderManager};
use indexmap::IndexMap;
use rusqlite::Connection;
use serde_json::json;
use std::collections::HashMap;
const LEGACY_SCHEMA_SQL: &str = r#"
CREATE TABLE providers (
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/schema.rs | src-tauri/src/database/schema.rs | //! Schema 定义和迁移
//!
//! 负责数据库表结构的创建和版本迁移。
use super::{lock_conn, Database, SCHEMA_VERSION};
use crate::error::AppError;
use rusqlite::Connection;
impl Database {
/// 创建所有数据库表
pub(crate) fn create_tables(&self) -> Result<(), AppError> {
let conn = lock_conn!(self.conn);
Self::create_tables_on_... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | true |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/mod.rs | src-tauri/src/database/mod.rs | //! 数据库模块 - SQLite 数据持久化
//!
//! 此模块提供应用的核心数据存储功能,包括:
//! - 供应商配置管理
//! - MCP 服务器配置
//! - 提示词管理
//! - Skills 管理
//! - 通用设置存储
//!
//! ## 架构设计
//!
//! ```text
//! database/
//! ├── mod.rs - Database 结构体 + 初始化
//! ├── schema.rs - 表结构定义 + Schema 迁移
//! ├── backup.rs - SQL 导入导出 + 快照备份
//! ├── migration.rs - ... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/backup.rs | src-tauri/src/database/backup.rs | //! 数据库备份和恢复
//!
//! 提供 SQL 导出/导入和二进制快照备份功能。
use super::{lock_conn, Database, DB_BACKUP_RETAIN};
use crate::config::get_app_config_dir;
use crate::error::AppError;
use chrono::Utc;
use rusqlite::backup::Backup;
use rusqlite::types::ValueRef;
use rusqlite::Connection;
use std::fs;
use std::path::{Path, PathBuf};
use te... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/migration.rs | src-tauri/src/database/migration.rs | //! JSON → SQLite 数据迁移
//!
//! 将旧版 config.json (MultiAppConfig) 数据迁移到 SQLite 数据库。
use super::{lock_conn, to_json_string, Database};
use crate::app_config::MultiAppConfig;
use crate::error::AppError;
use rusqlite::{params, Connection};
impl Database {
/// 从 MultiAppConfig 迁移数据到数据库
pub fn migrate_from_json(&sel... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/settings.rs | src-tauri/src/database/dao/settings.rs | //! 通用设置数据访问对象
//!
//! 提供键值对形式的通用设置存储。
use crate::database::{lock_conn, Database};
use crate::error::AppError;
use rusqlite::params;
impl Database {
/// 获取设置值
pub fn get_setting(&self, key: &str) -> Result<Option<String>, AppError> {
let conn = lock_conn!(self.conn);
let mut stmt = conn
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/mcp.rs | src-tauri/src/database/dao/mcp.rs | //! MCP 服务器数据访问对象
//!
//! 提供 MCP 服务器的 CRUD 操作。
use crate::app_config::{McpApps, McpServer};
use crate::database::{lock_conn, Database};
use crate::error::AppError;
use indexmap::IndexMap;
use rusqlite::params;
impl Database {
/// 获取所有 MCP 服务器
pub fn get_all_mcp_servers(&self) -> Result<IndexMap<String, McpSer... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/stream_check.rs | src-tauri/src/database/dao/stream_check.rs | //! 流式健康检查日志 DAO
use crate::database::{lock_conn, Database};
use crate::error::AppError;
use crate::services::stream_check::{StreamCheckConfig, StreamCheckResult};
impl Database {
/// 保存流式检查日志
pub fn save_stream_check_log(
&self,
provider_id: &str,
provider_name: &str,
app_type... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/prompts.rs | src-tauri/src/database/dao/prompts.rs | //! 提示词数据访问对象
//!
//! 提供提示词(Prompt)的 CRUD 操作。
use crate::database::{lock_conn, Database};
use crate::error::AppError;
use crate::prompt::Prompt;
use indexmap::IndexMap;
use rusqlite::params;
impl Database {
/// 获取指定应用类型的所有提示词
pub fn get_prompts(&self, app_type: &str) -> Result<IndexMap<String, Prompt>, AppErr... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/mod.rs | src-tauri/src/database/dao/mod.rs | //! Data Access Object layer
//!
//! Database access operations for each domain
pub mod failover;
pub mod mcp;
pub mod prompts;
pub mod providers;
pub mod proxy;
pub mod settings;
pub mod skills;
pub mod stream_check;
pub mod universal_providers;
// 所有 DAO 方法都通过 Database impl 提供,无需单独导出
// 导出 FailoverQueueItem 供外部使用
p... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/failover.rs | src-tauri/src/database/dao/failover.rs | //! 故障转移队列 DAO
//!
//! 管理代理模式下的故障转移队列(基于 providers 表的 in_failover_queue 字段)
use crate::database::{lock_conn, Database};
use crate::error::AppError;
use crate::provider::Provider;
use serde::{Deserialize, Serialize};
/// 故障转移队列条目(简化版,用于前端展示)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCa... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/universal_providers.rs | src-tauri/src/database/dao/universal_providers.rs | //! 统一供应商 (Universal Provider) DAO
//!
//! 提供统一供应商的 CRUD 操作。
use crate::database::{lock_conn, to_json_string, Database};
use crate::error::AppError;
use crate::provider::UniversalProvider;
use std::collections::HashMap;
/// 统一供应商的 Settings Key
const UNIVERSAL_PROVIDERS_KEY: &str = "universal_providers";
impl Databas... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/skills.rs | src-tauri/src/database/dao/skills.rs | //! Skills 数据访问对象
//!
//! 提供 Skills 和 Skill Repos 的 CRUD 操作。
//!
//! v3.10.0+ 统一管理架构:
//! - Skills 使用统一的 id 主键,支持三应用启用标志
//! - 实际文件存储在 ~/.cc-switch/skills/,同步到各应用目录
use crate::app_config::{InstalledSkill, SkillApps};
use crate::database::{lock_conn, Database};
use crate::error::AppError;
use crate::services::skill::Sk... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/proxy.rs | src-tauri/src/database/dao/proxy.rs | //! 代理功能数据访问层
//!
//! 处理代理配置、Provider健康状态和使用统计的数据库操作
use crate::error::AppError;
use crate::proxy::types::*;
use super::super::{lock_conn, Database};
impl Database {
// ==================== Global Proxy Config ====================
/// 获取全局代理配置(统一字段)
///
/// 从 claude 行读取(三行镜像一致)
pub async fn get_... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/database/dao/providers.rs | src-tauri/src/database/dao/providers.rs | //! 供应商数据访问对象
//!
//! 提供供应商(Provider)的 CRUD 操作。
use crate::database::{lock_conn, Database};
use crate::error::AppError;
use crate::provider::{Provider, ProviderMeta};
use indexmap::IndexMap;
use rusqlite::params;
use std::collections::HashMap;
impl Database {
/// 获取指定应用类型的所有供应商
pub fn get_all_providers(
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/mcp/claude.rs | src-tauri/src/mcp/claude.rs | //! Claude MCP 同步和导入模块
use serde_json::Value;
use std::collections::HashMap;
use crate::app_config::{McpApps, McpConfig, McpServer, MultiAppConfig};
use crate::error::AppError;
use super::validation::{extract_server_spec, validate_server_spec};
fn should_sync_claude_mcp() -> bool {
// Claude 未安装/未初始化时:通常 ~/.cla... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/mcp/validation.rs | src-tauri/src/mcp/validation.rs | //! MCP 服务器配置验证模块
use serde_json::Value;
use crate::error::AppError;
/// 基础校验:允许 stdio/http/sse;或省略 type(视为 stdio)。对应必填字段存在
pub fn validate_server_spec(spec: &Value) -> Result<(), AppError> {
if !spec.is_object() {
return Err(AppError::McpValidation(
"MCP 服务器连接定义必须为 JSON 对象".into(),
)... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/mcp/mod.rs | src-tauri/src/mcp/mod.rs | //! MCP (Model Context Protocol) 服务器管理模块
//!
//! 本模块负责 MCP 服务器配置的验证、同步和导入导出。
//!
//! ## 模块结构
//!
//! - `validation` - 服务器配置验证
//! - `claude` - Claude MCP 同步和导入
//! - `codex` - Codex MCP 同步和导入(含 TOML 转换)
//! - `gemini` - Gemini MCP 同步和导入
mod claude;
mod codex;
mod gemini;
mod validation;
// 重新导出公共 API
pub use claude::... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/mcp/gemini.rs | src-tauri/src/mcp/gemini.rs | //! Gemini MCP 同步和导入模块
use serde_json::Value;
use std::collections::HashMap;
use crate::app_config::{McpApps, McpConfig, McpServer, MultiAppConfig};
use crate::error::AppError;
use super::validation::{extract_server_spec, validate_server_spec};
fn should_sync_gemini_mcp() -> bool {
// Gemini 未安装/未初始化时:~/.gemini... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/mcp/codex.rs | src-tauri/src/mcp/codex.rs | //! Codex MCP 同步和导入模块
//!
//! 包含 Codex 的 MCP 配置管理:
//! - 从 ~/.codex/config.toml 导入
//! - 同步到 ~/.codex/config.toml
//! - JSON 到 TOML 的转换逻辑
use serde_json::{json, Value};
use std::collections::HashMap;
use crate::app_config::{McpApps, McpConfig, McpServer, MultiAppConfig};
use crate::error::AppError;
use super::valida... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/tests.rs | src-tauri/src/deeplink/tests.rs | //! Deep link module tests
use super::mcp::parse_mcp_apps;
use super::parser::parse_deeplink_url;
use super::prompt::import_prompt_from_deeplink;
use super::provider::parse_and_merge_config;
use super::utils::{infer_homepage_from_endpoint, validate_url};
use super::DeepLinkImportRequest;
use crate::AppType;
use crate:... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/mcp.rs | src-tauri/src/deeplink/mcp.rs | //! MCP server import from deep link
//!
//! Handles batch import of MCP server configurations via ccswitch:// URLs.
use super::utils::decode_base64_param;
use super::DeepLinkImportRequest;
use crate::app_config::{McpApps, McpServer};
use crate::error::AppError;
use crate::services::McpService;
use crate::store::AppSt... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/parser.rs | src-tauri/src/deeplink/parser.rs | //! Deep link URL parser
//!
//! Parses ccswitch:// URLs into DeepLinkImportRequest structures.
use super::utils::validate_url;
use super::DeepLinkImportRequest;
use crate::error::AppError;
use std::collections::HashMap;
use url::Url;
/// Parse a ccswitch:// URL into a DeepLinkImportRequest
///
/// Expected format:
/... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/utils.rs | src-tauri/src/deeplink/utils.rs | //! Deep link utility functions
//!
//! Common helpers for URL validation, Base64 decoding, etc.
use crate::error::AppError;
use base64::prelude::*;
use url::Url;
/// Validate that a string is a valid HTTP(S) URL
pub fn validate_url(url_str: &str, field_name: &str) -> Result<(), AppError> {
let url = Url::parse(u... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/prompt.rs | src-tauri/src/deeplink/prompt.rs | //! Prompt import from deep link
//!
//! Handles importing prompt configurations via ccswitch:// URLs.
use super::utils::decode_base64_param;
use super::DeepLinkImportRequest;
use crate::error::AppError;
use crate::prompt::Prompt;
use crate::services::PromptService;
use crate::store::AppState;
use crate::AppType;
use ... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/skill.rs | src-tauri/src/deeplink/skill.rs | //! Skill import from deep link
//!
//! Handles importing skill repository configurations via ccswitch:// URLs.
use super::DeepLinkImportRequest;
use crate::error::AppError;
use crate::services::skill::SkillRepo;
use crate::store::AppState;
/// Import a skill from deep link request
pub fn import_skill_from_deeplink(
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/mod.rs | src-tauri/src/deeplink/mod.rs | //! Deep link import functionality for CC Switch
//!
//! This module implements the ccswitch:// protocol for importing configurations
//! via deep links. Supports importing:
//! - Provider configurations (Claude/Codex/Gemini)
//! - MCP server configurations
//! - Prompts
//! - Skills
//!
//! See docs/ccswitch-deeplink-... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/src/deeplink/provider.rs | src-tauri/src/deeplink/provider.rs | //! Provider import from deep link
//!
//! Handles importing provider configurations via ccswitch:// URLs.
use super::utils::{decode_base64_param, infer_homepage_from_endpoint};
use super::DeepLinkImportRequest;
use crate::error::AppError;
use crate::provider::{Provider, ProviderMeta, UsageScript};
use crate::services... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/provider_commands.rs | src-tauri/tests/provider_commands.rs | use serde_json::json;
use cc_switch_lib::{
get_codex_auth_path, get_codex_config_path, read_json_file, switch_provider_test_hook,
write_codex_live_atomic, AppError, AppType, McpApps, McpServer, MultiAppConfig, Provider,
};
#[path = "support.rs"]
mod support;
use std::collections::HashMap;
use support::{create... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/deeplink_import.rs | src-tauri/tests/deeplink_import.rs | use std::sync::Arc;
use cc_switch_lib::{
import_provider_from_deeplink, parse_deeplink_url, AppState, Database, ProxyService,
};
#[path = "support.rs"]
mod support;
use support::{ensure_test_home, reset_test_fs, test_mutex};
#[test]
fn deeplink_import_claude_provider_persists_to_db() {
let _guard = test_mute... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/support.rs | src-tauri/tests/support.rs | use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, OnceLock};
use cc_switch_lib::{
update_settings, AppSettings, AppState, Database, MultiAppConfig, ProxyService,
};
/// 为测试设置隔离的 HOME 目录,避免污染真实用户数据。
pub fn ensure_test_home() -> &'static Path {
static HOME: OnceLock<PathBuf> = OnceLock::new();
HOM... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/app_type_parse.rs | src-tauri/tests/app_type_parse.rs | use std::str::FromStr;
use cc_switch_lib::AppType;
#[test]
fn parse_known_apps_case_insensitive_and_trim() {
assert!(matches!(AppType::from_str("claude"), Ok(AppType::Claude)));
assert!(matches!(AppType::from_str("codex"), Ok(AppType::Codex)));
assert!(matches!(
AppType::from_str(" ClAuDe \n"),
... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/import_export_sync.rs | src-tauri/tests/import_export_sync.rs | use serde_json::json;
use std::fs;
use std::path::PathBuf;
use cc_switch_lib::{
get_claude_settings_path, read_json_file, AppError, AppType, ConfigService, MultiAppConfig,
Provider, ProviderMeta,
};
#[path = "support.rs"]
mod support;
use support::{
create_test_state, create_test_state_with_config, ensure... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | true |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/app_config_load.rs | src-tauri/tests/app_config_load.rs | use std::fs;
use std::path::PathBuf;
use cc_switch_lib::{AppError, MultiAppConfig};
mod support;
use support::{ensure_test_home, reset_test_fs, test_mutex};
fn cfg_path() -> PathBuf {
let home = std::env::var("HOME").expect("HOME should be set by ensure_test_home");
PathBuf::from(home).join(".cc-switch").joi... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/mcp_commands.rs | src-tauri/tests/mcp_commands.rs | use std::collections::HashMap;
use std::fs;
use serde_json::json;
use cc_switch_lib::{
get_claude_mcp_path, get_claude_settings_path, import_default_config_test_hook, AppError,
AppType, McpApps, McpServer, McpService, MultiAppConfig,
};
#[path = "support.rs"]
mod support;
use support::{create_test_state_with... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
farion1231/cc-switch | https://github.com/farion1231/cc-switch/blob/32149b1eeb6663445ffbd956d38631109935407b/src-tauri/tests/provider_service.rs | src-tauri/tests/provider_service.rs | use serde_json::json;
use cc_switch_lib::{
get_claude_settings_path, read_json_file, write_codex_live_atomic, AppError, AppType, McpApps,
McpServer, MultiAppConfig, Provider, ProviderMeta, ProviderService,
};
#[path = "support.rs"]
mod support;
use support::{
create_test_state, create_test_state_with_conf... | rust | MIT | 32149b1eeb6663445ffbd956d38631109935407b | 2026-01-04T15:46:09.354064Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/build.rs | build.rs | #[cfg(feature = "embedded_assets")]
use std::{env, path::Path};
fn main() {
#[cfg(feature = "embedded_assets")]
embedded_assets_main();
#[cfg(not(feature = "embedded_assets"))]
{
// No-op when feature is disabled
}
}
#[cfg(feature = "embedded_assets")]
fn embedded_assets_main() {
// I... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/initializers/view_engine.rs | loco-new/base_template/src/initializers/view_engine.rs | use async_trait::async_trait;
use axum::{Extension, Router as AxumRouter};
use fluent_templates::{ArcLoader, FluentLoader};
use loco_rs::{
app::{AppContext, Initializer},
controller::views::{engines, ViewEngine},
Error, Result,
};
use tracing::info;
const I18N_DIR: &str = "assets/i18n";
const I18N_SHARED: ... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/tasks/user_create.rs | loco-new/base_template/src/tasks/user_create.rs | use loco_rs::prelude::*;
use crate::{
mailers::auth::AuthMailer,
models::{_entities::users, users::RegisterParams},
};
pub struct UserCreate;
#[async_trait]
impl Task for UserCreate {
fn task(&self) -> TaskInfo {
TaskInfo {
name: "user:create".to_string(),
detail: "Create a... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/workers/downloader.rs | loco-new/base_template/src/workers/downloader.rs | use loco_rs::prelude::*;
use serde::{Deserialize, Serialize};
pub struct DownloadWorker {
pub ctx: AppContext,
}
#[derive(Deserialize, Debug, Serialize)]
pub struct DownloadWorkerArgs {
pub user_guid: String,
}
#[async_trait]
impl BackgroundWorker<DownloadWorkerArgs> for DownloadWorker {
fn build(ctx: &A... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/controllers/home.rs | loco-new/base_template/src/controllers/home.rs | use loco_rs::prelude::*;
use crate::views::home::HomeResponse;
#[debug_handler]
async fn current() -> Result<Response> {
format::json(HomeResponse::new("loco"))
}
pub fn routes() -> Routes {
Routes::new().prefix("/api").add("/", get(current))
}
| rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/controllers/auth.rs | loco-new/base_template/src/controllers/auth.rs | use crate::{
mailers::auth::AuthMailer,
models::{
_entities::users,
users::{LoginParams, RegisterParams},
},
views::auth::{CurrentResponse, LoginResponse},
};
use loco_rs::prelude::*;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::sync::OnceLock;
pub static EMAIL_DOMAIN... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/models/users.rs | loco-new/base_template/src/models/users.rs | use async_trait::async_trait;
use chrono::{offset::Local, Duration};
use loco_rs::{auth::jwt, hash, prelude::*};
use serde::{Deserialize, Serialize};
use serde_json::Map;
use uuid::Uuid;
pub use super::_entities::users::{self, ActiveModel, Entity, Model};
pub const MAGIC_LINK_LENGTH: i8 = 32;
pub const MAGIC_LINK_EXP... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/models/_entities/users.rs | loco-new/base_template/src/models/_entities/users.rs | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "users")]
pub struct Model {
pub created_at: DateTimeWithTimeZone,
pub updated... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/views/home.rs | loco-new/base_template/src/views/home.rs | use serde::{Deserialize, Serialize};
impl HomeResponse {
#[must_use]
pub fn new(app_name: &str) -> Self {
Self {
app_name: app_name.to_string(),
}
}
}
#[derive(Debug, Deserialize, Serialize)]
#[allow(clippy::module_name_repetitions)]
pub struct HomeResponse {
pub app_name: ... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/views/auth.rs | loco-new/base_template/src/views/auth.rs | use serde::{Deserialize, Serialize};
use crate::models::_entities::users;
#[derive(Debug, Deserialize, Serialize)]
pub struct LoginResponse {
pub token: String,
pub pid: String,
pub name: String,
pub is_verified: bool,
}
impl LoginResponse {
#[must_use]
pub fn new(user: &users::Model, token: ... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/mailers/auth.rs | loco-new/base_template/src/mailers/auth.rs | // auth mailer
#![allow(non_upper_case_globals)]
use loco_rs::prelude::*;
use serde_json::json;
use crate::models::users;
static welcome: Dir<'_> = include_dir!("src/mailers/auth/welcome");
static forgot: Dir<'_> = include_dir!("src/mailers/auth/forgot");
static magic_link: Dir<'_> = include_dir!("src/mailers/auth/m... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/src/mailers/mod.rs | loco-new/base_template/src/mailers/mod.rs | pub mod auth;
| rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/tests/workers/mod.rs | loco-new/base_template/tests/workers/mod.rs | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false | |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/base_template/migration/src/m20220101_000001_users.rs | loco-new/base_template/migration/src/m20220101_000001_users.rs | use loco_rs::schema::*;
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
create_table(
m,
"users",
&[
... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/settings.rs | loco-new/src/settings.rs | //! Defines configurable application settings.
use std::env;
use heck::ToSnakeCase;
#[allow(unused_imports)]
use rhai::{CustomType, Dynamic, EvalAltResult, Position, TypeBuilder};
use serde::{Deserialize, Serialize};
use crate::{
wizard::{self, AssetsOption, BackgroundOption, DBOption},
LOCO_VERSION, OS,
};
... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/lib.rs | loco-new/src/lib.rs | use clap::ValueEnum;
use serde::{Deserialize, Serialize};
use strum::Display;
pub mod generator;
pub mod settings;
pub mod wizard;
pub type Result<T> = std::result::Result<T, Error>;
/// Matching minimal Loco version.
pub const LOCO_VERSION: &str = "0.16";
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[e... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/wizard.rs | loco-new/src/wizard.rs | //! This module provides interactive utilities for setting up application
//! configurations based on user input.
use clap::ValueEnum;
use colored::Colorize;
use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select};
use serde::{Deserialize, Serialize};
use strum::{Display, EnumIter, IntoEnumIterator};
use crate:... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/generator/template.rs | loco-new/src/generator/template.rs | //! This module defines a `Template` struct for handling template files.
use std::{
collections::HashMap,
path::{Path, PathBuf},
sync::{Arc, Mutex},
};
use rand::{distributions::Alphanumeric, rngs::StdRng, Rng, SeedableRng};
use tera::{Context, Tera};
use crate::settings::Settings;
const TEMPLATE_EXTENS... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/generator/mod.rs | loco-new/src/generator/mod.rs | //! This module defines the `Generator` struct, which is responsible for
//! executing scripted commands
use std::path::Path;
pub mod executer;
pub mod template;
use std::sync::Arc;
use include_dir::{include_dir, Dir};
use rhai::{
export_module, exported_module,
plugin::{
Dynamic, FnNamespace, FuncReg... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/generator/executer/inmem.rs | loco-new/src/generator/executer/inmem.rs | use std::{
collections::BTreeMap,
path::{Path, PathBuf},
sync::Mutex,
};
use super::Executer;
use crate::{generator, settings::Settings};
pub struct Inmem {
pub source_path: PathBuf,
pub file_store: Mutex<BTreeMap<PathBuf, String>>,
pub template_engine: generator::template::Template,
}
impl I... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/generator/executer/filesystem.rs | loco-new/src/generator/executer/filesystem.rs | use std::path::{Path, PathBuf};
use fs_extra::file::{move_file, write_all};
use walkdir::WalkDir;
use super::Executer;
use crate::{generator, settings::Settings};
#[derive(Debug, Default, Clone)]
pub struct FileSystem {
pub source_dir: PathBuf,
pub target_dir: PathBuf,
pub template_engine: generator::tem... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/generator/executer/mod.rs | loco-new/src/generator/executer/mod.rs | //! This module defines error handling and the [`Executer`] trait
use crate::settings::Settings;
mod filesystem;
mod inmem;
use std::path::{Path, PathBuf};
pub use filesystem::FileSystem;
pub use inmem::Inmem;
#[cfg(test)]
use mockall::{automock, predicate::*};
pub type Result<T> = std::result::Result<T, Error>;
#[... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/src/bin/main.rs | loco-new/src/bin/main.rs | use std::{
env,
path::{Path, PathBuf},
process::{exit, Command},
sync::Arc,
};
use clap::{Parser, Subcommand};
use duct::cmd;
use loco::{
generator::{executer, extract_default_template, Generator},
settings::Settings,
wizard, Result, OS,
};
use tracing::level_filters::LevelFilter;
use traci... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/mod.rs | loco-new/tests/mod.rs | mod templates;
mod wizard;
pub mod assertion;
| rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/wizard/mod.rs | loco-new/tests/wizard/mod.rs | mod new;
| rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/wizard/new.rs | loco-new/tests/wizard/new.rs | use std::{collections::HashMap, path::PathBuf, process::Output, sync::Arc};
use duct::cmd;
use loco::{
generator::{executer::FileSystem, Generator},
settings,
wizard::{self, AssetsOption, BackgroundOption, DBOption},
OS,
};
// #[cfg(feature = "test-wizard")]
// #[rstest::rstest]
// fn test_all_combina... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/db.rs | loco-new/tests/templates/db.rs | use loco::{settings, wizard::DBOption};
use rstest::rstest;
use super::*;
use crate::assertion;
pub fn run_generator(db: DBOption) -> TestGenerator {
let settings = settings::Settings {
package_name: "loco-app-test".to_string(),
module_name: "loco_app_test".to_string(),
db: db.into(),
... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/initializers.rs | loco-new/tests/templates/initializers.rs | use loco::settings;
use rstest::rstest;
use super::*;
use crate::assertion;
pub fn run_generator(initializers: Option<settings::Initializers>) -> TestGenerator {
let settings = settings::Settings {
initializers,
..Default::default()
};
TestGenerator::generate(settings)
}
#[test]
fn test_... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/mailer.rs | loco-new/tests/templates/mailer.rs | use loco::settings;
use rstest::rstest;
use super::*;
use crate::assertion;
pub fn run_generator(enable_mailer: bool) -> TestGenerator {
let settings = settings::Settings {
mailer: enable_mailer,
..Default::default()
};
TestGenerator::generate(settings)
}
#[rstest]
fn test_config_file_wi... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/module_name.rs | loco-new/tests/templates/module_name.rs | use loco::{settings, wizard::DBOption};
use rstest::rstest;
use super::*;
use crate::assertion;
pub fn run_generator() -> TestGenerator {
let settings = settings::Settings {
package_name: "loco-app-test".to_string(),
module_name: "loco_app_test".to_string(),
..Default::default()
};
... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/asset.rs | loco-new/tests/templates/asset.rs | use loco::{settings, wizard::AssetsOption};
use rstest::rstest;
use super::*;
use crate::assertion;
pub fn run_generator(asset: AssetsOption) -> TestGenerator {
let settings = settings::Settings {
asset: asset.into(),
..Default::default()
};
TestGenerator::generate(settings)
}
#[rstest]
... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/auth.rs | loco-new/tests/templates/auth.rs | use loco::{settings, wizard::DBOption};
use rstest::rstest;
use super::*;
use crate::assertion;
pub fn run_generator(enable_auth: bool, db: DBOption) -> TestGenerator {
let settings = settings::Settings {
package_name: "loco-app-test".to_string(),
module_name: "loco_app_test".to_string(),
... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/mod.rs | loco-new/tests/templates/mod.rs | use std::{
path::{Path, PathBuf},
sync::Arc,
};
use loco::{
generator::{self, executer::FileSystem, template},
settings,
};
use rand::{rngs::StdRng, SeedableRng};
mod asset;
mod auth;
mod background;
mod db;
mod features;
mod initializers;
mod mailer;
mod module_name;
pub struct TestGenerator {
t... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/features.rs | loco-new/tests/templates/features.rs | use loco::settings;
use super::*;
use crate::assertion;
pub fn run_generator(default_features: bool, names: &[&str]) -> TestGenerator {
let settings = settings::Settings {
features: settings::Features {
default_features,
names: names.iter().map(std::string::ToString::to_string).col... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/templates/background.rs | loco-new/tests/templates/background.rs | use loco::{settings, wizard::BackgroundOption};
use rstest::rstest;
use super::*;
use crate::assertion;
pub fn run_generator(background: BackgroundOption) -> TestGenerator {
let settings = settings::Settings {
background: background.into(),
..Default::default()
};
TestGenerator::generate(... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/assertion/string.rs | loco-new/tests/assertion/string.rs | #![allow(clippy::missing_panics_doc)]
use std::path::PathBuf;
use regex::Regex;
#[must_use]
pub fn load(path: PathBuf) -> String {
std::fs::read_to_string(path).expect("could not read file")
}
pub fn assert_line_regex(content: &str, expected: &str) {
let re = Regex::new(expected).unwrap();
// Use assert... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/assertion/mod.rs | loco-new/tests/assertion/mod.rs | pub mod string;
pub mod toml;
pub mod yaml;
| rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/assertion/yaml.rs | loco-new/tests/assertion/yaml.rs | #![allow(clippy::missing_panics_doc)]
use std::{fs::File, io::BufReader, path::PathBuf};
use serde_yaml::Value;
#[must_use]
pub fn load(path: PathBuf) -> serde_yaml::Value {
let file = File::open(path).expect("could not open file");
let reader = BufReader::new(file);
serde_yaml::from_reader(reader).expect... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/loco-new/tests/assertion/toml.rs | loco-new/tests/assertion/toml.rs | #![allow(clippy::missing_panics_doc)]
use std::path::PathBuf;
use toml::Value;
#[must_use]
pub fn load(path: PathBuf) -> toml::Value {
let s = std::fs::read_to_string(path).expect("could not open file");
toml::from_str(&s).expect("invalid toml content")
}
pub fn assert_path_value_eq_string(toml: &Value, path... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/src/db.rs | src/db.rs | //! # Database Operations
//!
//! This module defines functions and operations related to the application's
//! database interactions.
use super::Result as AppResult;
use crate::{
app::{AppContext, Hooks},
cargo_config::CargoConfig,
config, doctor, env_vars,
errors::Error,
};
use chrono::{DateTime, Utc... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | true |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/src/config.rs | src/config.rs | //! # Configuration Management
//!
//! This module defines the configuration structures and functions to manage and
//! load configuration settings for the application.
/***
=============
CONTRIBUTORS:
=============
Here's a check list when adding configuration values:
* Add the new configuration piece
* Document ea... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
loco-rs/loco | https://github.com/loco-rs/loco/blob/13984b401057515e321775ccbbed95a8d8463f5a/src/app.rs | src/app.rs | //! This module contains the core components and traits for building a web
//! server application.
#[cfg(feature = "with-db")]
use {sea_orm::DatabaseConnection, std::path::Path};
use std::{
any::{Any, TypeId},
net::SocketAddr,
sync::Arc,
};
use async_trait::async_trait;
use axum::Router as AxumRouter;
use... | rust | Apache-2.0 | 13984b401057515e321775ccbbed95a8d8463f5a | 2026-01-04T15:47:23.442679Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.