fix(generator): use endpoint.url directly in buildRequest to fix URL construction bug

The previous implementation used `new URL(endpoint.url, window.location.origin)`
which incorrectly constructed URLs based on the current page's origin. This broke
when endpoint URLs were already complete URLs (e.g., http://20.76.57.61:18080/...).

The fix uses endpoint.url directly since LLM extraction already provides complete
URLs. Also changed from GET with query params to POST with JSON body to match
typical API expectations.

🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
木炎
2026-04-17 11:34:16 +08:00
parent 4167639231
commit b8d2eb9faa

View File

@@ -306,18 +306,12 @@ function validateArgs(args) {{
}}
function buildRequest(args, endpoint) {{
const url = new URL(endpoint.url, window.location.origin);
const params = {{ ...STATIC_PARAMS, ...args }};
for (const [key, value] of Object.entries(params)) {{
if (value !== undefined && value !== null) {{
url.searchParams.set(key, String(value));
}}
}}
return {{
url: url.toString(),
method: endpoint.method || 'GET',
headers: {{ 'Content-Type': 'application/json' }}
}};
// Use endpoint.url directly - it's already a complete URL
const url = endpoint.url;
const method = endpoint.method || 'POST';
const headers = {{ 'Content-Type': 'application/json' }};
const body = JSON.stringify({{ ...STATIC_PARAMS, ...args }});
return {{ url, method, headers, body }};
}}
function normalizeRows(rawData) {{
@@ -360,7 +354,8 @@ const defaultDeps = {{
const request = buildRequest(args, endpoint);
const response = await fetch(request.url, {{
method: request.method,
headers: request.headers
headers: request.headers,
body: request.body
}});
if (!response.ok) throw new Error(`HTTP ${{response.status}}: ${{response.statusText}}`);
return response.json();