You've already forked AstralRinth
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::pg::PgConnection;
|
||||||
|
use diesel::prelude::*;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
pub fn connect() -> PgConnection{
|
pub fn connect() -> PgConnection {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set!");
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ pub struct Mod {
|
|||||||
pub downloads: i32,
|
pub downloads: i32,
|
||||||
pub categories: Vec<String>,
|
pub categories: Vec<String>,
|
||||||
pub body_path: String,
|
pub body_path: String,
|
||||||
pub icon_path: String
|
pub icon_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable)]
|
#[derive(Queryable)]
|
||||||
@@ -20,10 +20,9 @@ pub struct Version {
|
|||||||
pub title: String,
|
pub title: String,
|
||||||
pub changelog_path: String,
|
pub changelog_path: String,
|
||||||
pub files_path: Vec<String>,
|
pub files_path: Vec<String>,
|
||||||
pub date_published: NaiveDate,
|
pub date_published: NaiveDate,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
pub downloads: i32,
|
pub downloads: i32,
|
||||||
pub dependencies: Vec<String>,
|
pub dependencies: Vec<String>,
|
||||||
pub game_versions: Vec<String>
|
pub game_versions: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,28 @@ use handlebars::*;
|
|||||||
pub struct ContainsHelper;
|
pub struct ContainsHelper;
|
||||||
|
|
||||||
impl HelperDef for 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 {
|
fn call<'reg: 'rc, 'rc>(
|
||||||
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!"))?;
|
&self,
|
||||||
let value = h.param(1).map(|v| v.value().as_str().unwrap()).ok_or_else(|| RenderError::new("Parameter not found!"))?;
|
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 {
|
match tmpl {
|
||||||
Some(ref t) => t.render(r, ctx, rc, out),
|
Some(ref t) => t.render(r, ctx, rc, out),
|
||||||
|
|||||||
@@ -5,7 +5,14 @@ use handlebars::*;
|
|||||||
pub struct HumanFormatHelper;
|
pub struct HumanFormatHelper;
|
||||||
|
|
||||||
impl HelperDef for 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 param = h.param(0).and_then(|v| v.value().as_f64()).unwrap_or(0.0);
|
||||||
|
|
||||||
let mut formatted = human_format::Formatter::new().format(param);
|
let mut formatted = human_format::Formatter::new().format(param);
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@@ -4,14 +4,14 @@ extern crate serde_json;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
|
use actix_files as fs;
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
use handlebars::*;
|
use handlebars::*;
|
||||||
use actix_files as fs;
|
|
||||||
|
|
||||||
mod schema;
|
|
||||||
mod routes;
|
|
||||||
mod helpers;
|
|
||||||
mod database;
|
mod database;
|
||||||
|
mod helpers;
|
||||||
|
mod routes;
|
||||||
|
mod schema;
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
@@ -39,8 +39,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.service(routes::search_get)
|
.service(routes::search_get)
|
||||||
.service(routes::mod_editor_get)
|
.service(routes::mod_editor_get)
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8000")?
|
.bind("127.0.0.1:8000")?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use actix_web::{web, HttpResponse, get};
|
use actix_web::{get, web, HttpResponse};
|
||||||
use handlebars::*;
|
use handlebars::*;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
mod search;
|
|
||||||
mod index;
|
mod index;
|
||||||
mod mod_editor;
|
mod mod_editor;
|
||||||
|
mod search;
|
||||||
|
|
||||||
pub use self::mod_editor::mod_editor_get;
|
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_get;
|
||||||
pub use self::search::search_post;
|
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::*;
|
use handlebars::*;
|
||||||
|
|
||||||
#[get("modeditor")]
|
#[get("modeditor")]
|
||||||
|
|||||||
@@ -27,7 +27,4 @@ table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(
|
allow_tables_to_appear_in_same_query!(mods, versions,);
|
||||||
mods,
|
|
||||||
versions,
|
|
||||||
);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user