清理Tripo3D新代码的死代码与无意义断言
- 删除 job.rs 中无调用的 is_model3d_job_kind、source_entity_id 与本地 target_source_entity_id - 删除 artifacts.rs 中未被引用的 map_artifact_error 及其 TripoError 导入 - 删除未被引用的 MODEL3D_JOB_MAX_ATTEMPTS 与只被同文件测试断言的 queue source module 常量 - 删除对常量自身取值的恒真断言测试
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
//! 把流转交 OSS,不再把几十 MB 的模型完整读进 api-server 内存。
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use platform_tripo::{TripoDownloadedArtifact, TripoError};
|
||||
use platform_tripo::TripoDownloadedArtifact;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::http_error::AppError;
|
||||
@@ -57,8 +57,3 @@ fn artifact_too_large(actual_bytes: u64) -> AppError {
|
||||
"maxBytes": MODEL3D_MAX_ARTIFACT_BYTES,
|
||||
}))
|
||||
}
|
||||
|
||||
/// provider 错误在 artifacts 层与其它层使用同一份映射,避免两处口径分叉。
|
||||
pub(crate) fn map_artifact_error(error: TripoError) -> AppError {
|
||||
map_provider_error(error)
|
||||
}
|
||||
|
||||
@@ -8,20 +8,9 @@ use shared_contracts::model3d::common::Model3dGenerationTarget;
|
||||
use shared_contracts::model3d::image_to_model::Model3dImageToModelRequest;
|
||||
use shared_contracts::model3d::text_to_model::Model3dTextToModelRequest;
|
||||
|
||||
use super::pricing::Model3dEndpoint;
|
||||
|
||||
pub(crate) const MODEL3D_TEXT_TO_MODEL_JOB_KIND: &str = "model3d_text_to_model";
|
||||
pub(crate) const MODEL3D_IMAGE_TO_MODEL_JOB_KIND: &str = "model3d_image_to_model";
|
||||
|
||||
/// Tripo submit 无法幂等重放:任何 attempt 失败都必须终态收口,所以固定单次尝试。
|
||||
///
|
||||
/// 崩溃后租约到期也按 attempt 耗尽结算为失败并冲正扣费,不存在“重新 claim 再 submit 一次”
|
||||
/// 的窗口;checkpoint 只用于对账与防御性地拒绝二次 submit。
|
||||
pub(crate) const MODEL3D_JOB_MAX_ATTEMPTS: u32 = 1;
|
||||
|
||||
/// 复用编辑器生成队列的 source module:现有 worker claim 只接受这一来源,本能力不自造队列。
|
||||
pub(crate) const MODEL3D_JOB_SOURCE_MODULE: &str = "editor-canvas";
|
||||
|
||||
/// checkpoint 的 provider 标识;不含 provider task id,只说明 checkpoint 来自哪个 provider。
|
||||
pub(crate) const MODEL3D_PROVIDER_KIND: &str = "tripo";
|
||||
|
||||
@@ -47,13 +36,6 @@ impl Model3dJobKind {
|
||||
.find(|kind| kind.as_str() == job_kind.trim())
|
||||
}
|
||||
|
||||
pub(crate) const fn endpoint(self) -> Model3dEndpoint {
|
||||
match self {
|
||||
Self::TextToModel => Model3dEndpoint::TextToModel,
|
||||
Self::ImageToModel => Model3dEndpoint::ImageToModel,
|
||||
}
|
||||
}
|
||||
|
||||
/// 任务列表里对用户可见的阶段名;provider 与实际模型档位不出现在这里。
|
||||
pub(crate) const fn request_label(self) -> &'static str {
|
||||
match self {
|
||||
@@ -63,10 +45,6 @@ impl Model3dJobKind {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_model3d_job_kind(job_kind: &str) -> bool {
|
||||
Model3dJobKind::from_job_kind(job_kind).is_some()
|
||||
}
|
||||
|
||||
/// 队列里保存的请求:就是 API 请求本身,不含任何平台执行中间态。
|
||||
///
|
||||
/// provider task id 属于 checkpoint 字段,不写入请求 payload,因此不参与请求指纹。
|
||||
@@ -106,33 +84,10 @@ impl Model3dJobRequest {
|
||||
Self::ImageToModel(request) => request.generation.model.as_str(),
|
||||
}
|
||||
}
|
||||
|
||||
/// 任务审计用的来源实体:项目落点用项目 ID,素材库落点用目录 ID。
|
||||
pub(crate) fn source_entity_id(&self) -> String {
|
||||
match self {
|
||||
Self::TextToModel(request) => target_source_entity_id(&request.target),
|
||||
Self::ImageToModel(request) => target_source_entity_id(&request.target),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const MODEL3D_IMAGE_TO_MODEL_AUDIT_PROMPT: &str = "图生 3D 模型";
|
||||
|
||||
fn target_source_entity_id(
|
||||
target: &shared_contracts::model3d::common::Model3dGenerationTarget,
|
||||
) -> String {
|
||||
match target {
|
||||
shared_contracts::model3d::common::Model3dGenerationTarget::ProjectResource {
|
||||
project_id,
|
||||
..
|
||||
} => project_id.trim().to_string(),
|
||||
shared_contracts::model3d::common::Model3dGenerationTarget::AssetLibrary {
|
||||
folder_id,
|
||||
..
|
||||
} => folder_id.trim().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// 从队列 payload 还原请求。
|
||||
///
|
||||
/// 队列 payload 比 API 请求多一个幂等指纹字段,且请求类型是 `deny_unknown_fields`;
|
||||
@@ -197,7 +152,6 @@ mod tests {
|
||||
parse_model3d_job_request(MODEL3D_TEXT_TO_MODEL_JOB_KIND, &payload).expect("应可解析");
|
||||
|
||||
assert_eq!(request.job_kind(), Model3dJobKind::TextToModel);
|
||||
assert_eq!(request.source_entity_id(), "project-1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
state::AppState,
|
||||
};
|
||||
|
||||
use super::job::{MODEL3D_JOB_SOURCE_MODULE, Model3dJobKind};
|
||||
use super::job::Model3dJobKind;
|
||||
|
||||
/// 3D 生成自己的幂等命名空间,避免与图片 / 视频生成共用 dedupe key。
|
||||
const MODEL3D_GENERATION_DEDUPE_PREFIX: &str = "model3d-generation";
|
||||
@@ -80,9 +80,6 @@ where
|
||||
.await
|
||||
}
|
||||
|
||||
/// 队列来源模块必须是既有编辑器生成队列;worker claim 只认这一来源。
|
||||
pub(crate) const MODEL3D_QUEUE_SOURCE_MODULE: &str = MODEL3D_JOB_SOURCE_MODULE;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -94,9 +91,4 @@ mod tests {
|
||||
"/api/runtime/external-generation/jobs/task-1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn queue_source_module_stays_on_editor_generation_queue() {
|
||||
assert_eq!(MODEL3D_QUEUE_SOURCE_MODULE, "editor-canvas");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user