linted the code.
This commit is contained in:
1 parent
0c171171c2
commit
f4170610b0
12 files changed
+84
-57
No files matched your search
+12
-10
@@ -4,15 +4,15 @@ use std::{env, path::PathBuf};
|
||||
|
||||
use actix_files;
|
||||
use actix_web::{
|
||||
App,
|
||||
dev::ServiceResponse,
|
||||
error,
|
||||
FromRequest,
|
||||
http::{header::ContentType, StatusCode}, HttpRequest, HttpResponse, HttpServer, middleware::{ErrorHandlerResponse, ErrorHandlers, Logger}, Responder, Result, web,
|
||||
http::{header::ContentType, StatusCode},
|
||||
middleware::{ErrorHandlerResponse, ErrorHandlers, Logger},
|
||||
web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder, Result,
|
||||
};
|
||||
use actix_web_lab::respond::Html;
|
||||
use async_channel;
|
||||
use futures::{FutureExt, pin_mut, select};
|
||||
use futures::{pin_mut, select, FutureExt};
|
||||
use minijinja;
|
||||
use minijinja_autoreload::AutoReloader;
|
||||
use rusqlite::Connection;
|
||||
@@ -83,9 +83,11 @@ fn create_auto_reloader(enable_template_autoreload: bool) -> AutoReloader {
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn web_ui_main(connFact: SQLiteConnectionFactory,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool) -> CustomResult<()> {
|
||||
pub async fn web_ui_main(
|
||||
connFact: SQLiteConnectionFactory,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool,
|
||||
) -> CustomResult<()> {
|
||||
// The closure is invoked every time the environment is outdated to recreate it.
|
||||
let tmpl_reloader = create_auto_reloader(enable_template_autoreload);
|
||||
|
||||
@@ -113,9 +115,9 @@ pub async fn web_ui_main(connFact: SQLiteConnectionFactory,
|
||||
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, not_found))
|
||||
.wrap(Logger::default())
|
||||
})
|
||||
.workers(2)
|
||||
.bind(("0.0.0.0", port))
|
||||
.unwrap();
|
||||
.workers(2)
|
||||
.bind(("0.0.0.0", port))
|
||||
.unwrap();
|
||||
|
||||
let t1 = server.run().fuse();
|
||||
let t2 = event_processor_loop(connFact, event_receiver).fuse();
|
||||
|
||||
+13
-9
@@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use actix_web::{error, HttpRequest, Responder, web};
|
||||
use actix_web::{error, web, HttpRequest, Responder};
|
||||
use clap::builder::TypedValueParser;
|
||||
use log::info;
|
||||
use minijinja::context;
|
||||
@@ -23,8 +23,10 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Resp
|
||||
}
|
||||
|
||||
#[actix_web::get("/overview")]
|
||||
pub async fn overview(tmpl_env: MiniJinjaRenderer,
|
||||
connFactory: web::Data<SQLiteConnectionFactory>) -> actix_web::Result<impl Responder> {
|
||||
pub async fn overview(
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
connFactory: web::Data<SQLiteConnectionFactory>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let conn = connFactory.readonly().unwrap(); // todo; to proper 500
|
||||
let service_factory = ServiceFactory::new(&conn);
|
||||
let user_service = service_factory.get_user_service();
|
||||
@@ -41,10 +43,11 @@ struct LoginPayload {
|
||||
password: String,
|
||||
}
|
||||
|
||||
|
||||
#[actix_web::post("/login")]
|
||||
pub async fn login(tmpl_env: MiniJinjaRenderer,
|
||||
web::Json(form): web::Json<LoginPayload>) -> actix_web::Result<impl Responder> {
|
||||
pub async fn login(
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
web::Json(form): web::Json<LoginPayload>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let ctx = context! {
|
||||
name => form.username,
|
||||
};
|
||||
@@ -55,7 +58,9 @@ pub async fn login(tmpl_env: MiniJinjaRenderer,
|
||||
pub async fn logout(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
|
||||
let ctx = context! {};
|
||||
let res = tmpl_env.render("partials/index/form.html", ctx)?;
|
||||
Ok(res.customize().insert_header(("Set-Cookie", "username=nobody")))
|
||||
Ok(res
|
||||
.customize()
|
||||
.insert_header(("Set-Cookie", "username=nobody")))
|
||||
}
|
||||
|
||||
#[actix_web::get("/partials/overview/submit_button")]
|
||||
@@ -86,7 +91,6 @@ pub async fn actions_partials(
|
||||
tmpl_env.render(template_location.as_str(), ctx)
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct CreateEventPayload {
|
||||
event: Event,
|
||||
@@ -102,7 +106,7 @@ pub async fn push_event(
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let path_event_type = req.match_info().get("event_type").unwrap();
|
||||
if path_event_type.to_string() != form.event_type {
|
||||
return Err(error::ErrorBadRequest("Inconsistent event type."))
|
||||
return Err(error::ErrorBadRequest("Inconsistent event type."));
|
||||
}
|
||||
let validation = form.event.validate_event();
|
||||
if validation.is_err() {
|
||||
|
||||
+5
-3
@@ -6,12 +6,14 @@ use tokio::time::sleep;
|
||||
|
||||
use crate::event_processor::process_event;
|
||||
use crate::events::Event;
|
||||
use crate::util::{CustomResult, SQLiteConnectionFactory};
|
||||
use crate::util::Error::FuckingError;
|
||||
use crate::util::{CustomResult, SQLiteConnectionFactory};
|
||||
|
||||
// todo, all the "?" and handle the exceptions for real
|
||||
pub async fn event_processor_loop(conFact: SQLiteConnectionFactory,
|
||||
r: async_channel::Receiver<Event>) -> CustomResult<()> {
|
||||
pub async fn event_processor_loop(
|
||||
conFact: SQLiteConnectionFactory,
|
||||
r: async_channel::Receiver<Event>,
|
||||
) -> CustomResult<()> {
|
||||
loop {
|
||||
let res = r.recv().await;
|
||||
let mut conn = conFact.connection()?;
|
||||
|
||||
Reference in new issue
Block a user