ff14-mitigator/api/cache.php
xziino 636a65965a Analyse+Planer: sourceID fuer Reprisal/Feint/Addle via Cast-Events
- Neuer Abschnitt 2c in analysis.php: Cast-Events fuer Reprisal/Feint/Addle
  per 1 GQL-Request (3 Aliase) abfragen, da dataType:Buffs nur Friendly-
  Targets liefert (Boss-Debuffs fehlen dort)
- buffSourceTimeline mit Cast-Timestamps + 10s Dauer befuellt
- findBuffSourcePlayer(): sucht aktiven Caster zum Schadens-Zeitpunkt
- resolveMitigations(): gibt sourcePlayerType aus buffSourceTimeline zurueck
- guessJob() in planner.js: sourcePlayerType als erste Prioritaet vor
  job-basiertem Fallback -> DRK Reprisal, MNK Feint etc. korrekt zugeordnet
- analysis.js: Debuff-Icons im Header zeigen Job im Tooltip (z.B. DRK - Reprisal)
- Cache v5 -> v6

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

53 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
const CACHED_LOG_DIR = __DIR__ . '/../cached_logs';
const CACHED_LOG_VERSION = 'v6';
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);
}