-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: abstract routes into separate scripts
- Loading branch information
1 parent
86a9c15
commit 500639b
Showing
3 changed files
with
38 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use axum::{ | ||
body::Body, | ||
http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}, | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
Json, | ||
}; | ||
|
||
use serde::Deserialize; | ||
use tectonic::latex_to_pdf; | ||
|
||
#[derive(Deserialize)] | ||
pub struct CompileSchema { | ||
latex: String, | ||
} | ||
|
||
pub async fn compile(Json(payload): Json<CompileSchema>) -> impl IntoResponse { | ||
let pdf = latex_to_pdf(payload.latex).expect("Unable to convert LaTeX to PDF"); | ||
let body = Body::from(pdf); | ||
|
||
Response::builder() | ||
.status(StatusCode::OK) | ||
.header(CONTENT_TYPE, "application/pdf") | ||
.header(CONTENT_DISPOSITION, "attachment; filename=\"compiled.pdf\"") | ||
.body(body) | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub async fn index() -> &'static str { | ||
"Welcome to v1 of the API!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters