Handle paste dynamic fetch
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
8d755c01f7
commit
e7a18f4b03
2 changed files with 10 additions and 6 deletions
|
@ -9,4 +9,4 @@ edition = "2021"
|
|||
actix-web = "4"
|
||||
tera = "1.17.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
reqwest = { version = "0.11",default-features = false, features = ["rustls-tls"] }
|
||||
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -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") {
|
||||
|
|
Loading…
Reference in a new issue