Load new math resources in the native Web editor

This commit is contained in:
gloamxun committed 2026-11-29 14:01:40 +08:00
1 parent 8b6dab8d52
commit fe86163767
12 files changed
+838 -106

No files matched your search

+28
View File
@@ -982,6 +982,34 @@ impl CompileJob {
}
pub fn compile_detailed(
self,
request: CompileRequest,
) -> Result<Arc<CompiledDocument>, CompileFailure> {
self.compile_attempt(request)
}
/// Retry a failed, unpublished attempt in the same revision after the
/// caller supplies a new snapshot. A newer revision cancels every attempt.
pub fn compile_expanding_project(
self,
mut request: CompileRequest,
mut expand: impl FnMut(&CompileFailure) -> Option<Arc<ProjectSnapshot>>,
) -> Result<Arc<CompiledDocument>, CompileFailure> {
for _ in 0..24 {
match self.compile_attempt(request.clone()) {
Err(failure) if !self.job.cancellation().is_cancelled() => {
let Some(project) = expand(&failure) else {
return Err(failure);
};
request = request.with_project(project);
}
result => return result,
}
}
self.compile_attempt(request)
}
fn compile_attempt(
&self,
mut request: CompileRequest,
) -> Result<Arc<CompiledDocument>, CompileFailure> {
if self.compiler.entry_checkpoints.is_some()
+13 -2
View File
@@ -13,11 +13,14 @@ const MAX_FILE_BYTES: u64 = 16 * 1024 * 1024;
const ZIP64_MESSAGE: &str =
"ZIP64 archives are not supported; re-create the archive without ZIP64 extensions";
#[derive(serde::Serialize)]
pub(super) struct ProjectFile {
pub(super) path: String,
pub(super) size: u64,
}
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub(super) struct ProjectInfo {
pub(super) id: String,
pub(super) name: String,
@@ -629,6 +632,7 @@ fn read_zip(bytes: &[u8]) -> Result<Vec<(String, Vec<u8>)>, String> {
}
let mut entries = Vec::new();
let mut cursor = cd_offset;
let mut expanded = 0u64;
for _ in 0..count {
if read_u32(cursor)? != 0x0201_4b50 {
return Err("corrupt zip central directory".to_string());
@@ -653,6 +657,13 @@ fn read_zip(bytes: &[u8]) -> Result<Vec<(String, Vec<u8>)>, String> {
if flags & 0x0001 != 0 {
return Err("encrypted zip entries are not supported".to_string());
}
expanded += uncompressed_size as u64;
if uncompressed_size as u64 > MAX_FILE_BYTES
|| expanded > MAX_PROJECT_BYTES
|| entries.len() >= MAX_PROJECT_FILES
{
return Err(format!("ZIP entry exceeds project limits: {name}"));
}
if read_u32(local_offset)? != 0x0403_4b50 {
return Err("corrupt zip local header".to_string());
}
@@ -665,9 +676,9 @@ fn read_zip(bytes: &[u8]) -> Result<Vec<(String, Vec<u8>)>, String> {
let content = match method {
0 => data.to_vec(),
8 => {
let mut decoder = DeflateDecoder::new(data);
let mut output = Vec::new();
decoder
DeflateDecoder::new(data)
.take(uncompressed_size as u64 + 1)
.read_to_end(&mut output)
.map_err(|error| format!("could not inflate `{name}`: {error}"))?;
output