cargo fix the project
Make use of clippy and rustfmt Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -1,19 +1,20 @@
|
|||||||
#![feature(proc_macro_hygiene, decl_macro)]
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||||||
#[macro_use] extern crate rocket;
|
#[macro_use]
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
extern crate tree_magic;
|
extern crate tree_magic;
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use rocket_contrib::templates::Template;
|
|
||||||
use rocket::request::Form;
|
use rocket::request::Form;
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket::Data;
|
use rocket::Data;
|
||||||
|
use rocket_contrib::templates::Template;
|
||||||
|
|
||||||
mod paste_id;
|
mod paste_id;
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ fn pretty_retrieve(id: PasteId) -> Option<Template> {
|
|||||||
|
|
||||||
match tree_magic::match_filepath("text/plain", filepath) {
|
match tree_magic::match_filepath("text/plain", filepath) {
|
||||||
true => Some(rendered),
|
true => Some(rendered),
|
||||||
false => None
|
false => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,12 +60,21 @@ fn upload(paste: Data) -> Result<String, std::io::Error> {
|
|||||||
// Look into using open(), take() methods in the Data struct
|
// Look into using open(), take() methods in the Data struct
|
||||||
paste.stream_to_file(filepath)?;
|
paste.stream_to_file(filepath)?;
|
||||||
|
|
||||||
let url = match tree_magic::from_filepath(filepath).as_str().contains("text") {
|
let url = match tree_magic::from_filepath(filepath)
|
||||||
true => format!("https://{host}/p/{id}\n", host = env::var("HOST_URL")
|
.as_str()
|
||||||
.unwrap_or("<no_host_provided>".to_string()), id = id),
|
.contains("text")
|
||||||
|
{
|
||||||
|
true => format!(
|
||||||
|
"https://{host}/p/{id}\n",
|
||||||
|
host = env::var("HOST_URL").unwrap_or("<no_host_provided>".to_string()),
|
||||||
|
id = id
|
||||||
|
),
|
||||||
|
|
||||||
false => format!("https://{host}/{id}\n", host = env::var("HOST_URL")
|
false => format!(
|
||||||
.unwrap_or("http://localhost:8000".to_string()), id = id)
|
"https://{host}/{id}\n",
|
||||||
|
host = env::var("HOST_URL").unwrap_or("http://localhost:8000".to_string()),
|
||||||
|
id = id
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(url)
|
Ok(url)
|
||||||
@@ -96,7 +106,10 @@ fn index() -> Option<Template> {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.mount("/", routes![index, upload, submit, retrieve, pretty_retrieve])
|
.mount(
|
||||||
|
"/",
|
||||||
|
routes![index, upload, submit, retrieve, pretty_retrieve],
|
||||||
|
)
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
.launch();
|
.launch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ impl<'a> FromParam<'a> for PasteId<'a> {
|
|||||||
fn from_param(param: &'a RawStr) -> Result<Self, Self::Error> {
|
fn from_param(param: &'a RawStr) -> Result<Self, Self::Error> {
|
||||||
match valid_id(param) {
|
match valid_id(param) {
|
||||||
true => Ok(PasteId(Cow::Borrowed(param))),
|
true => Ok(PasteId(Cow::Borrowed(param))),
|
||||||
false => Err(param)
|
false => Err(param),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user