Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
be48508
remove RwLock for SqliteLayer
funnyboy-roks Aug 29, 2025
6cfe515
work on erudite updates
funnyboy-roks Aug 29, 2025
891deb1
better sqlx macros
funnyboy-roks Aug 29, 2025
2eedec4
switch id types to use [u8; 20]
funnyboy-roks Aug 29, 2025
d8011cb
Merge branch 'main' into erudite-changes
funnyboy-roks Aug 29, 2025
c0e2a33
websockets are kind nice now and fix some clippy lints
funnyboy-roks Aug 29, 2025
7967f88
guts are mostly in place
funnyboy-roks Sep 25, 2025
49dfe30
make tests work
funnyboy-roks Sep 25, 2025
02358f0
Merge branch 'main' into erudite-changes
funnyboy-roks Sep 25, 2025
5da1337
fix machete ci after https://github.com/bnjbvr/cargo-machete/pull/188
funnyboy-roks Sep 25, 2025
34eeefc
fix machete ci
funnyboy-roks Sep 25, 2025
c11db28
remove lazy_static
funnyboy-roks Sep 25, 2025
1fb261f
remove msrv check
funnyboy-roks Sep 25, 2025
b8a858a
add abort and build out rest api
funnyboy-roks Sep 25, 2025
af44ea4
fix tests
funnyboy-roks Sep 25, 2025
1c1a46d
I said it wouldn't be forgotten
funnyboy-roks Sep 26, 2025
39bac4a
Merge branch 'main' into erudite-changes
funnyboy-roks Oct 1, 2025
86f699c
remove websocket recieve handling
funnyboy-roks Oct 1, 2025
504ba5c
tfw you forget to save a file
funnyboy-roks Oct 1, 2025
4840b50
only allow submissions/tests if the server is not paused
funnyboy-roks Oct 4, 2025
bbfd524
changes while updating frontend
funnyboy-roks Oct 9, 2025
25fab17
more changes while updating frontend
funnyboy-roks Oct 10, 2025
e5f58e4
emit websocket when tests compiled
funnyboy-roks Oct 10, 2025
2fb48f6
fix tests and clippy
funnyboy-roks Oct 10, 2025
fa1a2e8
itty bitty data race
funnyboy-roks Oct 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 97 additions & 53 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
edition = "2021"
version = "0.1.0"
rust-version = "1.81"
rust-version = "1.87"

[workspace.dependencies]
anyhow = "1.0.95"
Expand All @@ -26,11 +26,8 @@ derive_more = { version = "2.0.1", features = [
"from_str",
] }
directories = "6.0.0"
erudite = { git = "https://github.com/basalt-rs/erudite.git", rev = "7de318e", features = [
"serde",
] }
erudite = { git = "https://github.com/basalt-rs/erudite.git", rev = "f45f587" }
lazy_static = "1.5.0"
leucite = "0.2.0"
rand = "0.8.5"
redact = { version = "0.1.10", features = ["serde"] }
scopeguard = "1.2.0"
Expand All @@ -41,7 +38,7 @@ sqlx = { version = "0.8.3", features = [
"runtime-tokio-native-tls",
"time",
] }
thiserror = "2.0.11"
thiserror = "2.0.16"
time = { version = "0.3.40", features = ["serde"] }
tokio = { version = "1.43.0", features = ["full"] }
tower-http = { version = "0.6.2", features = ["cors", "trace", "fs"] }
Expand Down
2 changes: 1 addition & 1 deletion basalt-server-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ derive_more.workspace = true
directories.workspace = true
erudite.workspace = true
lazy_static.workspace = true
leucite.workspace = true
rand.workspace = true
redact.workspace = true
scopeguard.workspace = true
Expand All @@ -45,6 +44,7 @@ rustyscript = { git = "https://github.com/rscarson/rustyscript.git", branch = "m
"http",
], optional = true }
reqwest = { version = "0.11.0", features = ["json"], optional = true }
futures = "0.3.31"

[dev-dependencies]
async-tempfile = { version = "0.6.0", features = ["uuid"] }
Expand Down
29 changes: 19 additions & 10 deletions basalt-server-lib/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,31 @@ CREATE TABLE IF NOT EXISTS submission_history (
id VARCHAR(32) NOT NULL PRIMARY KEY,
submitter VARCHAR(32) NOT NULL REFERENCES users(id),
time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
compile_fail BOOLEAN NOT NULL,
code TEXT NOT NULL,
question_index INTEGER NOT NULL,
score FLOAT NOT NULL,
success BOOLEAN NOT NULL,
language TEXT NOT NULL
language TEXT NOT NULL,
compile_result INTEGER NOT NULL, -- CompileResultState enum
compile_stdout TEXT NOT NULL,
compile_stderr TEXT NOT NULL,
compile_exit_status INTEGER NOT NULL,
-- The remaining data will be updated after the tests have finished running
state INTEGER NOT NULL DEFAULT 0, -- SubmissionState
score FLOAT NOT NULL DEFAULT 0.0,
success BOOLEAN NOT NULL DEFAULT false,
time_taken INTEGER NOT NULL DEFAULT 0 -- NOTE: This is stored as a `u64` cast as an `i64`. Keep that in mind while doing operations on this data in queries.
);

-- History of tests that have been run on submissions
CREATE TABLE IF NOT EXISTS submission_test_history (
-- Output of each test
CREATE TABLE IF NOT EXISTS test_results (
submission VARCHAR(32) NOT NULL REFERENCES submission_history(id),
test_index INTEGER NOT NULL,
result VARCHAR(32) NOT NULL,
stdout TEXT,
stderr TEXT,
exit_status INTEGER NOT NULL
result INTEGER NOT NULL, -- TestResultState enum
stdout TEXT NOT NULL,
stderr TEXT NOT NULL,
exit_status INTEGER NOT NULL,
time_taken INTEGER NOT NULL, -- NOTE: This is stored as a `u64` cast as an `i64`. Keep that in mind while doing operations on this data in queries.

PRIMARY KEY (submission, test_index)
);

CREATE TABLE IF NOT EXISTS announcements (
Expand Down
3 changes: 1 addition & 2 deletions basalt-server-lib/src/extractors/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ async fn extract(
let session_id = bearer.token();

// confirm user is in db and the session is active
let db = state.db.read().await;
trace!("getting user from session");
let user = repositories::session::get_user_from_session(&db, session_id)
let user = repositories::session::get_user_from_session(&state.db, session_id)
.await
.map_err(|_| {
trace!("token expired");
Expand Down
1 change: 1 addition & 0 deletions basalt-server-lib/src/repositories/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod announcements;
pub mod session;
pub mod submissions;
pub mod users;
pub mod util;
36 changes: 5 additions & 31 deletions basalt-server-lib/src/repositories/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,13 @@ use sqlx::{prelude::FromRow, SqliteExecutor};
use utoipa::ToSchema;

use crate::{
define_id_type,
repositories::users::{Role, UserId},
storage::SqliteLayer,
};

use super::users::User;

#[derive(
Debug,
Clone,
Hash,
Eq,
PartialEq,
Serialize,
Deserialize,
ToSchema,
derive_more::From,
derive_more::Into,
sqlx::Type,
)]
#[sqlx(transparent)]
pub struct SessionId(pub String);

impl SessionId {
fn new() -> Self {
use rand::{distributions::Alphanumeric, Rng};
let id = rand::thread_rng()
.sample_iter(Alphanumeric)
.take(20)
.map(char::from)
.collect::<String>();
Self(id)
}
}
define_id_type!(SessionId);

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct Session {
Expand Down Expand Up @@ -88,7 +62,7 @@ pub enum GetSessionError {
}

pub async fn get_user_from_session(
sql: &SqliteLayer,
sql: impl SqliteExecutor<'_> + Copy, // Copy is implemented for &T
session_id: &str,
) -> Result<User, GetSessionError> {
#[derive(sqlx::FromRow)]
Expand All @@ -102,7 +76,7 @@ pub async fn get_user_from_session(
}

let session = sqlx::query_as!(SessionUser, "SELECT users.*, expires_at FROM users JOIN sessions ON users.id = sessions.user_id WHERE session_id = $1", session_id)
.fetch_optional(&sql.db)
.fetch_optional(sql)
.await
.map_err(|e| GetSessionError::QueryError(e.to_string()))?
.ok_or_else(|| GetSessionError::SessionNotFound {
Expand All @@ -111,7 +85,7 @@ pub async fn get_user_from_session(

if SystemTime::UNIX_EPOCH + Duration::from_secs(session.expires_at as u64) < SystemTime::now() {
sqlx::query!("DELETE FROM sessions WHERE session_id = $1", session_id)
.execute(&sql.db)
.execute(sql)
.await
.map_err(|e| GetSessionError::QueryError(e.to_string()))?;

Expand Down
Loading
Loading