Handle paste dynamic fetch

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-12-11 19:16:24 +05:30
parent 8d755c01f7
commit e7a18f4b03
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5
2 changed files with 10 additions and 6 deletions

View file

@ -9,7 +9,7 @@ struct Template {
#[derive(Deserialize)]
struct Paste {
paste_id: String,
paste_id: Option<String>,
}
@ -20,15 +20,19 @@ async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Respond
let client = Client::new();
let mut headers = HeaderMap::new();
headers.insert("PRIVATE-TOKEN", "".parse().unwrap());
let resp = client.get("https://git.baalajimaestro.me/api/v4/projects/?ref=master").headers(headers).send().await.unwrap();
let data = resp.text().await.unwrap();
context.insert("paste_content", &data);
let resp: String;
if paste.paste_id.is_some() {
resp = client.get(format!("https://git.baalajimaestro.me/api/v4/projects/12/repository/files/paste%2F{}.md?ref=master", paste.paste_id.as_ref().unwrap())).headers(headers).send().await.unwrap().text().await.unwrap();
}
else {
resp = "".to_string();
}
context.insert("paste_content", &resp);
let rendered = my_data.paste.render("paste.html", &context);
HttpResponse::Ok().body(rendered.unwrap())
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let tera = match Tera::new("templates/*.html") {