补齐创作生成订阅消息通知
订阅消息任务名称改为玩法模板名。 拼图、敲木鱼、抓大鹅、跳一跳、方洞、视觉小说在草稿生成成功或失败终态发送通知。 订阅消息泥点字段按本次生成结算后的实际扣除展示,失败退款后显示0。 更新微信订阅消息运维和支付方案文档口径。
This commit is contained in:
@@ -43,6 +43,10 @@ use crate::{
|
||||
platform_errors::map_oss_error,
|
||||
request_context::RequestContext,
|
||||
state::AppState,
|
||||
wechat_subscribe_message::{
|
||||
GenerationResultSubscribeMessage, GenerationResultSubscribeMessageStatus,
|
||||
send_generation_result_subscribe_message_after_completion,
|
||||
},
|
||||
};
|
||||
|
||||
const WOODEN_FISH_PROVIDER: &str = "wooden-fish";
|
||||
@@ -147,6 +151,15 @@ pub async fn execute_wooden_fish_action(
|
||||
wooden_fish_json(payload, &request_context, WOODEN_FISH_CREATION_PROVIDER)?;
|
||||
let owner_user_id = authenticated.claims().user_id().to_string();
|
||||
let author_display_name = resolve_author_display_name(&state, &authenticated);
|
||||
let is_compile_draft = matches!(
|
||||
payload.action_type,
|
||||
shared_contracts::wooden_fish::WoodenFishActionType::CompileDraft
|
||||
);
|
||||
let generation_points_cost = if is_compile_draft {
|
||||
resolve_wooden_fish_generation_points_cost(&state).await
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let result = execute_wooden_fish_action_with_generated_assets(
|
||||
&state,
|
||||
&request_context,
|
||||
@@ -160,21 +173,55 @@ pub async fn execute_wooden_fish_action(
|
||||
.as_ref()
|
||||
.err()
|
||||
.is_some_and(|response| response.status().is_server_error())
|
||||
&& matches!(
|
||||
payload.action_type,
|
||||
shared_contracts::wooden_fish::WoodenFishActionType::CompileDraft
|
||||
)
|
||||
&& is_compile_draft
|
||||
{
|
||||
mark_wooden_fish_generation_failed(
|
||||
let failed_at_micros = current_utc_micros();
|
||||
let work_name =
|
||||
resolve_wooden_fish_notification_work_name(&state, &session_id, &owner_user_id).await;
|
||||
if mark_wooden_fish_generation_failed(
|
||||
&state,
|
||||
&request_context,
|
||||
&session_id,
|
||||
owner_user_id.as_str(),
|
||||
author_display_name.as_str(),
|
||||
)
|
||||
.await;
|
||||
.await
|
||||
{
|
||||
send_generation_result_subscribe_message_after_completion(
|
||||
&state,
|
||||
GenerationResultSubscribeMessage {
|
||||
owner_user_id: owner_user_id.clone(),
|
||||
task_name: Some(WOODEN_FISH_TEMPLATE_NAME.to_string()),
|
||||
work_name,
|
||||
status: GenerationResultSubscribeMessageStatus::Failed,
|
||||
consumed_points: 0,
|
||||
completed_at_micros: failed_at_micros,
|
||||
page: Some("/pages/web-view/index".to_string()),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
let response = result?;
|
||||
if is_compile_draft && response.session.status == WoodenFishGenerationStatus::Ready {
|
||||
send_generation_result_subscribe_message_after_completion(
|
||||
&state,
|
||||
GenerationResultSubscribeMessage {
|
||||
owner_user_id,
|
||||
task_name: Some(WOODEN_FISH_TEMPLATE_NAME.to_string()),
|
||||
work_name: response
|
||||
.session
|
||||
.draft
|
||||
.as_ref()
|
||||
.map(|draft| draft.work_title.clone()),
|
||||
status: GenerationResultSubscribeMessageStatus::Succeeded,
|
||||
consumed_points: generation_points_cost,
|
||||
completed_at_micros: current_utc_micros(),
|
||||
page: Some("/pages/web-view/index".to_string()),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
Ok(json_success_body(Some(&request_context), response))
|
||||
}
|
||||
@@ -588,13 +635,37 @@ async fn execute_wooden_fish_action_with_generated_assets(
|
||||
})
|
||||
}
|
||||
|
||||
async fn resolve_wooden_fish_generation_points_cost(state: &AppState) -> u64 {
|
||||
crate::creation_entry_config::resolve_creation_entry_mud_point_cost(
|
||||
state,
|
||||
WOODEN_FISH_TEMPLATE_ID,
|
||||
u64::from(shared_contracts::creation_entry_config::DEFAULT_UNIFIED_CREATION_MUD_POINT_COST),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn resolve_wooden_fish_notification_work_name(
|
||||
state: &AppState,
|
||||
session_id: &str,
|
||||
owner_user_id: &str,
|
||||
) -> Option<String> {
|
||||
state
|
||||
.spacetime_client()
|
||||
.get_wooden_fish_session(session_id.to_string(), owner_user_id.to_string())
|
||||
.await
|
||||
.ok()
|
||||
.and_then(|session| session.draft)
|
||||
.map(|draft| draft.work_title)
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
}
|
||||
|
||||
async fn mark_wooden_fish_generation_failed(
|
||||
state: &AppState,
|
||||
request_context: &RequestContext,
|
||||
session_id: &str,
|
||||
owner_user_id: &str,
|
||||
author_display_name: &str,
|
||||
) {
|
||||
) -> bool {
|
||||
if let Err(error) = state
|
||||
.spacetime_client()
|
||||
.mark_wooden_fish_generation_failed(
|
||||
@@ -612,7 +683,9 @@ async fn mark_wooden_fish_generation_failed(
|
||||
error = %error,
|
||||
"敲木鱼草稿生成失败后的状态回写失败"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn default_wooden_fish_hit_object_asset() -> WoodenFishImageAsset {
|
||||
|
||||
Reference in New Issue
Block a user