fix: 收窄创作入口关闭熔断范围
This commit is contained in:
@@ -34,7 +34,7 @@ pub async fn get_creation_entry_config_handler(
|
||||
Ok(json_success_body(Some(&request_context), config))
|
||||
}
|
||||
|
||||
/// 中文注释:api-server 路由熔断只拦创作/运行态 API 请求,不改变前端入口展示规则。
|
||||
/// 中文注释:api-server 路由熔断只拦新建创作入口,不限制已有作品读取、发布作品游玩或公开广场浏览。
|
||||
pub async fn require_creation_entry_route_enabled(
|
||||
State(state): State<AppState>,
|
||||
request: Request<Body>,
|
||||
@@ -72,54 +72,56 @@ pub async fn require_creation_entry_route_enabled(
|
||||
|
||||
pub fn resolve_creation_entry_route_id(path: &str) -> Option<&'static str> {
|
||||
let normalized = path.trim_end_matches('/');
|
||||
if normalized.starts_with("/api/runtime/puzzle") {
|
||||
if normalized == "/api/runtime/puzzle/agent/sessions"
|
||||
|| normalized == "/api/runtime/puzzle/onboarding/generate"
|
||||
{
|
||||
return Some("puzzle");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/match3d") {
|
||||
return Some("match3d");
|
||||
if normalized.starts_with("/api/runtime/puzzle/gallery/")
|
||||
&& normalized.ends_with("/remix")
|
||||
{
|
||||
return Some("puzzle");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/bark-battle") {
|
||||
return Some("bark-battle");
|
||||
}
|
||||
if normalized.starts_with("/api/creation/bark-battle") {
|
||||
return Some("bark-battle");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/wooden-fish") {
|
||||
return Some("wooden-fish");
|
||||
}
|
||||
if normalized.starts_with("/api/creation/wooden-fish") {
|
||||
return Some("wooden-fish");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/square-hole") {
|
||||
return Some("square-hole");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/jump-hop") {
|
||||
return Some("jump-hop");
|
||||
}
|
||||
if normalized.starts_with("/api/creation/jump-hop") {
|
||||
return Some("jump-hop");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/big-fish") {
|
||||
if normalized == "/api/runtime/big-fish/agent/sessions" {
|
||||
return Some("big-fish");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/custom-world")
|
||||
|| normalized.starts_with("/api/runtime/custom-world-library")
|
||||
|| normalized.starts_with("/api/runtime/custom-world-gallery")
|
||||
|| normalized.starts_with("/api/runtime/chat")
|
||||
|| normalized.starts_with("/api/story")
|
||||
if normalized.starts_with("/api/runtime/big-fish/gallery/")
|
||||
&& normalized.ends_with("/remix")
|
||||
{
|
||||
return Some("big-fish");
|
||||
}
|
||||
if normalized == "/api/runtime/custom-world/agent/sessions"
|
||||
|| normalized == "/api/runtime/custom-world/profile"
|
||||
{
|
||||
return Some("rpg");
|
||||
}
|
||||
if normalized.starts_with("/api/runtime/visual-novel") {
|
||||
if normalized.starts_with("/api/runtime/custom-world-gallery/")
|
||||
&& normalized.ends_with("/remix")
|
||||
{
|
||||
return Some("rpg");
|
||||
}
|
||||
if normalized == "/api/creation/match3d/sessions" {
|
||||
return Some("match3d");
|
||||
}
|
||||
if normalized == "/api/creation/square-hole/sessions" {
|
||||
return Some("square-hole");
|
||||
}
|
||||
if normalized == "/api/creation/bark-battle/drafts" {
|
||||
return Some("bark-battle");
|
||||
}
|
||||
if normalized == "/api/creation/wooden-fish/sessions" {
|
||||
return Some("wooden-fish");
|
||||
}
|
||||
if normalized == "/api/creation/jump-hop/sessions" {
|
||||
return Some("jump-hop");
|
||||
}
|
||||
if normalized == "/api/creation/visual-novel/sessions" {
|
||||
return Some("visual-novel");
|
||||
}
|
||||
if normalized.starts_with("/api/creation/visual-novel") {
|
||||
return Some("visual-novel");
|
||||
}
|
||||
if normalized.starts_with("/api/creation/edutainment/baby-object-match") {
|
||||
if normalized == "/api/creation/edutainment/baby-object-match/assets" {
|
||||
return Some("baby-object-match");
|
||||
}
|
||||
if normalized.starts_with("/api/creation/edutainment/baby-love-drawing") {
|
||||
if normalized == "/api/creation/edutainment/baby-love-drawing/magic" {
|
||||
return Some("baby-love-drawing");
|
||||
}
|
||||
None
|
||||
@@ -171,58 +173,68 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn resolves_runtime_paths_to_creation_type_ids() {
|
||||
fn resolves_new_creation_paths_to_creation_type_ids() {
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/puzzle/works"),
|
||||
resolve_creation_entry_route_id("/api/runtime/puzzle/agent/sessions"),
|
||||
Some("puzzle"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/match3d/runs/run-1"),
|
||||
resolve_creation_entry_route_id("/api/runtime/puzzle/gallery/profile-1/remix"),
|
||||
Some("puzzle"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/creation/match3d/sessions"),
|
||||
Some("match3d"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/square-hole/runs/run-1"),
|
||||
resolve_creation_entry_route_id("/api/creation/square-hole/sessions"),
|
||||
Some("square-hole"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/visual-novel/works"),
|
||||
Some("visual-novel"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/creation/visual-novel/sessions"),
|
||||
Some("visual-novel"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/big-fish/agent/sessions"),
|
||||
Some("big-fish"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/custom-world/agent/sessions"),
|
||||
Some("rpg"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/custom-world-library/profile-1"),
|
||||
resolve_creation_entry_route_id(
|
||||
"/api/runtime/custom-world-gallery/user-1/profile-1/remix"
|
||||
),
|
||||
Some("rpg"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/custom-world-library/profile-1"),
|
||||
None,
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/custom-world-gallery/user-1/profile-1"),
|
||||
Some("rpg"),
|
||||
None,
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/story/sessions/runtime"),
|
||||
Some("rpg"),
|
||||
None,
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/chat/npc/turn/stream"),
|
||||
Some("rpg"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/bark-battle/works/work-1/config"),
|
||||
Some("bark-battle"),
|
||||
None,
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/creation/bark-battle/drafts"),
|
||||
Some("bark-battle"),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/bark-battle/works/work-1/config"),
|
||||
None,
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/runtime/wooden-fish/runs/run-1"),
|
||||
Some("wooden-fish"),
|
||||
None,
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_creation_entry_route_id("/api/creation/wooden-fish/sessions"),
|
||||
|
||||
Reference in New Issue
Block a user