Tłumaczenia - poprawki.
This commit is contained in:
+9
-21
@@ -31,30 +31,18 @@ if ($lang === '' || !isset($languages[$lang])) {
|
||||
|
||||
$langConfig = $languages[$lang];
|
||||
$source = (string) ($langConfig['source'] ?? 'upstream');
|
||||
$ttl = max(60, (int) ($config['ttl_seconds'] ?? 86400));
|
||||
$timeout = max(3, (int) ($config['timeout_seconds'] ?? 12));
|
||||
$cacheFile = menuCachePath($lang);
|
||||
|
||||
$cached = readMenuCache($cacheFile);
|
||||
$now = time();
|
||||
$cachedAtTs = 0;
|
||||
if ($cached && !empty($cached['cachedAt'])) {
|
||||
$cachedAtTs = strtotime((string) $cached['cachedAt']) ?: 0;
|
||||
}
|
||||
$isFresh = $cached && $cachedAtTs > 0 && ($now - $cachedAtTs) < $ttl;
|
||||
|
||||
if ($isFresh) {
|
||||
// Cache odświeżamy tylko ręcznie (panel admina / skrypt CLI) — nie fetchujemy upstreamu przy każdym TTL.
|
||||
if ($cached) {
|
||||
echo json_encode($cached, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($source === 'ai') {
|
||||
if ($cached) {
|
||||
// Stary AI-cache jest OK dłużej niż TTL — cron i tak odświeża raz/dzień.
|
||||
echo json_encode($cached, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
$from = strtolower((string) ($langConfig['from'] ?? 'pl'));
|
||||
$fallback = readMenuCache(menuCachePath($from));
|
||||
if ($fallback) {
|
||||
@@ -67,7 +55,7 @@ if ($source === 'ai') {
|
||||
http_response_code(503);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'AI menu not available yet — run scripts/refresh_menu_cache.php',
|
||||
'message' => 'AI menu not available yet — uruchom: php scripts/refresh_menu_cache.php --force-ai',
|
||||
'lang' => $lang,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
@@ -78,20 +66,20 @@ $url = $base . '/' . rawurlencode($lang);
|
||||
$raw = fetchUpstreamMenu($url, $timeout);
|
||||
|
||||
if ($raw === null) {
|
||||
if ($cached) {
|
||||
echo json_encode($cached, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
http_response_code(502);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to fetch menu',
|
||||
'message' => 'Failed to fetch menu (brak cache — uruchom odświeżenie w panelu)',
|
||||
'lang' => $lang,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$mapped = mapUpstreamMenu($raw, $lang, 'upstream');
|
||||
writeMenuCache($cacheFile, $mapped);
|
||||
try {
|
||||
writeMenuCache($cacheFile, $mapped);
|
||||
} catch (Throwable $e) {
|
||||
// Serwuj świeże dane nawet gdy cache nie da się zapisać
|
||||
}
|
||||
|
||||
echo json_encode($mapped, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
Reference in New Issue
Block a user