feat(htyproc): IMAGE_FORM_COMPRESS task posts form_image_compress_audit to ai-api
Made-with: Cursor
This commit is contained in:
@@ -247,6 +247,9 @@ async fn run_one(
|
|||||||
TaskType::VideoCompression => {
|
TaskType::VideoCompression => {
|
||||||
tasks::run_video_compression_task(rt, sudo, host, &mut req).await
|
tasks::run_video_compression_task(rt, sudo, host, &mut req).await
|
||||||
}
|
}
|
||||||
|
TaskType::ImageFormCompress => {
|
||||||
|
tasks::run_image_form_compress_task(rt, sudo, host, &mut req).await
|
||||||
|
}
|
||||||
TaskType::Noop | TaskType::TestUpyunRemove => Ok(()),
|
TaskType::Noop | TaskType::TestUpyunRemove => Ok(()),
|
||||||
};
|
};
|
||||||
match &res {
|
match &res {
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
mod pipelines;
|
mod pipelines;
|
||||||
|
|
||||||
pub use pipelines::{
|
pub use pipelines::{
|
||||||
run_ai_score_task, run_audio_file_ai_score_task, run_video_compression_task, run_watermark_task,
|
run_ai_score_task, run_audio_file_ai_score_task, run_image_form_compress_task,
|
||||||
|
run_video_compression_task, run_watermark_task,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,6 +39,46 @@ pub async fn run_ai_score_task(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `IMAGE_FORM_COMPRESS`:压缩直传已在 ngx 完成;此处仅向 ai-api 登记 URL(日志/后续扩展),不重跑压缩。
|
||||||
|
pub async fn run_image_form_compress_task(
|
||||||
|
rt: &Arc<ProcessorRuntime>,
|
||||||
|
sudo: &str,
|
||||||
|
host: &str,
|
||||||
|
req: &mut ReqTask,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let ts_tid = req.task_id.as_deref().unwrap_or("");
|
||||||
|
let raw = req
|
||||||
|
.payload
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("missing payload"))?;
|
||||||
|
let public_url = raw
|
||||||
|
.get("url")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("IMAGE_FORM_COMPRESS: missing payload.url"))?;
|
||||||
|
let hint: String = public_url.chars().take(120).collect();
|
||||||
|
let base = rt.ai_url.trim_end_matches('/');
|
||||||
|
let url = format!("{base}/api/v1/ai/form_image_compress_audit");
|
||||||
|
tracing::debug!(
|
||||||
|
ts_task_id = %ts_tid,
|
||||||
|
endpoint = %url,
|
||||||
|
url_prefix = %hint,
|
||||||
|
"IMAGE_FORM_COMPRESS: POST ai-api audit",
|
||||||
|
);
|
||||||
|
let body = json!({ "url": public_url });
|
||||||
|
let resp = rt
|
||||||
|
.http
|
||||||
|
.post(&url)
|
||||||
|
.header("HtySudoerToken", sudo)
|
||||||
|
.header("HtyHost", host)
|
||||||
|
.json(&body)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
parse_hty_response(resp).await?;
|
||||||
|
tracing::debug!(ts_task_id = %ts_tid, "IMAGE_FORM_COMPRESS: ai-api audit ok");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn run_watermark_task(
|
pub async fn run_watermark_task(
|
||||||
rt: &Arc<ProcessorRuntime>,
|
rt: &Arc<ProcessorRuntime>,
|
||||||
sudo: &str,
|
sudo: &str,
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ pub enum TaskType {
|
|||||||
AudioFileAiScore,
|
AudioFileAiScore,
|
||||||
Watermark,
|
Watermark,
|
||||||
VideoCompression,
|
VideoCompression,
|
||||||
|
/// 机构首页等经 OpenResty `form_upload_to_compress` 已落又拍后的登记任务;载荷见 `payload.url`。
|
||||||
|
ImageFormCompress,
|
||||||
TestUpyunRemove,
|
TestUpyunRemove,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ impl FromStr for TaskType {
|
|||||||
"AUDIO_FILE_AI_SCORE" => Ok(Self::AudioFileAiScore),
|
"AUDIO_FILE_AI_SCORE" => Ok(Self::AudioFileAiScore),
|
||||||
"WATERMARK" => Ok(Self::Watermark),
|
"WATERMARK" => Ok(Self::Watermark),
|
||||||
"VIDEO_COMPRESSION" => Ok(Self::VideoCompression),
|
"VIDEO_COMPRESSION" => Ok(Self::VideoCompression),
|
||||||
|
"IMAGE_FORM_COMPRESS" => Ok(Self::ImageFormCompress),
|
||||||
"TEST_UPYUN_REMOVE" => Ok(Self::TestUpyunRemove),
|
"TEST_UPYUN_REMOVE" => Ok(Self::TestUpyunRemove),
|
||||||
_ => Err(format!("unknown TaskType: {s}")),
|
_ => Err(format!("unknown TaskType: {s}")),
|
||||||
}
|
}
|
||||||
@@ -45,6 +48,7 @@ impl TaskType {
|
|||||||
Self::AudioFileAiScore => "AUDIO_FILE_AI_SCORE",
|
Self::AudioFileAiScore => "AUDIO_FILE_AI_SCORE",
|
||||||
Self::Watermark => "WATERMARK",
|
Self::Watermark => "WATERMARK",
|
||||||
Self::VideoCompression => "VIDEO_COMPRESSION",
|
Self::VideoCompression => "VIDEO_COMPRESSION",
|
||||||
|
Self::ImageFormCompress => "IMAGE_FORM_COMPRESS",
|
||||||
Self::TestUpyunRemove => "TEST_UPYUN_REMOVE",
|
Self::TestUpyunRemove => "TEST_UPYUN_REMOVE",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user