diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | README.md | 42 | ||||
-rw-r--r-- | scripts/populate.sh | 21 | ||||
-rw-r--r-- | src/api/mod.rs | 1 | ||||
-rw-r--r-- | src/auth.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 13 |
6 files changed, 39 insertions, 42 deletions
@@ -19,7 +19,7 @@ utoipa-swagger-ui = { version = "9.0.0", features = ["actix-web"] } [package.metadata.scripts] db_create = "bash ./scripts/create_db.sh" -db_populate = "bash ./scripts/populate.sh" +# db_populate = "bash ./scripts/populate.sh" db_fast_populate = "bash ./scripts/fast_populate.sh" db_start = "sudo systemctl start mariadb" db_stop = "sudo systemctl stop mariadb" @@ -1,20 +1,21 @@ # Balalaika -School project of a lyrics game site. +Lyrics api written in rust (school project). -## Set up env -Create a .env file and fill using env_example as a guide. +## Setup +### Dependencies +This project requires mariadb and cargo. -## Set up database +### Set up env +Create a .env file and fill it using the env_example as a guide. + +### Set up database To manage the database through the program's scripts use `cargo run-script` - -You can install the app with -`cargo install cargo-run-script` +(installable through cargo with `cargo install cargo-run-script`). Available scripts: ``` db_create -db_populate db_fast_populate db_start db_stop @@ -23,15 +24,32 @@ db_stop The start/stop scripts assume that you're using systemd. If not, just start/stop the mariadb service manually. -db_fast_populate is a non-tested experimental alternative that -attempts to use a backup sql file to create the database. +db_fast_populate is an alternative to populate the database +without having to interact with Genius' api. +You can still use the original method by executing +./scripts/populate.main.py with a python interpreter. ## Changes -### Single parameters ONLY +### Single parameters only You can only search a parameter at a time. This is because Rust needs to process the sql queries ahead of time in order to make them safe to injection attacks. +### No music genres +Skipped for the sake of simplicity + +### Song titles renamed to "names" +For the sake of making it easier to understand. + +### API requests moved into a new scope +To keep things organised, +the main API requests have been moved to the /api scope. +Routes such as /song are now /api/song. + +### Authentication routes have been added +In order to create/remove users and retrieve the tokens, +a new scope has been created (/auth). + ## TODO -[ ] - User / Password system, use user id to generate tokens +[X] - User / Password system, use user id to generate tokens [ ] - Add documentation (Utoipa) diff --git a/scripts/populate.sh b/scripts/populate.sh deleted file mode 100644 index 0f1ac0c..0000000 --- a/scripts/populate.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -echo activate virtual environment? \(source ~/.venv/bin/activate\) [y/n] -read answer - -if [[ $answer == 'y' ]] then - source ~/.config/venv/bin/activate -fi - -mkdir -p lyrics_cache -cd lyrics_cache - -python3 ../scripts/populate/main.py - -cd .. -mv lyrics_cache/covers ./ -rm -rf lyrics_cache - -if [[ $answer == 'y' ]] then - deactivate -fi - diff --git a/src/api/mod.rs b/src/api/mod.rs index d07079a..2a7c3a8 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -6,6 +6,7 @@ pub mod artist; pub mod search_results; pub mod song; +/* Set up scope */ pub fn api_scope() -> Scope { web::scope("/api") .service(song::get_song) diff --git a/src/auth.rs b/src/auth.rs index 5fdf079..9c6f978 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -5,6 +5,7 @@ use chrono::{Duration, Utc}; use jsonwebtoken::{encode, EncodingKey, Header}; use serde::{Deserialize, Serialize}; +/* Set up scope */ pub fn auth_scope() -> Scope { web::scope("/auth") .service(register) @@ -112,7 +113,6 @@ async fn encode_token(id: usize, secret: &String) -> Result<String, HttpResponse }; } -// todo! tell if the user has been deleted or not #[delete("/user")] pub async fn delete_user( app_state: web::Data<AppState>, diff --git a/src/main.rs b/src/main.rs index 941df3a..69eed5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,25 +24,24 @@ struct AppState { #[actix_web::main] async fn main() -> std::io::Result<()> { - // Errors can get very tough, - // the rust log saved my ass + /* Enable the log */ std::env::set_var("RUST_LOG", "debug"); env_logger::init(); dotenv().ok(); - /* create database wrapper (reference: acsim) */ + /* Create database wrapper (reference: acsim) */ let db_raw = match database::DatabaseWrapper::new().await { Ok(res) => res, Err(_) => panic!("Error creating database wrapper"), }; let db = Arc::new(db_raw); - /* get jwt secret from env */ + /* Get jwt secret from env */ let jwt_secret = env::var("SECRET") .expect("environment variable SECRET is *probably not setted up!!") .to_string(); - /* application data struct */ + /* Application data struct */ let app_state = AppState { database: db, secret: jwt_secret, @@ -80,7 +79,7 @@ async fn main() -> std::io::Result<()> { // let openapi = ApiDoc::openapi(); - /* main server setup */ + /* Server setup */ HttpServer::new(move || { App::new() .app_data(web::Data::new(app_state.clone())) @@ -97,7 +96,7 @@ async fn main() -> std::io::Result<()> { .await } -/* main page*/ +/* Main page*/ async fn root() -> String { String::from("Server is up and running") } |