Ergebnisse: erzeugte Seite im gesicherten Rahmen starten (Seite ansehen)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -571,6 +571,42 @@ fn run_files(
|
||||
artifacts::list_files(std::path::Path::new(&dir), if run.external { None } else { Some(base.as_path()) })
|
||||
}
|
||||
|
||||
/// Die Seite (`index.html`), die ein Lauf erzeugt hat, damit die Oberfläche sie in einem gesicherten
|
||||
/// Rahmen zeigen kann. Größer als 2 MB wird sie nicht geliefert.
|
||||
#[tauri::command]
|
||||
fn run_page(
|
||||
paths: State<'_, AppPaths>,
|
||||
batch_id: i64,
|
||||
model: String,
|
||||
task_id: String,
|
||||
repeat_idx: u32,
|
||||
) -> Result<Option<String>, String> {
|
||||
let store = Store::open(&paths.0.data_dir.join(DB_FILE))?;
|
||||
let run = store
|
||||
.runs_for_batch(batch_id)?
|
||||
.into_iter()
|
||||
.find(|r| r.model == model && r.task_id == task_id && r.repeat_idx == repeat_idx)
|
||||
.ok_or("Lauf nicht gefunden.")?;
|
||||
let Some(work) = run.artifact_path else { return Ok(None) };
|
||||
let base = paths.0.data_dir.join("runs");
|
||||
let real = std::path::Path::new(&work).canonicalize().map_err(|_| "Ergebnisordner existiert nicht mehr.".to_string())?;
|
||||
if !run.external {
|
||||
let base = base.canonicalize().map_err(|e| format!("Datenordner nicht lesbar: {e}"))?;
|
||||
if !real.starts_with(&base) {
|
||||
return Err("Der Ergebnisordner liegt außerhalb des Datenordners.".into());
|
||||
}
|
||||
}
|
||||
let file = real.join("index.html");
|
||||
let meta = match std::fs::symlink_metadata(&file) {
|
||||
Ok(m) if m.is_file() => m,
|
||||
_ => return Ok(None),
|
||||
};
|
||||
if meta.len() > 2 * 1024 * 1024 {
|
||||
return Err("index.html ist größer als 2 MB und wird nicht angezeigt.".into());
|
||||
}
|
||||
Ok(std::fs::read_to_string(&file).ok())
|
||||
}
|
||||
|
||||
/// Ein Punkt der Checkliste einer Demo-Aufgabe.
|
||||
#[derive(Serialize, serde::Deserialize)]
|
||||
pub struct CheckItem {
|
||||
@ -729,6 +765,7 @@ pub fn run() {
|
||||
run_steps,
|
||||
run_files,
|
||||
run_demo_output,
|
||||
run_page,
|
||||
task_catalog,
|
||||
task_stats,
|
||||
runtime_status,
|
||||
|
||||
Reference in New Issue
Block a user