에셋 리로드 파일별 캐시 검증 보강

This commit is contained in:
seo
2026-07-25 19:45:14 +09:00
parent b7534d8824
commit 520a5f679d
4 changed files with 55 additions and 15 deletions
+6 -1
View File
@@ -62,22 +62,27 @@ function collect_asset_files(string $root, array $scanRoots, array $excludePrefi
clearstatcache();
$rootPath = realpath($root);
$fingerprints = [];
$assets = [];
foreach (collect_asset_files($root, $scanRoots, $excludePrefixes) as $fullPath) {
$relativePath = ltrim(str_replace($rootPath ?: $root, '', $fullPath), DIRECTORY_SEPARATOR);
$fileHash = is_readable($fullPath) ? (hash_file('sha256', $fullPath) ?: 'hash-failed') : 'unreadable';
$fileVersion = (string)filemtime($fullPath) . '-' . substr($fileHash, 0, 10);
$publicPath = '/' . str_replace(DIRECTORY_SEPARATOR, '/', $relativePath);
$fingerprints[] = implode('|', [
str_replace(DIRECTORY_SEPARATOR, '/', $relativePath),
ltrim($publicPath, '/'),
(string)filesize($fullPath),
(string)filemtime($fullPath),
$fileHash,
]);
$assets[$publicPath] = $fileVersion;
}
echo json_encode([
'result' => 'ok',
'service' => $service,
'version' => hash('sha256', implode("\n", $fingerprints)),
'assets' => $assets,
'count' => count($fingerprints),
'generatedAt' => time(),
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);