feat(curl): add curl support

Signed-off-by: supercmmetry <vishaals2000@gmail.com>
This commit is contained in:
supercmmetry 2021-07-29 11:34:00 +05:30
parent 9bf7458c04
commit 0182fa749e
No known key found for this signature in database
GPG Key ID: 8E60EF28A328E40D
3 changed files with 28 additions and 3 deletions

View File

@ -6,7 +6,7 @@ use rocket::response::status::Custom;
use rocket_contrib::json::Json;
use serde_json::Value;
use crate::api::catchers::{forbidden, internal_server_error, not_found, unprocessable_entity};
use crate::{api::catchers::{forbidden, internal_server_error, not_found, unprocessable_entity}, utils::domain::get_domain};
use crate::api::guards::db::DbConn;
use crate::core::paste::{entity::Paste, service::{create_paste, fetch_paste, update_paste}};
use crate::core::users::service::{create_or_fetch_user, fetch_user};
@ -130,6 +130,25 @@ fn update(mut paste: Json<Paste>, conn: DbConn, mut ck: Cookies) -> Custom<Json<
}
}
pub fn fuel(rocket: Rocket) -> Rocket {
rocket.mount("/api/paste", routes![create, fetch, update])
#[post("/", data = "<input>")]
fn anonymous(input: String, conn: DbConn) -> String {
let mut new_paste = Paste {
id: Some(phonetic_key::get_random_id()),
belongs_to: None,
content: input,
is_url: None,
};
dbg!(new_paste.id.clone());
match create_paste(&mut new_paste, &conn) {
Ok(_) => format!("{}/{}", get_domain(), new_paste.id.unwrap()),
Err(_) => String::from("Internal Server Error"),
}
}
pub fn fuel(rocket: Rocket) -> Rocket {
rocket
.mount("/api/paste", routes![create, fetch, update])
.mount("/", routes![anonymous])
}

5
src/utils/domain.rs Normal file
View File

@ -0,0 +1,5 @@
use std::env;
pub fn get_domain() -> String {
env::var("KATBIN_DOMAIN_NAME").unwrap().parse::<String>().expect("domain name")
}

View File

@ -2,3 +2,4 @@ pub mod db;
pub mod errors;
pub mod phonetic_key;
pub mod users;
pub mod domain;