fix cargo
This commit is contained in:
@ -26,7 +26,8 @@
|
|||||||
"Bash(npm install:*)",
|
"Bash(npm install:*)",
|
||||||
"WebFetch(domain:raw.githubusercontent.com)",
|
"WebFetch(domain:raw.githubusercontent.com)",
|
||||||
"WebFetch(domain:www.npmjs.com)",
|
"WebFetch(domain:www.npmjs.com)",
|
||||||
"Bash(rm:*)"
|
"Bash(rm:*)",
|
||||||
|
"Bash(cargo:*)"
|
||||||
],
|
],
|
||||||
"deny": []
|
"deny": []
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use sqlx::{Pool, Postgres, Sqlite, Row};
|
use sqlx::{Pool, Postgres, Sqlite};
|
||||||
use sqlx::migrate::MigrateDatabase;
|
use sqlx::migrate::MigrateDatabase;
|
||||||
use crate::error::{AppError, AppResult};
|
use crate::error::{AppError, AppResult};
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Database {
|
pub enum Database {
|
||||||
@ -20,7 +19,7 @@ impl Database {
|
|||||||
Ok(Database::Postgres(pool))
|
Ok(Database::Postgres(pool))
|
||||||
} else if database_url.starts_with("sqlite://") {
|
} else if database_url.starts_with("sqlite://") {
|
||||||
// Extract the path from sqlite:// URL
|
// 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
|
// Create the database file if it doesn't exist
|
||||||
if !Sqlite::database_exists(database_url).await.unwrap_or(false) {
|
if !Sqlite::database_exists(database_url).await.unwrap_or(false) {
|
||||||
|
@ -40,7 +40,7 @@ async fn login(
|
|||||||
.create_access_token(&user, state.settings.access_token_expire_minutes)?;
|
.create_access_token(&user, state.settings.access_token_expire_minutes)?;
|
||||||
|
|
||||||
// Create or update user in database
|
// 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 {
|
Ok(Json(LoginResponse {
|
||||||
access_token,
|
access_token,
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod cards;
|
pub mod cards;
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
|
|
||||||
pub use auth::*;
|
|
||||||
pub use cards::*;
|
|
||||||
pub use sync::*;
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{AppError, AppResult},
|
error::AppResult,
|
||||||
AppState,
|
AppState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::State,
|
|
||||||
http::StatusCode,
|
|
||||||
response::Json,
|
response::Json,
|
||||||
routing::{get, post},
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
use tracing::{info, warn};
|
use tracing::info;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod database;
|
mod database;
|
||||||
|
@ -189,6 +189,7 @@ pub struct UserCardWithMaster {
|
|||||||
|
|
||||||
/// Database query result for JOIN operations
|
/// Database query result for JOIN operations
|
||||||
#[derive(Debug, Clone, FromRow)]
|
#[derive(Debug, Clone, FromRow)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct UserCardWithMasterQuery {
|
pub struct UserCardWithMasterQuery {
|
||||||
// user_cards fields
|
// user_cards fields
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
@ -266,21 +267,25 @@ pub struct GachaProbabilities {
|
|||||||
/// External Data Models (from ai.json)
|
/// External Data Models (from ai.json)
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct ExternalCardData {
|
pub struct ExternalCardData {
|
||||||
pub ai: AiData,
|
pub ai: AiData,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct AiData {
|
pub struct AiData {
|
||||||
pub card: CardData,
|
pub card: CardData,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct CardData {
|
pub struct CardData {
|
||||||
pub cards: Vec<ExternalCard>,
|
pub cards: Vec<ExternalCard>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct ExternalCard {
|
pub struct ExternalCard {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@ -291,17 +296,20 @@ pub struct ExternalCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct CpRange {
|
pub struct CpRange {
|
||||||
pub min: i32,
|
pub min: i32,
|
||||||
pub max: i32,
|
pub max: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct LangData {
|
pub struct LangData {
|
||||||
pub ja: Option<JapaneseData>,
|
pub ja: Option<JapaneseData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct JapaneseData {
|
pub struct JapaneseData {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub skill: Option<String>,
|
pub skill: Option<String>,
|
||||||
|
@ -5,11 +5,13 @@ use crate::{
|
|||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct AtprotoService {
|
pub struct AtprotoService {
|
||||||
client: Client,
|
client: Client,
|
||||||
session: Option<String>,
|
session: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
impl AtprotoService {
|
impl AtprotoService {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -18,6 +20,7 @@ impl AtprotoService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn with_session(session: String) -> Self {
|
pub fn with_session(session: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client: Client::new(),
|
client: Client::new(),
|
||||||
@ -26,11 +29,12 @@ impl AtprotoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a card record in user's atproto PDS
|
/// Create a card record in user's atproto PDS
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn create_card_record(
|
pub async fn create_card_record(
|
||||||
&self,
|
&self,
|
||||||
did: &str,
|
did: &str,
|
||||||
card: &UserCard,
|
card: &UserCard,
|
||||||
master: &CardMaster,
|
_master: &CardMaster,
|
||||||
) -> AppResult<String> {
|
) -> AppResult<String> {
|
||||||
let session = self.session.as_ref()
|
let session = self.session.as_ref()
|
||||||
.ok_or_else(|| AppError::authentication("No atproto session available"))?;
|
.ok_or_else(|| AppError::authentication("No atproto session available"))?;
|
||||||
@ -81,6 +85,7 @@ impl AtprotoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// List card records from user's PDS
|
/// List card records from user's PDS
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn list_card_records(&self, did: &str) -> AppResult<Vec<serde_json::Value>> {
|
pub async fn list_card_records(&self, did: &str) -> AppResult<Vec<serde_json::Value>> {
|
||||||
let session = self.session.as_ref()
|
let session = self.session.as_ref()
|
||||||
.ok_or_else(|| AppError::authentication("No atproto session available"))?;
|
.ok_or_else(|| AppError::authentication("No atproto session available"))?;
|
||||||
@ -119,6 +124,7 @@ impl AtprotoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve PDS endpoint from DID
|
/// Resolve PDS endpoint from DID
|
||||||
|
#[allow(dead_code)]
|
||||||
async fn resolve_pds_from_did(&self, did: &str) -> AppResult<String> {
|
async fn resolve_pds_from_did(&self, did: &str) -> AppResult<String> {
|
||||||
// This is a simplified resolution
|
// This is a simplified resolution
|
||||||
// In a real implementation, you would:
|
// In a real implementation, you would:
|
||||||
@ -141,6 +147,7 @@ impl AtprotoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve PLC DID to PDS endpoint
|
/// Resolve PLC DID to PDS endpoint
|
||||||
|
#[allow(dead_code)]
|
||||||
async fn resolve_plc_did(&self, plc_id: &str) -> AppResult<String> {
|
async fn resolve_plc_did(&self, plc_id: &str) -> AppResult<String> {
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
@ -174,6 +181,7 @@ impl AtprotoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Authenticate with atproto and get session
|
/// Authenticate with atproto and get session
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn authenticate(&self, identifier: &str, password: &str) -> AppResult<(String, String)> {
|
pub async fn authenticate(&self, identifier: &str, password: &str) -> AppResult<(String, String)> {
|
||||||
// Try multiple PDS endpoints for authentication
|
// Try multiple PDS endpoints for authentication
|
||||||
let pds_endpoints = [
|
let pds_endpoints = [
|
||||||
@ -193,6 +201,7 @@ impl AtprotoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Try authentication at a specific PDS
|
/// Try authentication at a specific PDS
|
||||||
|
#[allow(dead_code)]
|
||||||
async fn try_authenticate_at_pds(
|
async fn try_authenticate_at_pds(
|
||||||
&self,
|
&self,
|
||||||
pds_url: &str,
|
pds_url: &str,
|
||||||
|
@ -3,13 +3,14 @@ use crate::{
|
|||||||
models::*,
|
models::*,
|
||||||
};
|
};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct CardMasterService {
|
pub struct CardMasterService {
|
||||||
client: Client,
|
client: Client,
|
||||||
master_url: String,
|
master_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
impl CardMasterService {
|
impl CardMasterService {
|
||||||
pub fn new(master_url: String) -> Self {
|
pub fn new(master_url: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -19,6 +20,7 @@ impl CardMasterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch card master data from external source (ai.json)
|
/// Fetch card master data from external source (ai.json)
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn fetch_external_card_data(&self) -> AppResult<Vec<ExternalCard>> {
|
pub async fn fetch_external_card_data(&self) -> AppResult<Vec<ExternalCard>> {
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
@ -44,6 +46,7 @@ impl CardMasterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get fallback card data if external fetch fails
|
/// Get fallback card data if external fetch fails
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_fallback_card_data(&self) -> Vec<ExternalCard> {
|
pub fn get_fallback_card_data(&self) -> Vec<ExternalCard> {
|
||||||
vec![
|
vec![
|
||||||
ExternalCard {
|
ExternalCard {
|
||||||
@ -178,6 +181,7 @@ impl CardMasterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get card master data, trying external source first then fallback
|
/// Get card master data, trying external source first then fallback
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_card_master_data(&self) -> Vec<ExternalCard> {
|
pub async fn get_card_master_data(&self) -> Vec<ExternalCard> {
|
||||||
match self.fetch_external_card_data().await {
|
match self.fetch_external_card_data().await {
|
||||||
Ok(cards) => {
|
Ok(cards) => {
|
||||||
@ -192,6 +196,7 @@ impl CardMasterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert external card data to database format
|
/// Convert external card data to database format
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn external_to_card_master(external: &ExternalCard) -> CardMaster {
|
pub fn external_to_card_master(external: &ExternalCard) -> CardMaster {
|
||||||
let description = if let Some(lang) = &external.lang {
|
let description = if let Some(lang) = &external.lang {
|
||||||
if let Some(ja) = &lang.ja {
|
if let Some(ja) = &lang.ja {
|
||||||
|
@ -3,12 +3,9 @@ use crate::{
|
|||||||
database::{Database, DatabaseTransaction},
|
database::{Database, DatabaseTransaction},
|
||||||
error::{AppError, AppResult},
|
error::{AppError, AppResult},
|
||||||
models::*,
|
models::*,
|
||||||
query_as, query_one_as, query_optional_as,
|
|
||||||
services::CardMasterService,
|
|
||||||
};
|
};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::collections::HashMap;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct GachaService {
|
pub struct GachaService {
|
||||||
@ -128,7 +125,7 @@ impl GachaService {
|
|||||||
async fn select_card_master(
|
async fn select_card_master(
|
||||||
&self,
|
&self,
|
||||||
tx: &mut DatabaseTransaction,
|
tx: &mut DatabaseTransaction,
|
||||||
rarity: &CardRarity,
|
_rarity: &CardRarity,
|
||||||
_pool_id: Option<i32>,
|
_pool_id: Option<i32>,
|
||||||
) -> AppResult<CardMaster> {
|
) -> AppResult<CardMaster> {
|
||||||
// For now, randomly select from all available cards
|
// For now, randomly select from all available cards
|
||||||
|
@ -3,7 +3,4 @@ pub mod card_master;
|
|||||||
pub mod atproto;
|
pub mod atproto;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
pub use gacha::GachaService;
|
pub use gacha::GachaService;
|
||||||
pub use card_master::CardMasterService;
|
|
||||||
pub use atproto::AtprotoService;
|
|
||||||
pub use user::UserService;
|
|
@ -5,8 +5,10 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct UserService;
|
pub struct UserService;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
impl UserService {
|
impl UserService {
|
||||||
pub async fn get_user_by_did(db: &Database, did: &str) -> AppResult<Option<User>> {
|
pub async fn get_user_by_did(db: &Database, did: &str) -> AppResult<Option<User>> {
|
||||||
match db {
|
match db {
|
||||||
@ -27,6 +29,7 @@ impl UserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn create_user(db: &Database, did: &str, handle: &str) -> AppResult<User> {
|
pub async fn create_user(db: &Database, did: &str, handle: &str) -> AppResult<User> {
|
||||||
let now = Utc::now();
|
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> {
|
pub async fn update_user_handle(db: &Database, did: &str, handle: &str) -> AppResult<User> {
|
||||||
let now = Utc::now();
|
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> {
|
pub async fn get_user_card_count(db: &Database, user_did: &str) -> AppResult<i64> {
|
||||||
match db {
|
match db {
|
||||||
Database::Postgres(pool) => {
|
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> {
|
pub async fn get_user_unique_card_count(db: &Database, user_did: &str) -> AppResult<i64> {
|
||||||
match db {
|
match db {
|
||||||
Database::Postgres(pool) => {
|
Database::Postgres(pool) => {
|
||||||
@ -133,6 +139,7 @@ impl UserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_user_cards_by_rarity(
|
pub async fn get_user_cards_by_rarity(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
user_did: &str,
|
user_did: &str,
|
||||||
|
Reference in New Issue
Block a user