产物结构体不再派生 Debug,改成只打元数据

- 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 只带字节数、不带字节内容
This commit is contained in:
2026-09-24 18:00:45 +08:00
parent 03aec35350
commit b83113619e
@@ -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<String>,
@@ -164,6 +163,19 @@ pub struct TripoArtifactBytes {
pub bytes: Vec<u8>,
}
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}");
}
}