Expand input files in project PDF exports
This commit is contained in:
1 parent
a5da5c9521
commit
6a4483cf4d
5 files changed
+65
-13
No files matched your search
+14
-9
@@ -409,6 +409,17 @@ fn respond_pdf(request: Request, pdf: Vec<u8>) -> Result<(), String> {
|
||||
const MAX_ZIP_BYTES: usize = 32 * 1024 * 1024;
|
||||
const MAX_UPLOAD_BYTES: usize = 16 * 1024 * 1024;
|
||||
|
||||
fn expand_project_inputs(source: &str, store: &projects::ProjectStore, id: &str) -> String {
|
||||
let read = |path: &str| {
|
||||
let bytes = store
|
||||
.read_file(id, path)
|
||||
.ok()
|
||||
.or_else(|| store.read_file(id, &format!("{path}.tex")).ok())?;
|
||||
String::from_utf8(bytes).ok()
|
||||
};
|
||||
route_d::expand_inputs(source, read)
|
||||
}
|
||||
|
||||
fn handle_project_request(
|
||||
mut request: Request,
|
||||
method: &Method,
|
||||
@@ -500,14 +511,7 @@ fn handle_project_request(
|
||||
Err(error) => return respond_api_error(request, 422, &error),
|
||||
};
|
||||
if query_param(url, "engine").as_deref() == Some("route-d") {
|
||||
let read = |path: &str| {
|
||||
let bytes = store
|
||||
.read_file(id, path)
|
||||
.ok()
|
||||
.or_else(|| store.read_file(id, &format!("{path}.tex")).ok())?;
|
||||
String::from_utf8(bytes).ok()
|
||||
};
|
||||
let expanded = route_d::expand_inputs(&source, read);
|
||||
let expanded = expand_project_inputs(&source, &store, id);
|
||||
return match route_d::project_preview_json(id, &expanded) {
|
||||
Ok(json) => respond_json(request, 200, &json),
|
||||
Err(error) => respond_api_error(request, 422, &error),
|
||||
@@ -529,7 +533,8 @@ fn handle_project_request(
|
||||
Err(error) => return respond_api_error(request, 422, &error),
|
||||
};
|
||||
if query_param(url, "engine").as_deref() == Some("route-d") {
|
||||
return match route_d::pdf_bytes(&source) {
|
||||
let expanded = expand_project_inputs(&source, &store, id);
|
||||
return match route_d::pdf_bytes(&expanded) {
|
||||
Ok(pdf) => respond_pdf(request, pdf),
|
||||
Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user