fix: resolve {vars} in endpoint test button using saved params config
Fixed vars use their preset (month_start, current_date, etc.); ask-mode vars fall back to today's date so the test always sends a valid URL. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
ff9ff67445
commit
e177919be2
@@ -1960,6 +1960,33 @@ HTML;
|
|||||||
|
|
||||||
if ($url === '') { echo json_encode(['ok' => false, 'error' => 'URL vacía']); exit; }
|
if ($url === '') { echo json_encode(['ok' => false, 'error' => 'URL vacía']); exit; }
|
||||||
|
|
||||||
|
// Resolve {var} placeholders using params config
|
||||||
|
$stmt = db()->prepare("SELECT params FROM company_endpoints WHERE company_id=? AND endpoint_key=?");
|
||||||
|
$stmt->execute([$companyId, $key]);
|
||||||
|
$paramsJson = $stmt->fetchColumn();
|
||||||
|
$varConfigs = is_string($paramsJson) ? (json_decode($paramsJson, true) ?? []) : [];
|
||||||
|
$presets = [
|
||||||
|
'current_date' => date('Y-m-d'),
|
||||||
|
'month_start' => date('Y-m-01'),
|
||||||
|
'month_end' => date('Y-m-t'),
|
||||||
|
'last_7_start' => date('Y-m-d', strtotime('-7 days')),
|
||||||
|
'last_30_start' => date('Y-m-d', strtotime('-30 days')),
|
||||||
|
'year_start' => date('Y-01-01'),
|
||||||
|
];
|
||||||
|
foreach ($varConfigs as $cfg) {
|
||||||
|
$k = $cfg['key'] ?? '';
|
||||||
|
if (!$k) continue;
|
||||||
|
if (($cfg['mode'] ?? '') === 'fixed') {
|
||||||
|
$val = $cfg['value'] ?? 'current_date';
|
||||||
|
$url = str_replace('{' . $k . '}', $presets[$val] ?? $val, $url);
|
||||||
|
} else {
|
||||||
|
// ponytail: ask-mode vars get today as test default
|
||||||
|
$url = str_replace('{' . $k . '}', date('Y-m-d'), $url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Replace any remaining unresolved {vars} with today
|
||||||
|
$url = preg_replace('/\{[^}]+\}/', date('Y-m-d'), $url);
|
||||||
|
|
||||||
$company = CompanyRepository::findById($companyId);
|
$company = CompanyRepository::findById($companyId);
|
||||||
$apiKey = $company['api_key'] ?? '';
|
$apiKey = $company['api_key'] ?? '';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user