diff --git a/server-rs/crates/platform-tripo/src/common/types.rs b/server-rs/crates/platform-tripo/src/common/types.rs index 0600e6d36..00326cc7d 100644 --- a/server-rs/crates/platform-tripo/src/common/types.rs +++ b/server-rs/crates/platform-tripo/src/common/types.rs @@ -293,6 +293,10 @@ fn fallback_artifact_extension(content_type: Option<&str>) -> &'static str { "png" } else if content_type.starts_with("image/jpeg") { "jpg" + } else if content_type.starts_with("image/jpg") { + // `image/jpg` 不是标准写法,但确有 provider 这么回;落到默认 `.glb` 会让一张 + // 预览图带上模型后缀,这里按声明值给回 jpg。 + "jpg" } else if content_type.starts_with("image/webp") { "webp" } else { @@ -341,6 +345,27 @@ mod tests { assert!(!stem.contains('.'), "`..` 必须被中性化:{stem}"); } + #[test] + fn fallback_extension_follows_the_declared_image_content_type() { + assert_eq!( + artifact_filename("preview", Some("image/png"), &artifact_url("/artifact")), + "preview.png" + ); + assert_eq!( + artifact_filename("preview", Some("image/jpg"), &artifact_url("/artifact")), + "preview.jpg" + ); + assert_eq!( + artifact_filename("preview", Some("image/webp"), &artifact_url("/artifact")), + "preview.webp" + ); + // 读不出形态时仍按模型产物兜底。 + assert_eq!( + artifact_filename("model", None, &artifact_url("/artifact")), + "model.glb" + ); + } + #[test] fn blank_stem_falls_back_to_a_fixed_name() { assert_eq!(