Run cargo fmt
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
55319a84da
commit
62b3c30a48
1 changed files with 18 additions and 13 deletions
31
src/main.rs
31
src/main.rs
|
@ -1,10 +1,15 @@
|
||||||
use actix_web::{get, App, HttpResponse, HttpServer, Responder, web::{Data, Query}, http::header::ContentType};
|
|
||||||
use actix_files as fs;
|
use actix_files as fs;
|
||||||
use tera::{Tera, Context};
|
use actix_web::{
|
||||||
use serde::{Serialize, Deserialize};
|
get,
|
||||||
use reqwest::{Client, header::HeaderMap};
|
http::header::ContentType,
|
||||||
use std::env;
|
web::{Data, Query},
|
||||||
|
App, HttpResponse, HttpServer, Responder,
|
||||||
|
};
|
||||||
use mime::TEXT_HTML;
|
use mime::TEXT_HTML;
|
||||||
|
use reqwest::{header::HeaderMap, Client};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::env;
|
||||||
|
use tera::{Context, Tera};
|
||||||
|
|
||||||
struct Template {
|
struct Template {
|
||||||
paste: Tera,
|
paste: Tera,
|
||||||
|
@ -45,23 +50,23 @@ async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Respond
|
||||||
let response_json = response.text().await.unwrap();
|
let response_json = response.text().await.unwrap();
|
||||||
if response_code != "200" {
|
if response_code != "200" {
|
||||||
paste_content = "Paste ID Invalid".to_string();
|
paste_content = "Paste ID Invalid".to_string();
|
||||||
|
} else {
|
||||||
|
let resp_struct: ResponseJSON = serde_json::from_str(&response_json).unwrap();
|
||||||
|
paste_content =
|
||||||
|
String::from_utf8(base64::decode(resp_struct.content).unwrap()).unwrap();
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
let resp_struct: ResponseJSON = serde_json::from_str(&response_json).unwrap();
|
|
||||||
paste_content = String::from_utf8(base64::decode(resp_struct.content).unwrap()).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
paste_content = "Provide a Paste ID".to_string();
|
paste_content = "Provide a Paste ID".to_string();
|
||||||
}
|
}
|
||||||
context.insert("paste_content", &paste_content);
|
context.insert("paste_content", &paste_content);
|
||||||
let rendered = my_data.paste.render("paste.html", &context);
|
let rendered = my_data.paste.render("paste.html", &context);
|
||||||
HttpResponse::Ok().insert_header(ContentType(TEXT_HTML)).body(rendered.unwrap())
|
HttpResponse::Ok()
|
||||||
|
.insert_header(ContentType(TEXT_HTML))
|
||||||
|
.body(rendered.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
let tera = match Tera::new("templates/*.html") {
|
let tera = match Tera::new("templates/*.html") {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
Loading…
Reference in a new issue