Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mdcpp/mdoj
Browse files Browse the repository at this point in the history
  • Loading branch information
KAIYOHUGO committed Jul 16, 2024
2 parents 9b35227 + 8f68bc6 commit 468686d
Show file tree
Hide file tree
Showing 50 changed files with 1,555 additions and 447 deletions.
258 changes: 258 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ features = [
"judger",
"transport",
"serde",
"extra_trait",
"extra_trait"
]

[dependencies.postcard]
Expand Down
27 changes: 16 additions & 11 deletions backend/migration/src/m20231207_000001_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ enum Submit {
Score,
}
#[derive(Iden)]
enum Test {
enum Testcase {
Table,
Id,
UserId,
Expand Down Expand Up @@ -457,32 +457,37 @@ impl MigrationTrait for Migration {
manager
.create_table(
Table::create()
.table(Test::Table)
.table(Testcase::Table)
.if_not_exists()
.col(
ColumnDef::new(Test::Id)
ColumnDef::new(Testcase::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Test::UserId).integer().not_null())
.col(ColumnDef::new(Testcase::UserId).integer().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-test-user")
.from(Test::Table, Test::UserId)
.from(Testcase::Table, Testcase::UserId)
.to(User::Table, User::Id),
)
.col(ColumnDef::new(Test::ProblemId).integer().null())
.col(ColumnDef::new(Testcase::ProblemId).integer().null())
.foreign_key(
ForeignKey::create()
.name("fk-test-user")
.from(Test::Table, Test::ProblemId)
.from(Testcase::Table, Testcase::ProblemId)
.to(Problem::Table, Problem::Id),
)
.col(ColumnDef::new(Test::Input).binary().not_null())
.col(ColumnDef::new(Test::Output).binary().not_null())
.col(ColumnDef::new(Test::Score).unsigned().not_null().default(0))
.col(ColumnDef::new(Testcase::Input).binary().not_null())
.col(ColumnDef::new(Testcase::Output).binary().not_null())
.col(
ColumnDef::new(Testcase::Score)
.unsigned()
.not_null()
.default(0),
)
.to_owned(),
)
.await?;
Expand Down Expand Up @@ -703,7 +708,7 @@ impl MigrationTrait for Migration {
.drop_table(Table::drop().table(Submit::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Test::Table).to_owned())
.drop_table(Table::drop().table(Testcase::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Token::Table).to_owned())
Expand Down
13 changes: 8 additions & 5 deletions backend/src/init/config.rs → backend/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::{path::PathBuf, str::FromStr};

use super::Error;
use crate::server;
use crate::server::InitError;
use ip_network::IpNetwork;
use serde::{Deserialize, Serialize};
use tokio::{fs, io::AsyncReadExt};

pub use crate::server::PACKAGE_NAME;

lazy_static::lazy_static! {
pub static ref CONFIG_PATH: PathBuf=PathBuf::from_str(
&std::env::var("CONFIG_PATH").unwrap_or("config.toml".to_string()))
Expand Down Expand Up @@ -130,7 +133,7 @@ impl Default for Imgur {
}
}

pub async fn init() -> super::Result<GlobalConfig> {
pub async fn init() -> server::Result<GlobalConfig> {
let config_path = CONFIG_PATH.as_path();
if fs::metadata(config_path).await.is_ok() {
let mut buf = Vec::new();
Expand All @@ -140,10 +143,10 @@ pub async fn init() -> super::Result<GlobalConfig> {
config
.read_to_end(&mut buf)
.await
.map_err(Error::ConfigRead)?;
.map_err(InitError::ConfigRead)?;
let config =
std::str::from_utf8(&buf).expect("Config file may container non-utf8 character");
let config: GlobalConfig = toml::from_str(config).map_err(Error::ConfigParse)?;
let config: GlobalConfig = toml::from_str(config).map_err(InitError::ConfigParse)?;
Ok(config)
} else {
println!(
Expand All @@ -155,7 +158,7 @@ pub async fn init() -> super::Result<GlobalConfig> {
let config_txt = toml::to_string(&config).unwrap();
fs::write(config_path, config_txt)
.await
.map_err(Error::ConfigWrite)?;
.map_err(InitError::ConfigWrite)?;

println!(
"Config generated, please edit {:?} before restart",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controller/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rand::{rngs::OsRng, Rng};
use serde::{de::DeserializeOwned, Serialize};
use tracing::Span;

use crate::init::config::GlobalConfig;
use crate::config::GlobalConfig;
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use blake2::{Blake2b512, Digest};

Expand Down
Loading

0 comments on commit 468686d

Please sign in to comment.