fix: use internal URL for AI HTTP tools
Prefer IA_WEB_INTERNAL_URL or local HOST for AI tool requests while preserving public page links for users.
This commit is contained in:
@@ -196,8 +196,7 @@ fn validate_endpoint_id(value: &str) -> anyhow::Result<String> {
|
||||
|
||||
fn api_docs_base_url() -> String {
|
||||
std::env::var("IA_API_DOCS_BASE_URL")
|
||||
.or_else(|_| std::env::var("IA_WEB_BASE_URL"))
|
||||
.or_else(|_| std::env::var("WEB_BASE_URL"))
|
||||
.or_else(|_| std::env::var("IA_WEB_INTERNAL_URL"))
|
||||
.or_else(|_| std::env::var("HOST").map(|host| format!("http://{host}")))
|
||||
.unwrap_or_else(|_| "http://127.0.0.1:9003".to_string())
|
||||
.trim()
|
||||
|
||||
+13
-4
@@ -129,7 +129,7 @@ async fn create_markdown_preview_inner(arguments: &str) -> anyhow::Result<String
|
||||
}
|
||||
|
||||
async fn create_page_request(payload: Value) -> anyhow::Result<String> {
|
||||
let base_url = web_base_url();
|
||||
let base_url = web_request_base_url();
|
||||
let endpoint = format!("{base_url}/v1/web/pages");
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
@@ -184,7 +184,7 @@ async fn query_web_pages_inner(arguments: &str) -> anyhow::Result<String> {
|
||||
let page = args.page.unwrap_or(1).max(1);
|
||||
let per_page = args.per_page.unwrap_or(10).clamp(1, 20);
|
||||
|
||||
let mut url = reqwest::Url::parse(&format!("{}/v1/web/pages", web_base_url()))
|
||||
let mut url = reqwest::Url::parse(&format!("{}/v1/web/pages", web_request_base_url()))
|
||||
.context("构造 web 页面查询地址失败")?;
|
||||
{
|
||||
let mut query_pairs = url.query_pairs_mut();
|
||||
@@ -266,7 +266,7 @@ fn web_page_url(page: &WebPageItem) -> String {
|
||||
} else {
|
||||
format!("/web/{}/{}", page.page_type, page.slug)
|
||||
};
|
||||
format!("{}{}", web_base_url(), path)
|
||||
format!("{}{}", web_public_base_url(), path)
|
||||
}
|
||||
|
||||
fn optional_text(value: Option<String>) -> Option<String> {
|
||||
@@ -275,7 +275,16 @@ fn optional_text(value: Option<String>) -> Option<String> {
|
||||
.filter(|value| !value.is_empty())
|
||||
}
|
||||
|
||||
fn web_base_url() -> String {
|
||||
fn web_request_base_url() -> String {
|
||||
std::env::var("IA_WEB_INTERNAL_URL")
|
||||
.or_else(|_| std::env::var("HOST").map(|host| format!("http://{host}")))
|
||||
.unwrap_or_else(|_| "http://127.0.0.1:9003".to_string())
|
||||
.trim()
|
||||
.trim_end_matches('/')
|
||||
.replace("0.0.0.0", "127.0.0.1")
|
||||
}
|
||||
|
||||
fn web_public_base_url() -> String {
|
||||
std::env::var("IA_WEB_BASE_URL")
|
||||
.or_else(|_| std::env::var("WEB_BASE_URL"))
|
||||
.or_else(|_| std::env::var("HOST").map(|host| format!("http://{host}")))
|
||||
|
||||
Reference in New Issue
Block a user