chore: update actix-* deps

This commit is contained in:
realaravinth
2022-05-07 16:10:14 +05:30
parent 6d6b494c6f
commit 91c6f77cab
16 changed files with 1101 additions and 1006 deletions

View File

@@ -230,16 +230,17 @@ async fn register(
async fn login(
id: Identity,
payload: web::Json<runners::Login>,
path: web::Path<super::RedirectQuery>,
query: web::Query<super::RedirectQuery>,
data: AppData,
) -> ServiceResult<impl Responder> {
let username = runners::login_runner(payload.into_inner(), &data).await?;
id.remember(username);
// Ok(HttpResponse::Ok())
if let Some(redirect_to) = &path.redirect_to {
let query = query.into_inner();
if let Some(redirect_to) = query.redirect_to {
Ok(HttpResponse::Found()
.insert_header((header::LOCATION, redirect_to))
.append_header((header::LOCATION, redirect_to))
.finish())
} else {
Ok(HttpResponse::Ok().finish())

View File

@@ -16,7 +16,7 @@
*/
use std::borrow::Cow;
use actix_web::body::AnyBody;
use actix_web::body::BoxBody;
use actix_web::{http::header, web, HttpResponse, Responder};
use mime_guess::from_path;
use rust_embed::RustEmbed;
@@ -54,12 +54,15 @@ struct Asset;
pub fn handle_embedded_file(path: &str) -> HttpResponse {
match Asset::get(path) {
Some(content) => {
let body: AnyBody = match content.data {
Cow::Borrowed(bytes) => bytes.into(),
Cow::Owned(bytes) => bytes.into(),
let body: BoxBody = match content.data {
Cow::Borrowed(bytes) => BoxBody::new(bytes),
Cow::Owned(bytes) => BoxBody::new(bytes),
};
HttpResponse::Ok()
.insert_header(header::CacheControl(vec![
header::CacheDirective::Public,
header::CacheDirective::Extension("immutable".into(), None),
header::CacheDirective::MaxAge(CACHE_AGE),
]))
.content_type(from_path(path).first_or_octet_stream().as_ref())
@@ -69,6 +72,7 @@ pub fn handle_embedded_file(path: &str) -> HttpResponse {
}
}
#[my_codegen::get(path = "DOCS.assets")]
async fn dist(path: web::Path<String>) -> impl Responder {
handle_embedded_file(&path)

View File

@@ -42,5 +42,5 @@ lazy_static! {
pub async fn login() -> impl Responder {
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&*INDEX)
.body(&**INDEX)
}

View File

@@ -39,5 +39,5 @@ lazy_static! {
pub async fn join() -> impl Responder {
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&*INDEX)
.body(&**INDEX)
}

View File

@@ -56,11 +56,11 @@ async fn error(path: web::Path<usize>) -> impl Responder {
let resp = match path.into_inner() {
500 => HttpResponse::InternalServerError()
.content_type("text/html; charset=utf-8")
.body(&*INTERNAL_SERVER_ERROR_BODY),
.body(&**INTERNAL_SERVER_ERROR_BODY),
_ => HttpResponse::InternalServerError()
.content_type("text/html; charset=utf-8")
.body(&*UNKNOWN_ERROR_BODY),
.body(&**UNKNOWN_ERROR_BODY),
};
resp

View File

@@ -104,7 +104,7 @@ async fn delete_account() -> impl Responder {
.unwrap();
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&page)
.body(page)
}
#[my_codegen::get(
@@ -117,5 +117,5 @@ async fn update_secret() -> impl Responder {
.unwrap();
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&page)
.body(page)
}

View File

@@ -54,7 +54,7 @@ impl<'a> Default for AdvanceIndexPage<'a> {
pub async fn advance() -> impl Responder {
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&*ADVANCE_INDEX)
.body(&**ADVANCE_INDEX)
}
#[derive(TemplateOnce, Clone)]
@@ -86,5 +86,5 @@ impl<'a> Default for EasyIndexPage<'a> {
pub async fn easy() -> impl Responder {
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&*EASY_INDEX)
.body(&**EASY_INDEX)
}

View File

@@ -34,5 +34,5 @@ pub async fn delete_sitekey(path: web::Path<String>) -> impl Responder {
.unwrap();
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&page)
.body(page)
}

View File

@@ -50,5 +50,5 @@ lazy_static! {
pub async fn sitemap() -> impl Responder {
HttpResponse::Ok()
.content_type("application/xml; charset=utf-8")
.body(&*INDEX)
.body(&**INDEX)
}

View File

@@ -121,10 +121,6 @@ impl Settings {
pub fn new() -> Result<Self, ConfigError> {
let mut s = Config::new();
// setting default values
#[cfg(test)]
s.set_default("database.pool", 2.to_string())
.expect("Couldn't get the number of CPUs");
const CURRENT_DIR: &str = "./config/default.toml";
const ETC: &str = "/etc/mcaptcha/config.toml";
@@ -162,6 +158,13 @@ impl Settings {
set_database_url(&mut s);
// setting default values
#[cfg(test)]
s.set("database.pool", 2.to_string())
.expect("Couldn't set database pool count");
match s.try_into() {
Ok(val) => Ok(val),
Err(e) => Err(ConfigError::Message(format!("\n\nError: {}. If it says missing fields, then please refer to https://github.com/mCaptcha/mcaptcha#configuration to learn more about how mcaptcha reads configuration\n\n", e))),

View File

@@ -16,7 +16,7 @@
*/
use std::borrow::Cow;
use actix_web::body::AnyBody;
use actix_web::body::BoxBody;
use actix_web::{get, http::header, web, HttpResponse, Responder};
use log::debug;
use mime_guess::from_path;
@@ -82,9 +82,9 @@ struct Asset;
fn handle_assets(path: &str) -> HttpResponse {
match Asset::get(path) {
Some(content) => {
let body: AnyBody = match content.data {
Cow::Borrowed(bytes) => bytes.into(),
Cow::Owned(bytes) => bytes.into(),
let body: BoxBody = match content.data {
Cow::Borrowed(bytes) => BoxBody::new(bytes),
Cow::Owned(bytes) => BoxBody::new(bytes),
};
HttpResponse::Ok()
@@ -100,6 +100,7 @@ fn handle_assets(path: &str) -> HttpResponse {
}
}
#[get("/assets/{_:.*}")]
pub async fn static_files(path: web::Path<String>) -> impl Responder {
handle_assets(&path)
@@ -112,9 +113,9 @@ struct Favicons;
fn handle_favicons(path: &str) -> HttpResponse {
match Favicons::get(path) {
Some(content) => {
let body: AnyBody = match content.data {
Cow::Borrowed(bytes) => bytes.into(),
Cow::Owned(bytes) => bytes.into(),
let body: BoxBody = match content.data {
Cow::Borrowed(bytes) => BoxBody::new(bytes),
Cow::Owned(bytes) => BoxBody::new(bytes),
};
HttpResponse::Ok()
@@ -130,6 +131,7 @@ fn handle_favicons(path: &str) -> HttpResponse {
}
}
#[get("/{file}")]
pub async fn favicons(path: web::Path<String>) -> impl Responder {
debug!("searching favicons");

View File

@@ -3,6 +3,7 @@ use std::sync::Arc;
use actix_web::test;
use actix_web::{
dev::ServiceResponse, error::ResponseError, http::StatusCode,
body::{EitherBody, BoxBody},
middleware as actix_middleware,
};
use libmcaptcha::defense::Level;
@@ -85,7 +86,7 @@ pub async fn register_and_signin(
name: &str,
email: &str,
password: &str,
) -> (Arc<data::Data>, Login, ServiceResponse) {
) -> (Arc<data::Data>, Login, ServiceResponse<EitherBody<BoxBody>>) {
register(name, email, password).await;
signin(name, password).await
}
@@ -109,7 +110,7 @@ pub async fn register(name: &str, email: &str, password: &str) {
}
/// signin util
pub async fn signin(name: &str, password: &str) -> (Arc<Data>, Login, ServiceResponse) {
pub async fn signin(name: &str, password: &str) -> (Arc<Data>, Login, ServiceResponse<EitherBody<BoxBody>>) {
let data = Data::new().await;
let app = get_app!(data.clone()).await;
@@ -172,7 +173,7 @@ pub fn get_level_data() -> CreateCaptcha {
pub async fn add_levels_util(
name: &str,
password: &str,
) -> (Arc<data::Data>, Login, ServiceResponse, MCaptchaDetails) {
) -> (Arc<data::Data>, Login, ServiceResponse<EitherBody<BoxBody>>, MCaptchaDetails) {
let (data, creds, signin_resp) = signin(name, password).await;
let cookies = get_cookie!(signin_resp);
let app = get_app!(data).await;

View File

@@ -58,7 +58,7 @@ lazy_static! {
async fn show_widget() -> PageResult<impl Responder> {
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(&*INDEX_PAGE))
.body(&**INDEX_PAGE))
}
/// widget services