You've already forked pages
forked from didirus/AstralRinth
Run rustfmt on everything
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use diesel::prelude::*;
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::prelude::*;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
pub fn connect() -> PgConnection{
|
||||
pub fn connect() -> PgConnection {
|
||||
dotenv().ok();
|
||||
|
||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set!");
|
||||
PgConnection::establish(&database_url).unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
PgConnection::establish(&database_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ mod models;
|
||||
|
||||
pub use database::connect;
|
||||
pub use models::Mod;
|
||||
pub use models::Version;
|
||||
pub use models::Version;
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct Mod {
|
||||
pub downloads: i32,
|
||||
pub categories: Vec<String>,
|
||||
pub body_path: String,
|
||||
pub icon_path: String
|
||||
pub icon_path: String,
|
||||
}
|
||||
|
||||
#[derive(Queryable)]
|
||||
@@ -20,10 +20,9 @@ pub struct Version {
|
||||
pub title: String,
|
||||
pub changelog_path: String,
|
||||
pub files_path: Vec<String>,
|
||||
pub date_published: NaiveDate,
|
||||
pub date_published: NaiveDate,
|
||||
pub author: String,
|
||||
pub downloads: i32,
|
||||
pub dependencies: Vec<String>,
|
||||
pub game_versions: Vec<String>
|
||||
pub game_versions: Vec<String>,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,28 @@ use handlebars::*;
|
||||
pub struct ContainsHelper;
|
||||
|
||||
impl HelperDef for ContainsHelper {
|
||||
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, r: &'reg Handlebars<'_>, ctx: &'rc Context, rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult {
|
||||
let array = h.param(0).map(|v| serde_json::from_value::<Vec<String>>(v.value().clone()).unwrap()).ok_or_else(|| RenderError::new("Parameter not found!"))?;
|
||||
let value = h.param(1).map(|v| v.value().as_str().unwrap()).ok_or_else(|| RenderError::new("Parameter not found!"))?;
|
||||
fn call<'reg: 'rc, 'rc>(
|
||||
&self,
|
||||
h: &Helper<'reg, 'rc>,
|
||||
r: &'reg Handlebars<'_>,
|
||||
ctx: &'rc Context,
|
||||
rc: &mut RenderContext<'reg, 'rc>,
|
||||
out: &mut dyn Output,
|
||||
) -> HelperResult {
|
||||
let array = h
|
||||
.param(0)
|
||||
.map(|v| serde_json::from_value::<Vec<String>>(v.value().clone()).unwrap())
|
||||
.ok_or_else(|| RenderError::new("Parameter not found!"))?;
|
||||
let value = h
|
||||
.param(1)
|
||||
.map(|v| v.value().as_str().unwrap())
|
||||
.ok_or_else(|| RenderError::new("Parameter not found!"))?;
|
||||
|
||||
let tmpl = if array.contains(&String::from(value)) { h.template() } else { h.inverse() };
|
||||
let tmpl = if array.contains(&String::from(value)) {
|
||||
h.template()
|
||||
} else {
|
||||
h.inverse()
|
||||
};
|
||||
|
||||
match tmpl {
|
||||
Some(ref t) => t.render(r, ctx, rc, out),
|
||||
|
||||
@@ -5,7 +5,14 @@ use handlebars::*;
|
||||
pub struct HumanFormatHelper;
|
||||
|
||||
impl HelperDef for HumanFormatHelper {
|
||||
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Handlebars<'_>, _ctx: &'rc Context, _rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult {
|
||||
fn call<'reg: 'rc, 'rc>(
|
||||
&self,
|
||||
h: &Helper<'reg, 'rc>,
|
||||
_r: &'reg Handlebars<'_>,
|
||||
_ctx: &'rc Context,
|
||||
_rc: &mut RenderContext<'reg, 'rc>,
|
||||
out: &mut dyn Output,
|
||||
) -> HelperResult {
|
||||
let param = h.param(0).and_then(|v| v.value().as_f64()).unwrap_or(0.0);
|
||||
|
||||
let mut formatted = human_format::Formatter::new().format(param);
|
||||
@@ -15,4 +22,4 @@ impl HelperDef for HumanFormatHelper {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ mod contains;
|
||||
mod format_human;
|
||||
|
||||
pub use contains::ContainsHelper;
|
||||
pub use format_human::HumanFormatHelper;
|
||||
pub use format_human::HumanFormatHelper;
|
||||
|
||||
15
src/main.rs
15
src/main.rs
@@ -4,14 +4,14 @@ extern crate serde_json;
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
use actix_files as fs;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use handlebars::*;
|
||||
use actix_files as fs;
|
||||
|
||||
mod schema;
|
||||
mod routes;
|
||||
mod helpers;
|
||||
mod database;
|
||||
mod helpers;
|
||||
mod routes;
|
||||
mod schema;
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
@@ -39,8 +39,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(routes::search_get)
|
||||
.service(routes::mod_editor_get)
|
||||
})
|
||||
.bind("127.0.0.1:8000")?
|
||||
.run()
|
||||
.await
|
||||
.bind("127.0.0.1:8000")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use actix_web::{web, HttpResponse, get};
|
||||
use actix_web::{get, web, HttpResponse};
|
||||
use handlebars::*;
|
||||
|
||||
#[get("/")]
|
||||
@@ -9,4 +9,4 @@ pub async fn index_get(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
|
||||
let body = hb.render("index", &data).unwrap();
|
||||
|
||||
HttpResponse::Ok().body(body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
mod search;
|
||||
mod index;
|
||||
mod mod_editor;
|
||||
mod search;
|
||||
|
||||
pub use self::mod_editor::mod_editor_get;
|
||||
|
||||
pub use self::search::index_mods;
|
||||
pub use self::search::search_get;
|
||||
pub use self::search::search_post;
|
||||
pub use self::search::index_mods;
|
||||
|
||||
pub use self::index::index_get;
|
||||
pub use self::index::index_get;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use actix_web::{web, HttpResponse, get};
|
||||
use actix_web::{get, web, HttpResponse};
|
||||
use handlebars::*;
|
||||
|
||||
#[get("modeditor")]
|
||||
@@ -9,4 +9,4 @@ pub async fn mod_editor_get(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
|
||||
let body = hb.render("mod_editor", &data).unwrap();
|
||||
|
||||
HttpResponse::Ok().body(body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,4 @@ table! {
|
||||
}
|
||||
}
|
||||
|
||||
allow_tables_to_appear_in_same_query!(
|
||||
mods,
|
||||
versions,
|
||||
);
|
||||
allow_tables_to_appear_in_same_query!(mods, versions,);
|
||||
|
||||
Reference in New Issue
Block a user