Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Oct 24, 2024
1 parent fd3f371 commit 2412369
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 22 deletions.
10 changes: 10 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
unstable_features = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
brace_style = "PreferSameLine"
wrap_comments = true
condense_wildcard_suffixes = true
fn_params_layout = "Compressed"
hex_literal_case = "Upper"
enum_discrim_align_threshold = 20
tab_spaces = 4
3 changes: 2 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ pub mod ctfshow;
pub mod db;
pub mod selenium;

use serde::{Deserialize, Serialize};
use std::{path::Path, process, sync::OnceLock};

use serde::{Deserialize, Serialize};
use tokio::fs::{self};
use tracing::error;

Expand Down
3 changes: 1 addition & 2 deletions src/database/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ macro_rules! create_tables {

async fn create_table<E>(db: &DbConn, entity: E)
where
E: EntityTrait,
{
E: EntityTrait, {
let builder = db.get_database_backend();
let schema = Schema::new(builder);
let stmt = builder.build(schema.create_table_from_entity(entity).if_not_exists());
Expand Down
3 changes: 2 additions & 1 deletion src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
mod migration;

use std::time::Duration;

use once_cell::sync::OnceCell;
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
use std::time::Duration;
use tracing::info;

static DB: OnceCell<DatabaseConnection> = OnceCell::new();
Expand Down
4 changes: 1 addition & 3 deletions src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use once_cell::sync::OnceCell;
use tracing::{info, Level};
use tracing_appender::{non_blocking, non_blocking::WorkerGuard};
use tracing_error::ErrorLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

static FILE_GUARD: OnceCell<WorkerGuard> = OnceCell::new();
static CONSOLE_GUARD: OnceCell<WorkerGuard> = OnceCell::new();
Expand Down
3 changes: 1 addition & 2 deletions src/model/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ impl ActiveModelBehavior for ActiveModel {

async fn before_save<C>(mut self, _db: &C, _insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
C: ConnectionTrait, {
Ok(self)
}
}
6 changes: 2 additions & 4 deletions src/model/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use axum::async_trait;
use sea_orm::{entity::prelude::*, Set};
use serde::{Deserialize, Serialize};

use crate::database::get_db;

use super::record;
use crate::database::get_db;

#[derive(Debug, Clone, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "users")]
Expand Down Expand Up @@ -41,8 +40,7 @@ impl ActiveModelBehavior for ActiveModel {

async fn before_save<C>(mut self, _db: &C, _insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
C: ConnectionTrait, {
Ok(self)
}
}
3 changes: 2 additions & 1 deletion src/util/jwt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::config;
use jsonwebtoken::{encode, EncodingKey, Header};
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};

use crate::config;

static SECRET: Lazy<String> = Lazy::new(|| {
let mut secret_key = config::get_config().auth.jwt.secret_key.clone();
let re = Regex::new(r"\[([Uu][Uu][Ii][Dd])\]").unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/web/api/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::{database::get_db, util::jwt, web::traits::WebError};
use axum::{extract::Query, response::IntoResponse, routing::get, Json, Router};
use reqwest::StatusCode;
use sea_orm::{ActiveModelTrait, EntityTrait, Set};
Expand All @@ -7,6 +6,8 @@ use serde_json::json;
use tracing::info;
use utoipa::OpenApi;

use crate::{database::get_db, util::jwt, web::traits::WebError};

#[derive(OpenApi)]
#[openapi(paths(callback))]
pub struct Doc;
Expand Down
7 changes: 5 additions & 2 deletions src/web/middleware/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::{database::get_db, web::traits::WebError};
use axum::{
body::Body,
extract::Request,
Expand All @@ -11,7 +10,11 @@ use jsonwebtoken::{decode, DecodingKey, Validation};
use sea_orm::EntityTrait;
use serde_json::json;

use crate::{util, web::traits::Ext};
use crate::{
database::get_db,
util,
web::traits::{Ext, WebError},
};

pub async fn jwt(mut req: Request<Body>, next: Next) -> Result<Response, WebError> {
let token = req
Expand Down
13 changes: 8 additions & 5 deletions src/web/traits.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::model::user;
use axum::body::Body;
use axum::http::{Response, StatusCode};
use axum::response::IntoResponse;
use axum::Json;
use axum::{
body::Body,
http::{Response, StatusCode},
response::IntoResponse,
Json,
};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tracing::error;

use crate::model::user;

#[derive(Clone, Debug)]
pub struct Ext {
pub operator: Option<user::Model>,
Expand Down

0 comments on commit 2412369

Please sign in to comment.