From 7d03f8836de8f4dddb41ce1bf01f23bb683e3904 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 19 Mar 2021 15:47:59 +0100 Subject: chore: upgrade actix_web to version 3 --- src/commit/routes.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/commit') diff --git a/src/commit/routes.rs b/src/commit/routes.rs index e49f698..95c0faa 100644 --- a/src/commit/routes.rs +++ b/src/commit/routes.rs @@ -23,11 +23,11 @@ async fn index(state: web::Data) -> impl Responder { // Endpoint used for getting one commit async fn get_commit( state: web::Data, - hash: web::Path<(String,)>, + hash: web::Path, ) -> impl Responder { - info!(state.log, "GET /commit/{}/", &hash.0); + info!(state.log, "GET /commit/{}/", &hash); - let result = Commit::find(state.pool.clone(), hash.0.clone()).await; + let result = Commit::find(state.pool.clone(), hash.clone()).await; result .map(|commit| HttpResponse::Ok().json(commit)) @@ -39,14 +39,14 @@ async fn get_commit( async fn delete_commit( req: HttpRequest, state: web::Data, - hash: web::Path<(String,)>, + hash: web::Path, ) -> impl Responder { match req.headers().get(header::AUTHORIZATION) { Some(x) if x.to_str().unwrap() != env::var("SECRET_KEY").unwrap_or("".to_string()) => { - info!(state.log, "DELETE /commit/{}/ 401", &hash.0); + info!(state.log, "DELETE /commit/{}/ 401", &hash); return Err(AppError { error_type: AppErrorType::AuthorizationError, message: Some( @@ -57,13 +57,13 @@ async fn delete_commit( } Some(_) => {} None => { - info!(state.log, "DELETE /commit/{}/ 400", &hash.0); + info!(state.log, "DELETE /commit/{}/ 400", &hash); return Ok(HttpResponse::BadRequest().body("")); } }; - let result = Commit::delete(state.pool.clone(), &hash.0).await; - info!(state.log, "DELETE /commit/{}/", &hash.0); + let result = Commit::delete(state.pool.clone(), &hash).await; + info!(state.log, "DELETE /commit/{}/", &hash); result .map(|_| HttpResponse::NoContent().body("")) @@ -74,9 +74,9 @@ async fn delete_commit( pub fn config(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("/commit") - .service(web::resource("{_:/?}").route(web::get().to(index))) + .service(web::resource("/").route(web::get().to(index))) .service( - web::resource("/{hash}{_:/?}") + web::resource("/{hash}/") .route(web::get().to(get_commit)) .route(web::delete().to(delete_commit)), ), -- cgit v1.2.3-18-g5258 From 0fd8cc67f280143e815f1e2e449afa1f17c52a3b Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 19 Mar 2021 17:11:21 +0100 Subject: chore: select commit limited to 300 --- src/commit/models.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/commit') diff --git a/src/commit/models.rs b/src/commit/models.rs index b2aa2d2..deb2030 100644 --- a/src/commit/models.rs +++ b/src/commit/models.rs @@ -27,7 +27,7 @@ impl Commit { pub async fn find_all(pool: Pool) -> Result, AppError> { let client = get_client(pool.clone()).await.unwrap(); let statement = client - .prepare("SELECT * FROM commit ORDER BY date DESC") + .prepare("SELECT * FROM commit ORDER BY date DESC LIMIT 300") .await?; let commits = client -- cgit v1.2.3-18-g5258 From b9f8d1fc5183e942b28a55709bfcd1b22d691e79 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 19 Mar 2021 17:11:41 +0100 Subject: fix: error on escape quote text --- src/commit/models.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/commit') diff --git a/src/commit/models.rs b/src/commit/models.rs index deb2030..987bcd2 100644 --- a/src/commit/models.rs +++ b/src/commit/models.rs @@ -111,12 +111,12 @@ impl Commit { "('{}', {}, E'{}', '{}', '{}', E'{}', '{}', E'{}', '{}'),", commit.hash, tree, - commit.text.replace("'", "\\'"), + commit.text.replace("\\'", "'").replace("'", "\\'"), commit.date, commit.author_email, - commit.author_name.replace("'", "\\'"), + commit.author_name.replace("\\'", "'").replace("'", "\\'"), commit.committer_email, - commit.committer_name.replace("'", "\\'"), + commit.committer_name.replace("\\'", "'").replace("'", "\\'"), commit.repository_url )[..] } -- cgit v1.2.3-18-g5258