1
0

fix cargo

This commit is contained in:
2025-06-09 03:58:38 +09:00
parent 5ae075edd3
commit 142a5ac135
12 changed files with 42 additions and 25 deletions

View File

@ -26,7 +26,8 @@
"Bash(npm install:*)",
"WebFetch(domain:raw.githubusercontent.com)",
"WebFetch(domain:www.npmjs.com)",
"Bash(rm:*)"
"Bash(rm:*)",
"Bash(cargo:*)"
],
"deny": []
}

View File

@ -1,7 +1,6 @@
use sqlx::{Pool, Postgres, Sqlite, Row};
use sqlx::{Pool, Postgres, Sqlite};
use sqlx::migrate::MigrateDatabase;
use crate::error::{AppError, AppResult};
use std::str::FromStr;
#[derive(Clone)]
pub enum Database {
@ -20,7 +19,7 @@ impl Database {
Ok(Database::Postgres(pool))
} else if database_url.starts_with("sqlite://") {
// Extract the path from sqlite:// URL
let db_path = database_url.trim_start_matches("sqlite://");
let _db_path = database_url.trim_start_matches("sqlite://");
// Create the database file if it doesn't exist
if !Sqlite::database_exists(database_url).await.unwrap_or(false) {

View File

@ -40,7 +40,7 @@ async fn login(
.create_access_token(&user, state.settings.access_token_expire_minutes)?;
// Create or update user in database
let db_user = create_or_update_user(&state, &user.did, &user.handle).await?;
let _db_user = create_or_update_user(&state, &user.did, &user.handle).await?;
Ok(Json(LoginResponse {
access_token,

View File

@ -1,7 +1,3 @@
pub mod auth;
pub mod cards;
pub mod sync;
pub use auth::*;
pub use cards::*;
pub use sync::*;

View File

@ -6,7 +6,7 @@ use axum::{
};
use crate::{
error::{AppError, AppResult},
error::AppResult,
AppState,
};

View File

@ -1,15 +1,13 @@
use anyhow::Result;
use axum::{
extract::State,
http::StatusCode,
response::Json,
routing::{get, post},
routing::get,
Router,
};
use serde_json::{json, Value};
use std::net::SocketAddr;
use tower_http::cors::CorsLayer;
use tracing::{info, warn};
use tracing::info;
mod config;
mod database;

View File

@ -189,6 +189,7 @@ pub struct UserCardWithMaster {
/// Database query result for JOIN operations
#[derive(Debug, Clone, FromRow)]
#[allow(dead_code)]
pub struct UserCardWithMasterQuery {
// user_cards fields
pub id: i32,
@ -266,21 +267,25 @@ pub struct GachaProbabilities {
/// External Data Models (from ai.json)
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct ExternalCardData {
pub ai: AiData,
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct AiData {
pub card: CardData,
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct CardData {
pub cards: Vec<ExternalCard>,
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct ExternalCard {
pub id: i32,
pub name: String,
@ -291,17 +296,20 @@ pub struct ExternalCard {
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct CpRange {
pub min: i32,
pub max: i32,
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct LangData {
pub ja: Option<JapaneseData>,
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct JapaneseData {
pub name: Option<String>,
pub skill: Option<String>,

View File

@ -5,11 +5,13 @@ use crate::{
use reqwest::Client;
use serde_json::json;
#[allow(dead_code)]
pub struct AtprotoService {
client: Client,
session: Option<String>,
}
#[allow(dead_code)]
impl AtprotoService {
pub fn new() -> Self {
Self {
@ -18,6 +20,7 @@ impl AtprotoService {
}
}
#[allow(dead_code)]
pub fn with_session(session: String) -> Self {
Self {
client: Client::new(),
@ -26,11 +29,12 @@ impl AtprotoService {
}
/// Create a card record in user's atproto PDS
#[allow(dead_code)]
pub async fn create_card_record(
&self,
did: &str,
card: &UserCard,
master: &CardMaster,
_master: &CardMaster,
) -> AppResult<String> {
let session = self.session.as_ref()
.ok_or_else(|| AppError::authentication("No atproto session available"))?;
@ -81,6 +85,7 @@ impl AtprotoService {
}
/// List card records from user's PDS
#[allow(dead_code)]
pub async fn list_card_records(&self, did: &str) -> AppResult<Vec<serde_json::Value>> {
let session = self.session.as_ref()
.ok_or_else(|| AppError::authentication("No atproto session available"))?;
@ -119,6 +124,7 @@ impl AtprotoService {
}
/// Resolve PDS endpoint from DID
#[allow(dead_code)]
async fn resolve_pds_from_did(&self, did: &str) -> AppResult<String> {
// This is a simplified resolution
// In a real implementation, you would:
@ -141,6 +147,7 @@ impl AtprotoService {
}
/// Resolve PLC DID to PDS endpoint
#[allow(dead_code)]
async fn resolve_plc_did(&self, plc_id: &str) -> AppResult<String> {
let response = self
.client
@ -174,6 +181,7 @@ impl AtprotoService {
}
/// Authenticate with atproto and get session
#[allow(dead_code)]
pub async fn authenticate(&self, identifier: &str, password: &str) -> AppResult<(String, String)> {
// Try multiple PDS endpoints for authentication
let pds_endpoints = [
@ -193,6 +201,7 @@ impl AtprotoService {
}
/// Try authentication at a specific PDS
#[allow(dead_code)]
async fn try_authenticate_at_pds(
&self,
pds_url: &str,

View File

@ -3,13 +3,14 @@ use crate::{
models::*,
};
use reqwest::Client;
use std::collections::HashMap;
#[allow(dead_code)]
pub struct CardMasterService {
client: Client,
master_url: String,
}
#[allow(dead_code)]
impl CardMasterService {
pub fn new(master_url: String) -> Self {
Self {
@ -19,6 +20,7 @@ impl CardMasterService {
}
/// Fetch card master data from external source (ai.json)
#[allow(dead_code)]
pub async fn fetch_external_card_data(&self) -> AppResult<Vec<ExternalCard>> {
let response = self
.client
@ -44,6 +46,7 @@ impl CardMasterService {
}
/// Get fallback card data if external fetch fails
#[allow(dead_code)]
pub fn get_fallback_card_data(&self) -> Vec<ExternalCard> {
vec![
ExternalCard {
@ -178,6 +181,7 @@ impl CardMasterService {
}
/// Get card master data, trying external source first then fallback
#[allow(dead_code)]
pub async fn get_card_master_data(&self) -> Vec<ExternalCard> {
match self.fetch_external_card_data().await {
Ok(cards) => {
@ -192,6 +196,7 @@ impl CardMasterService {
}
/// Convert external card data to database format
#[allow(dead_code)]
pub fn external_to_card_master(external: &ExternalCard) -> CardMaster {
let description = if let Some(lang) = &external.lang {
if let Some(ja) = &lang.ja {

View File

@ -3,12 +3,9 @@ use crate::{
database::{Database, DatabaseTransaction},
error::{AppError, AppResult},
models::*,
query_as, query_one_as, query_optional_as,
services::CardMasterService,
};
use chrono::Utc;
use rand::Rng;
use std::collections::HashMap;
use uuid::Uuid;
pub struct GachaService {
@ -128,7 +125,7 @@ impl GachaService {
async fn select_card_master(
&self,
tx: &mut DatabaseTransaction,
rarity: &CardRarity,
_rarity: &CardRarity,
_pool_id: Option<i32>,
) -> AppResult<CardMaster> {
// For now, randomly select from all available cards

View File

@ -4,6 +4,3 @@ pub mod atproto;
pub mod user;
pub use gacha::GachaService;
pub use card_master::CardMasterService;
pub use atproto::AtprotoService;
pub use user::UserService;

View File

@ -5,8 +5,10 @@ use crate::{
};
use chrono::Utc;
#[allow(dead_code)]
pub struct UserService;
#[allow(dead_code)]
impl UserService {
pub async fn get_user_by_did(db: &Database, did: &str) -> AppResult<Option<User>> {
match db {
@ -27,6 +29,7 @@ impl UserService {
}
}
#[allow(dead_code)]
pub async fn create_user(db: &Database, did: &str, handle: &str) -> AppResult<User> {
let now = Utc::now();
@ -58,6 +61,7 @@ impl UserService {
}
}
#[allow(dead_code)]
pub async fn update_user_handle(db: &Database, did: &str, handle: &str) -> AppResult<User> {
let now = Utc::now();
@ -87,6 +91,7 @@ impl UserService {
}
}
#[allow(dead_code)]
pub async fn get_user_card_count(db: &Database, user_did: &str) -> AppResult<i64> {
match db {
Database::Postgres(pool) => {
@ -108,6 +113,7 @@ impl UserService {
}
}
#[allow(dead_code)]
pub async fn get_user_unique_card_count(db: &Database, user_did: &str) -> AppResult<i64> {
match db {
Database::Postgres(pool) => {
@ -133,6 +139,7 @@ impl UserService {
}
}
#[allow(dead_code)]
pub async fn get_user_cards_by_rarity(
db: &Database,
user_did: &str,