Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
297 changes: 16 additions & 281 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,25 @@ axum = { version = "0.7.9", features = ["json"] }
axum-extra = { version = "0.9.6", features = ["cookie", "typed-header"] }
axum-server = "0.6.0"
base64 = "0.21.7"
bytes = "1.10.1"
chrono = { workspace = true }
clap = { version = "4.5.38", features = ["derive"] }
db = { path = "crates/db" }
dotenv = "0.15.0"
env_logger = "0.10.2"
futures = "0.3.31"
http = "1.3.1"
log = "0.4.27"
model = { path = "crates/model" }
oauth2 = "4.4.2"
rand = "0.9.1"
reqwest = { version = "0.11.27", default-features = false, features = [ "blocking", "json", "rustls-tls"] }
rusoto_core = { version = "0.48.0", default-features = false, features = [ "rustls", ] }
rusoto_s3 = { version = "0.48.0", default-features = false, features = [ "rustls", ] }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = "0.10.9"
tokio = { workspace = true }
tower = { version = "0.4.13", features = ["tracing", "limit", "buffer"] }
tower-http = { version = "0.5.2", features = ["cors", "fs", "trace"] }
tower_governor = "0.2.0"
tracing = "0.1.41"
typeshare = { workspace = true }
url = "2.5.4"
walkdir = "2.5.0"

[dev-dependencies]
hyper = { version = "1.6.0", features = ["server"] }
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ COPY --from=server /usr/src/app/seed seed
COPY --from=server /usr/src/app/.well-known .well-known
COPY --from=server /usr/src/app/target/release/server /usr/local/bin

CMD server --source seed --initialize --latest-courses --skip-reviews --asset-dir assets --db-name mcgill-courses
CMD server --db-name mcgill-courses serve --asset-dir assets
21 changes: 3 additions & 18 deletions crates/db/src/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,11 @@
async fn seed(&self) -> Result {
info!("Seeding the database...");

let mut seeds = self.collect()?;

if self.options.latest_courses {
let courses = seeds
.clone()
.into_iter()
.filter(|seed| matches!(seed, Seed::Courses(_)))
.collect::<Vec<Seed>>();

seeds.retain(|seed| !matches!(seed, Seed::Courses(_)));

if let Some(last) = courses.last() {
seeds.insert(0, last.clone());
}
}
let seeds = self.collect()?;

for seed in seeds {
match seed {
Seed::Courses((path, courses)) if !self.options.skip_courses => {
Seed::Courses((path, courses)) => {
info!("Seeding courses from {}...", path.display());

let runner = |db: Db, item: Course| async move {
Expand All @@ -149,7 +135,7 @@

self.populate(courses, runner).await?;
}
Seed::Reviews((path, reviews)) if !self.options.skip_reviews => {
Seed::Reviews((path, reviews)) => {

Check warning on line 138 in crates/db/src/initializer.rs

View check run for this annotation

Codecov / codecov/patch

crates/db/src/initializer.rs#L138

Added line #L138 was not covered by tests
info!("Seeding reviews from {}...", path.display());

let runner = |db: Db, item: Review| async move {
Expand All @@ -165,7 +151,6 @@
path.display()
);
}
_ => continue,
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ bson = { version = "2.14.0", features = ["chrono-0_4"] }
combine = { path = "../combine" }
derivative = "2.2.0"
serde = { workspace = true }
serde_json = { workspace = true }
typeshare = { workspace = true }
3 changes: 0 additions & 3 deletions crates/model/src/initialize_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use super::*;

#[derive(Debug, Default)]
pub struct InitializeOptions {
pub latest_courses: bool,
pub multithreaded: bool,
pub skip_courses: bool,
pub skip_reviews: bool,
pub source: PathBuf,
}
15 changes: 15 additions & 0 deletions src/arguments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Arguments {
#[clap(flatten)]
options: Options,
#[clap(subcommand)]
subcommand: Subcommand,
}

impl Arguments {
pub(crate) async fn run(self) -> Result {
self.subcommand.run(self.options).await
}

Check warning on line 14 in src/arguments.rs

View check run for this annotation

Codecov / codecov/patch

src/arguments.rs#L12-L14

Added lines #L12 - L14 were not covered by tests
}
119 changes: 0 additions & 119 deletions src/hash.rs

This file was deleted.

23 changes: 9 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use {
crate::{
arguments::Arguments,
assets::Assets,
auth::{AuthRedirect, COOKIE_NAME},
error::Error,
hash::Hash,
object::Object,
options::Options,
seeder::Seeder,
server::Server,
state::State,
subcommand::Subcommand,
user::User,
},
anyhow::anyhow,
Expand All @@ -29,7 +31,6 @@
db::Db,
dotenv::dotenv,
env_logger::Env,
futures::TryStreamExt,
http::{
header, header::SET_COOKIE, request::Parts, HeaderMap, Request, StatusCode,
},
Expand All @@ -42,19 +43,13 @@
basic::BasicClient, AuthType, AuthUrl, ClientId, ClientSecret, CsrfToken,
RedirectUrl, Scope, TokenUrl,
},
rusoto_core::Region,
rusoto_s3::S3Client,
rusoto_s3::{GetObjectRequest, PutObjectOutput, PutObjectRequest, S3},
serde::{Deserialize, Serialize},
serde_json::json,
sha2::{Digest, Sha256},
std::{
backtrace::BacktraceStatus,
env,
fmt::{self, Display, Formatter},
fs,
fs::File,
io::Read,
net::SocketAddr,
path::PathBuf,
process,
Expand All @@ -73,27 +68,27 @@
tracing::Span,
typeshare::typeshare,
url::Url,
walkdir::WalkDir,
};

mod arguments;
mod assets;
mod auth;
mod courses;
mod error;
mod hash;
mod instructors;
mod interactions;
mod notifications;
mod object;
mod options;
mod reviews;
mod search;
mod seeder;
mod server;
mod state;
mod subcommand;
mod subscriptions;
mod user;

type Result<T = (), E = error::Error> = std::result::Result<T, E>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

#[tokio::main]
async fn main() {
Expand All @@ -102,7 +97,7 @@

dotenv().ok();

if let Err(error) = Server::parse().run().await {
if let Err(error) = Arguments::parse().run().await {

Check warning on line 100 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L100

Added line #L100 was not covered by tests
eprintln!("error: {error}");

for (i, error) in error.0.chain().skip(1).enumerate() {
Expand Down
51 changes: 0 additions & 51 deletions src/object.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

#[derive(Parser)]
#[derive(Debug, Parser)]
pub(crate) struct Options {
#[clap(long, default_value = "courses.json")]
pub(crate) source: PathBuf,
#[clap(long, default_value = "admin", help = "Database name")]
pub(crate) db_name: String,

Check warning on line 6 in src/options.rs

View check run for this annotation

Codecov / codecov/patch

src/options.rs#L6

Added line #L6 was not covered by tests
}
Loading