ff14-mitigator/api/cache.php
xziino 1a91d1af0e Planer/Analyse: Personal-Mits Knight's Resolve, Nascent Glint, Stem the Flow/Tide, Aquaveil, Exaltation
- api/analysis.php: 6 neue Einträge in MITIGATION_ABILITIES
  Knight's Resolve (PLD, 1002675, 10% DR), Nascent Glint (WAR, 1001858, 10% DR),
  Stem the Flow (WAR, 1002679, 10% DR), Stem the Tide (WAR, 1002680, Shield),
  Aquaveil (WHM, 1002708, 15% DR), Exaltation (AST, 1002717, 10% DR)
- js/ffxiv-data.js: JOB_ABILITIES, ABILITY_JOB_MAP, MITIG_ICONS, ABILITY_DR aktualisiert
- js/planner.js: alle 6 in TIMELINE_PERSONAL_ABILITIES eingetragen
- assets/jsons/Action.json: Recast-Daten für Nascent Flash (25s), Aquaveil (60s),
  Exaltation (60s) ergänzt (Gantt-Balken)
- assets/icons/mitigation/: 6 neue Icons heruntergeladen (XIVAPI Status-Icons)
- api/cache.php: Version v6 -> v8

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 16:22:12 +02:00

53 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
const CACHED_LOG_DIR = __DIR__ . '/../cached_logs';
const CACHED_LOG_VERSION = 'v8';
function cache_language(string $language): string {
$language = strtolower(trim($language));
return in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en';
}
function cache_report_code(string $reportCode): string {
return preg_replace('/[^a-zA-Z0-9]/', '', $reportCode);
}
function cache_key_part(string|int|float|null $value): string {
$value = (string)($value ?? '');
$value = preg_replace('/[^a-zA-Z0-9._-]/', '_', $value);
return trim($value, '_') ?: 'all';
}
function cached_log_path(string $kind, string $reportCode, string $language, array $parts = []): string {
$reportCode = cache_report_code($reportCode);
$language = cache_language($language);
$kind = cache_key_part($kind);
$safeParts = array_map('cache_key_part', $parts);
$suffix = $safeParts ? '_' . implode('_', $safeParts) : '';
return CACHED_LOG_DIR . '/' . CACHED_LOG_VERSION . '/' . $reportCode . '/' . $language . '/' . $kind . $suffix . '.json';
}
function read_cached_log(string $kind, string $reportCode, string $language, array $parts = []): ?string {
$path = cached_log_path($kind, $reportCode, $language, $parts);
if (!is_file($path)) return null;
$body = file_get_contents($path);
if ($body === false || trim($body) === '') return null;
return $body;
}
function write_cached_log(string $kind, string $reportCode, string $language, array $parts, string $body): void {
$decoded = json_decode($body, true);
if (!is_array($decoded) || isset($decoded['error'], $decoded['errors'], $decoded['reauth'])) return;
$path = cached_log_path($kind, $reportCode, $language, $parts);
$dir = dirname($path);
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) return;
$tmp = $path . '.' . bin2hex(random_bytes(4)) . '.tmp';
if (file_put_contents($tmp, $body, LOCK_EX) === false) return;
rename($tmp, $path);
}