3D 冒烟示例把产物写到 target 目录,不再落到仓库里

- server-rs/crates/platform-tripo/examples/tripo_generation_smoke.rs:产物落盘目录从「当前工作目录」改为 <cargo target>/tripo-smoke-artifacts,开始前建目录并打印路径;该目录本来就在入库排除范围内,根目录不会再攒出临时模型
- server-rs/crates/platform-tripo/examples/tripo_generation_smoke.rs:文件头文档同步改为说明新的产物落点
This commit is contained in:
2026-09-24 19:05:51 +08:00
parent 02f334b04a
commit acdfb8ed73
@@ -9,10 +9,12 @@
//! ```
//!
//! The example waits for each submitted task to finish, prints its mapped
//! output, and writes the downloaded model into the current directory. The
//! SDK poller is used only here and is not exposed by `platform-tripo`.
//! output, and writes the downloaded model into
//! `<cargo target dir>/tripo-smoke-artifacts` so a smoke run never leaves
//! tens-of-MB models inside the repository tree. The SDK poller is used only
//! here and is not exposed by `platform-tripo`.
use std::{env, time::Duration};
use std::{env, path::PathBuf, time::Duration};
use platform_tripo::{TripoImageInput, TripoProviderClient};
use shared_contracts::model3d::{
@@ -31,6 +33,14 @@ const SAMPLE_IMAGE_URL: &str = "https://www.rustacean.net/assets/rustacean-flat-
/// 冒烟脚本单次允许的产物体积上限,与 api-server 的口径一致(512 MiB)。
const SMOKE_MAX_ARTIFACT_BYTES: u64 = 512 * 1024 * 1024;
/// 产物落盘目录:固定在 cargo 的 target 目录下(`server-rs/target`),
/// 那里本来就不入库,示例也就不会在仓库里留下几十 MB 的临时模型。
fn artifact_output_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../target")
.join("tripo-smoke-artifacts")
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = required_env("TRIPO_API_KEY")?;
@@ -140,6 +150,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?;
println!("multiview_to_model task_id={}", multiview.task_id);
let output_dir = artifact_output_dir();
tokio::fs::create_dir_all(&output_dir).await?;
println!("artifact output dir={}", output_dir.display());
for (name, handle) in [
("text_to_model", text),
("image_to_model", image),
@@ -198,11 +212,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
};
let filename = artifact.filename(name);
let mut file = File::create(&filename).await?;
let path = output_dir.join(&filename);
let mut file = File::create(&path).await?;
file.write_all(&artifact.bytes).await?;
println!(
"{name} artifact={} bytes={} url={}",
filename,
path.display(),
artifact.bytes.len(),
artifact.url.redacted()
);