From 72ec85a1a0e9680ba09ba594ce731364238903cd Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Sun, 29 Nov 2026 23:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=B0=8F=E5=A3=B9=E5=AE=BF?= =?UTF-8?q?=E4=B8=BB=E7=9A=84=E7=94=BB=E5=B8=83=E5=88=B6=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E9=97=A8=E7=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/jiansun_canvas_workspace.rs | 61 +++++++++++++------ .../photocraft/src/jiansun_template_slots.rs | 22 ++++++- 2 files changed, 65 insertions(+), 18 deletions(-) diff --git a/apps/detail-photocraft/apps/photocraft/src/jiansun_canvas_workspace.rs b/apps/detail-photocraft/apps/photocraft/src/jiansun_canvas_workspace.rs index f4b1f03a..f238e973 100644 --- a/apps/detail-photocraft/apps/photocraft/src/jiansun_canvas_workspace.rs +++ b/apps/detail-photocraft/apps/photocraft/src/jiansun_canvas_workspace.rs @@ -2769,9 +2769,10 @@ fn candidate_export_source(dir: &Path, record: &Value) -> Value { source } -fn export_image_sources(dir: &Path, doc: &Document, state: &Value, meta: &Value, component: &str, variant: &str, aspects: &Value) -> (Vec, Vec) { +fn export_image_sources(dir: &Path, doc: &Document, state: &Value, meta: &Value, component: &str, variant: &str, aspects: &Value) -> (Vec, Vec, Vec) { use photocraft_doc::{LayerContent, LayerId, SmartSource}; let mut missing = Vec::new(); + let mut invalid_sources = Vec::new(); let mut sources = Vec::new(); let template = &state["template"]; let current_input = input_hash(dir, state, variant).ok(); @@ -2783,16 +2784,16 @@ fn export_image_sources(dir: &Path, doc: &Document, state: &Value, meta: &Value, let layer_path = mapping.into_iter().flatten().find(|row| row["kind"] == "image" && row["slotId"] == slot) .and_then(|row| row["nativeLayerId"].as_u64()).and_then(|id| doc.path_of(LayerId(id))); let marker = format!("jiansun.adopted.{variant}.{slot}"); - let record = doc.metadata.text.iter().find(|(key, _)| *key == marker).and_then(|(_, id)| read_candidate(dir, id).ok()) + let adopted = doc.metadata.text.iter().find(|(key, _)| *key == marker); + let record = adopted.and_then(|(_, id)| read_candidate(dir, id).ok()) .filter(|record| candidate_available(record) && record["binding"]["slotId"] == slot && record["binding"]["workspaceId"] == state["id"] && record["binding"]["templateHash"] == template["contentHash"] && record["binding"]["variantId"] == variant && record["inputHash"].as_str().is_none_or(|input| !input.starts_with(VARIANT_INPUT_HASH) || current_input.as_deref() == Some(input))); + let visible = layer_path.as_ref().is_some_and(|path| (1..=path.len()) + .all(|len| doc.layer_at(&path[..len]).is_some_and(|layer| layer.visible && layer.opacity > 0.0))); let found = layer_path.zip(record).and_then(|(path, record)| { - if !(1..=path.len()).all(|len| doc.layer_at(&path[..len]).is_some_and(|layer| layer.visible && layer.opacity > 0.0)) { - return None; - } let layer = doc.layer_at(&path)?; let LayerContent::Smart(smart) = &layer.content else { return None; }; let SmartSource::Embedded { file_name, bytes } = &smart.source else { return None; }; @@ -2809,14 +2810,17 @@ fn export_image_sources(dir: &Path, doc: &Document, state: &Value, meta: &Value, source["embeddedSize"] = json!(creation::png_size(bytes).ok()); Some(source) }); - if let Some(source) = found { + if found.is_none() && adopted.is_some() { + invalid_sources.push(id.to_owned()); + } + if let Some(source) = found.filter(|_| visible) { sources.push(source); } else { missing.push(id.to_owned()); } } } - (missing, sources) + (missing, invalid_sources, sources) } fn unverified_export_copy( @@ -3547,6 +3551,7 @@ fn export_product_stage_snapshot(dir: &Path, doc: u64, state: &Value, input: &Va return Ok(result); } result["exportAttempted"] = json!(true); + let agent_export = input["writeEpoch"].is_u64(); let blocked = |mut result: Value| { result["productionDelivery"] = json!({"state":"blocked","outputId":component}); Ok(result) @@ -3581,25 +3586,33 @@ fn export_product_stage_snapshot(dir: &Path, doc: u64, state: &Value, input: &Va result["productionProfile"] = production_profile::source(&state["template"], component); if let Some(layer) = production_profile::visible_sample_layer(native, profile, &meta) { result["visibleSampleLayer"] = json!(layer.name); - return blocked(result); + if !agent_export { return blocked(result); } } let missing_text = production_profile::missing_visible_text(native, &meta, profile); if !missing_text.is_empty() { result["missingVisibleText"] = json!(missing_text); - return blocked(result); + if !agent_export { return blocked(result); } } } if production_profile::fixed_text_policy(profile) { if let Some(layer) = production_profile::unapproved_fixed_text(native, &meta) { - result["visibleSampleLayer"] = json!(format!("{}(模板未声明可保留此固定文字)", layer.name)); - return blocked(result); + if agent_export { + result["unapprovedFixedText"] = json!(layer.name); + } else { + result["visibleSampleLayer"] = json!(format!("{}(模板未声明可保留此固定文字)", layer.name)); + } + if !agent_export { return blocked(result); } } } else { result["warnings"] = json!([production_profile::UNPUBLISHED_FIXED_TEXT]); } - let (missing, image_sources) = export_image_sources(dir, native, state, &meta, component, &variant_id, &aspects); + let (missing, invalid_sources, image_sources) = export_image_sources(dir, native, state, &meta, component, &variant_id, &aspects); if !missing.is_empty() { result["missingImages"] = json!(missing); + if !agent_export { return blocked(result); } + } + if !invalid_sources.is_empty() { + result["invalidImageSources"] = json!(invalid_sources); return blocked(result); } let journal = production_audit(dir, state, component, &variant_id, scope)?; @@ -3902,15 +3915,14 @@ impl Backend { if output["component"] != state["activeOutput"] { return Err("图片图位不属于所选制作输出".into()); } - let mapped = mapped_slot(&state, id, variant) - .filter(|slot| slot["nativeLayerId"].is_u64()).ok_or("请先打开对应模板画布,核对图片图层范围")?; + let mapped = mapped_slot(&state, id, variant); scoped_binding = binding.clone(); scoped_binding["scope"]["structureHash"] = state["structureHash"].clone(); if scoped_binding["revision"].is_null() { scoped_binding["revision"] = state["revision"].clone(); } scoped_binding["slotLabel"] = field.get("name").or(field.get("label")).unwrap_or(&field["fieldId"]).clone(); - let frame = slot_frame(field, Some(mapped)).ok_or("当前图片图层缺少已核对的范围")?; + let frame = slot_frame(field, mapped).ok_or("当前图片图层缺少已核对的范围")?; scoped_binding["imageFrame"] = json!({"width":frame["width"],"height":frame["height"]}); &scoped_binding } else { binding }; @@ -6097,7 +6109,7 @@ mod tests { } #[test] - fn completed_stage_cannot_export_a_template_with_an_unfilled_image_slot() { + fn missing_image_adoption_is_reported_for_agent_export_and_blocks_manual_export() { let fixture = fixture(); let mut state = load(&fixture.dir).unwrap(); let version = state["template"].clone(); @@ -6121,6 +6133,21 @@ mod tests { assert_eq!(result["files"], json!([])); assert!(!receipt_path(&fixture.dir,variant,"detail").exists()); + let mut agent_input = input.clone(); + agent_input["writeEpoch"] = json!(1); + let partial = export_product_stage_snapshot(&fixture.dir, 1, &state, &agent_input, "test-account", Some(&doc)).unwrap(); + assert_eq!(partial["missingImages"], json!(["S01-I01"])); + assert_eq!(partial["productionDelivery"]["outputState"], "exported"); + assert!(artifact_matches(&partial["files"][0], true)); + + let mut invalid_doc = doc.clone(); + let slot = slot_id(&state["template"]["contentHash"], variant, "S01-I01"); + invalid_doc.metadata.text.push((format!("jiansun.adopted.{variant}.{slot}"), Uuid::new_v4().to_string())); + let invalid = export_product_stage_snapshot(&fixture.dir, 1, &state, &agent_input, "test-account", Some(&invalid_doc)).unwrap(); + assert_eq!(invalid["invalidImageSources"], json!(["S01-I01"])); + assert_eq!(invalid["files"], json!([])); + assert_eq!(published_receipt(&receipt_path(&fixture.dir, variant, "detail")).unwrap()["generationId"], partial["generationId"]); + let mut candidate = candidate(&fixture.dir,"complete"); let id = candidate["id"].as_str().unwrap().to_owned(); let slot = candidate["binding"]["slotId"].as_str().unwrap().to_owned(); @@ -6206,7 +6233,7 @@ mod tests { assert!(artifact_matches(&ready["sourceDocument"], true)); assert!(artifact_matches(&snapshot["sourceDocument"], true)); let reopened = photocraft_format::load_path(Path::new(snapshot["editable"].as_str().unwrap())).unwrap(); - let (missing, source_links) = export_image_sources(&fixture.dir, &reopened, &state, &meta, "detail", variant, &Value::Null); + let (missing, _, source_links) = export_image_sources(&fixture.dir, &reopened, &state, &meta, "detail", variant, &Value::Null); assert!(missing.is_empty()); assert_eq!(snapshot["imageSources"], json!(source_links)); assert_eq!(snapshot["imageSources"][0]["fieldId"], "S01-I01"); diff --git a/apps/detail-photocraft/apps/photocraft/src/jiansun_template_slots.rs b/apps/detail-photocraft/apps/photocraft/src/jiansun_template_slots.rs index 16e0bff6..e1a19571 100644 --- a/apps/detail-photocraft/apps/photocraft/src/jiansun_template_slots.rs +++ b/apps/detail-photocraft/apps/photocraft/src/jiansun_template_slots.rs @@ -49,6 +49,8 @@ pub(super) fn validate_pack(pack: &Value) -> R<()> { return Err("模板包校验值不一致,未覆盖项目模板".into()); } let enterprise = pack["enterprise"].is_object(); + let native_xiaoyi = enterprise && (pack["enterprise"]["sourceKind"] == "xiaoyi-release" + || pack["xiaoyi"].is_object()); if enterprise && (!enterprise_version(&pack["enterprise"], &pack["version"]) || !hex(&pack["enterprise"]["manifestRevision"]) || !hex(&pack["enterprise"]["originalSha256"])) { return Err("企业模板版本身份无效".into()); } let outputs = pack["outputs"].as_array().filter(|a| !a.is_empty() && a.len() <= 40).ok_or("模板须含1至40项产出")?; let mut fields = std::collections::HashSet::new(); @@ -110,7 +112,11 @@ pub(super) fn validate_pack(pack: &Value) -> R<()> { let f = &slot["frame"]; let (x, y, w, h) = (number(&f["x"], "字段横坐标")?, number(&f["y"], "字段纵坐标")?, number(&f["width"], "字段宽度")?, number(&f["height"], "字段高度")?); - if x < 0.0 || y < 0.0 || w <= 0.0 || h <= 0.0 || x + w > width as f64 + 0.01 || y + h > height as f64 + 0.01 { + if native_xiaoyi && (w <= 0.0 || h <= 0.0) { + return Err("模板字段尺寸无效".into()); + } + if !native_xiaoyi && (x < 0.0 || y < 0.0 || w <= 0.0 || h <= 0.0 + || x + w > width as f64 + 0.01 || y + h > height as f64 + 0.01) { return Err("模板字段超出画布,请先明确裁切范围".into()); } match slot["kind"].as_str() { @@ -660,6 +666,20 @@ mod tests { assert!(validate_pack(&p).unwrap_err().contains("版本身份")); } #[test] + fn xiaoyi_native_template_keeps_out_of_canvas_frames() { + let mut p = pack(); + p["enterprise"] = json!({"sourceKind":"xiaoyi-release","snapshotVersion":p["version"], + "manifestRevision":"c".repeat(64),"originalSha256":"d".repeat(64)}); + p["outputs"][0]["slots"][0]["frame"]["x"] = json!(-20); + p["outputs"][0]["slots"][0]["frame"]["width"] = json!(1500); + p["contentHash"] = json!(pack_hash(&p).unwrap()); + validate_pack(&p).unwrap(); + + p["outputs"][0]["slots"][0]["frame"]["width"] = json!(0); + p["contentHash"] = json!(pack_hash(&p).unwrap()); + assert_eq!(validate_pack(&p).unwrap_err(), "模板字段尺寸无效"); + } + #[test] fn shipped_gujia_pack_preserves_distinct_outputs_and_explicit_reuse() { let p: Value = serde_json::from_str(include_str!("../../../../../lib/desktop-client/template-packs/gj-desk-dnz0385-native-v1.json")).unwrap(); validate_pack(&p).unwrap();