chore: update actix-* deps

This commit is contained in:
realaravinth 2022-05-07 16:10:14 +05:30
parent 6d6b494c6f
commit 91c6f77cab
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88
16 changed files with 1101 additions and 1006 deletions

1386
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -22,35 +22,35 @@ name = "tests-migrate"
path = "./src/tests-migrate.rs" path = "./src/tests-migrate.rs"
[dependencies] [dependencies]
actix-web = "4.0.0-beta.12" actix-web = "4.0.1"
actix = "0.12" actix = "0.13"
actix-identity = "0.4.0-beta.4" actix-identity = "0.4.0"
actix-http = "3.0.0-beta.13" actix-http = "3.0.4"
actix-rt = "2" actix-rt = "2"
actix-cors = "0.6.0-beta.4" actix-cors = "0.6.1"
actix-service = "2.0.0" actix-service = "2.0.0"
my-codegen = {version="0.5.0-beta.5", package = "actix-web-codegen", git ="https://github.com/realaravinth/actix-web"} #my-codegen = {version="0.5.0-beta.5", package = "actix-web-codegen", git ="https://github.com/realaravinth/actix-web"}
mime_guess = "2.0.3" mime_guess = "2.0.3"
rust-embed = "6.0.0" rust-embed = "6.4.0"
cache-buster = { git = "https://github.com/realaravinth/cache-buster" } cache-buster = { git = "https://github.com/realaravinth/cache-buster" }
futures = "0.3.15" futures = "0.3.15"
tokio = { version = "1.14", features = ["sync"]} tokio = { version = "1.14", features = ["sync"]}
sqlx = { version = "0.5.5", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] } sqlx = { version = "0.5.13", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] }
argon2-creds = { branch = "master", git = "https://github.com/realaravinth/argon2-creds"} argon2-creds = { branch = "master", git = "https://github.com/realaravinth/argon2-creds"}
#argon2-creds = { version="*", path = "../../argon2-creds/" } #argon2-creds = { version="*", path = "../../argon2-creds/" }
config = "0.11" config = "0.11"
validator = { version = "0.14", features = ["derive"]} validator = { version = "0.15", features = ["derive"]}
derive_builder = "0.10" derive_builder = "0.11"
derive_more = "0.99" derive_more = "0.99"
serde = "1" serde = "1"
serde_json = "1" serde_json = "1"
url = "2.2" url = "2.2"
urlencoding = "2.1.0"
pretty_env_logger = "0.4" pretty_env_logger = "0.4"
log = "0.4" log = "0.4"
@ -63,7 +63,7 @@ libmcaptcha = { branch = "master", git = "https://github.com/mCaptcha/libmcaptch
rand = "0.8" rand = "0.8"
sailfish = "0.3.2" sailfish = "0.4.0"
mime = "0.3.16" mime = "0.3.16"
@ -76,16 +76,24 @@ lettre = { version = "0.10.0-rc.3", features = [
openssl = { version = "0.10.29", features = ["vendored"] } openssl = { version = "0.10.29", features = ["vendored"] }
[dependencies.my-codegen]
git = "https://github.com/realaravinth/actix-web"
package = "actix-web-codegen"
[dependencies.actix-auth-middleware]
version = "0.2.0"
git = "https://github.com/realaravinth/actix-auth-middleware"
features = ["actix_identity_backend"]
[build-dependencies] [build-dependencies]
serde_json = "1" serde_json = "1"
cache-buster = { version = "0.2.0", git = "https://github.com/realaravinth/cache-buster" } cache-buster = { version = "0.2.0", git = "https://github.com/realaravinth/cache-buster" }
mime = "0.3.16" mime = "0.3.16"
sqlx = { version = "0.5.5", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] } sqlx = { version = "0.5.13", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] }
[dev-dependencies] [dev-dependencies]
pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" } pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" }
awc = "3.0.0-beta.11" awc = "3.0.0"
[target.x86_64-unknown-linux-musl] [target.x86_64-unknown-linux-musl]

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -42,5 +42,5 @@ lazy_static! {
pub async fn login() -> impl Responder { pub async fn login() -> impl Responder {
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .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 { pub async fn join() -> impl Responder {
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .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() { let resp = match path.into_inner() {
500 => HttpResponse::InternalServerError() 500 => HttpResponse::InternalServerError()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(&*INTERNAL_SERVER_ERROR_BODY), .body(&**INTERNAL_SERVER_ERROR_BODY),
_ => HttpResponse::InternalServerError() _ => HttpResponse::InternalServerError()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(&*UNKNOWN_ERROR_BODY), .body(&**UNKNOWN_ERROR_BODY),
}; };
resp resp

View File

@ -104,7 +104,7 @@ async fn delete_account() -> impl Responder {
.unwrap(); .unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(&page) .body(page)
} }
#[my_codegen::get( #[my_codegen::get(
@ -117,5 +117,5 @@ async fn update_secret() -> impl Responder {
.unwrap(); .unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .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 { pub async fn advance() -> impl Responder {
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(&*ADVANCE_INDEX) .body(&**ADVANCE_INDEX)
} }
#[derive(TemplateOnce, Clone)] #[derive(TemplateOnce, Clone)]
@ -86,5 +86,5 @@ impl<'a> Default for EasyIndexPage<'a> {
pub async fn easy() -> impl Responder { pub async fn easy() -> impl Responder {
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .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(); .unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .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 { pub async fn sitemap() -> impl Responder {
HttpResponse::Ok() HttpResponse::Ok()
.content_type("application/xml; charset=utf-8") .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> { pub fn new() -> Result<Self, ConfigError> {
let mut s = Config::new(); 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 CURRENT_DIR: &str = "./config/default.toml";
const ETC: &str = "/etc/mcaptcha/config.toml"; const ETC: &str = "/etc/mcaptcha/config.toml";
@ -162,6 +158,13 @@ impl Settings {
set_database_url(&mut s); 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() { match s.try_into() {
Ok(val) => Ok(val), 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))), 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 std::borrow::Cow;
use actix_web::body::AnyBody; use actix_web::body::BoxBody;
use actix_web::{get, http::header, web, HttpResponse, Responder}; use actix_web::{get, http::header, web, HttpResponse, Responder};
use log::debug; use log::debug;
use mime_guess::from_path; use mime_guess::from_path;
@ -82,9 +82,9 @@ struct Asset;
fn handle_assets(path: &str) -> HttpResponse { fn handle_assets(path: &str) -> HttpResponse {
match Asset::get(path) { match Asset::get(path) {
Some(content) => { Some(content) => {
let body: AnyBody = match content.data { let body: BoxBody = match content.data {
Cow::Borrowed(bytes) => bytes.into(), Cow::Borrowed(bytes) => BoxBody::new(bytes),
Cow::Owned(bytes) => bytes.into(), Cow::Owned(bytes) => BoxBody::new(bytes),
}; };
HttpResponse::Ok() HttpResponse::Ok()
@ -100,6 +100,7 @@ fn handle_assets(path: &str) -> HttpResponse {
} }
} }
#[get("/assets/{_:.*}")] #[get("/assets/{_:.*}")]
pub async fn static_files(path: web::Path<String>) -> impl Responder { pub async fn static_files(path: web::Path<String>) -> impl Responder {
handle_assets(&path) handle_assets(&path)
@ -112,9 +113,9 @@ struct Favicons;
fn handle_favicons(path: &str) -> HttpResponse { fn handle_favicons(path: &str) -> HttpResponse {
match Favicons::get(path) { match Favicons::get(path) {
Some(content) => { Some(content) => {
let body: AnyBody = match content.data { let body: BoxBody = match content.data {
Cow::Borrowed(bytes) => bytes.into(), Cow::Borrowed(bytes) => BoxBody::new(bytes),
Cow::Owned(bytes) => bytes.into(), Cow::Owned(bytes) => BoxBody::new(bytes),
}; };
HttpResponse::Ok() HttpResponse::Ok()
@ -130,6 +131,7 @@ fn handle_favicons(path: &str) -> HttpResponse {
} }
} }
#[get("/{file}")] #[get("/{file}")]
pub async fn favicons(path: web::Path<String>) -> impl Responder { pub async fn favicons(path: web::Path<String>) -> impl Responder {
debug!("searching favicons"); debug!("searching favicons");

View File

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

View File

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