From b83113619e2ccf62ae1083ddf491eacdbc92d084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Thu, 24 Sep 2026 18:00:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E7=89=A9=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E6=B4=BE=E7=94=9F=20Debug=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E6=88=90=E5=8F=AA=E6=89=93=E5=85=83=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - server-rs/crates/platform-tripo/src/common/types.rs:TripoArtifactBytes 去掉 derive(Debug),改为手写实现,只输出 url / content_type / content_length / 字节数,几十 MB 的 bytes 不会再被一次 {:?} 刷进日志 - server-rs/crates/platform-tripo/src/common/types.rs:补用例锁住 Debug 只带字节数、不带字节内容 --- .../crates/platform-tripo/src/common/types.rs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/server-rs/crates/platform-tripo/src/common/types.rs b/server-rs/crates/platform-tripo/src/common/types.rs index a2cc19745..a1ea065e0 100644 --- a/server-rs/crates/platform-tripo/src/common/types.rs +++ b/server-rs/crates/platform-tripo/src/common/types.rs @@ -155,7 +155,6 @@ pub(crate) struct TripoDownloadedArtifact { /// 与 [`TripoDownloadedArtifact`] 的区别是「读完了」:body 中途失败会被下载入口整体重下, /// 因此拿到这个值就代表这次读取是完整的。(几十 MB 的产物当前一次性读进内存,api-server /// 侧同样如此;未来接 OSS 流式 / 分片上传时再回到流式句柄。) -#[derive(Debug)] pub struct TripoArtifactBytes { pub url: TripoUrl, pub content_type: Option, @@ -164,6 +163,19 @@ pub struct TripoArtifactBytes { pub bytes: Vec, } +impl fmt::Debug for TripoArtifactBytes { + /// 只打印元数据与字节数:`bytes` 是几十 MB 级的产物,派生的 `Debug` 会把每个字节 + /// 写成十进制文本,一次 `{artifact:?}` 就能刷出几百 MB 日志。 + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("TripoArtifactBytes") + .field("url", &self.url) + .field("content_type", &self.content_type) + .field("content_length", &self.content_length) + .field("bytes_len", &self.bytes.len()) + .finish() + } +} + impl TripoDownloadedArtifact { pub(crate) fn new( task_id: String, @@ -378,4 +390,18 @@ mod tests { "artifact.glb" ); } + + #[test] + fn artifact_debug_reports_metadata_instead_of_the_payload() { + let artifact = TripoArtifactBytes { + url: artifact_url("/a.glb"), + content_type: Some("model/gltf-binary".to_string()), + content_length: Some(8), + bytes: vec![171; 8], + }; + + let debug = format!("{artifact:?}"); + assert!(debug.contains("bytes_len: 8"), "{debug}"); + assert!(!debug.contains("171"), "产物字节不能进 Debug 输出:{debug}"); + } }