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

This commit is contained in:
seo
2026-07-25 19:33:34 +09:00
parent 10c00b3e57
commit 3aff2748e8
4 changed files with 58 additions and 15 deletions
+8
View File
@@ -55,22 +55,30 @@ function collect_asset_files(string $root, array $scanRoots): array
clearstatcache();
$rootPath = realpath($root);
$fingerprints = [];
$assets = [];
foreach (collect_asset_files($root, $scanRoots) 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);
$fingerprints[] = implode('|', [
str_replace(DIRECTORY_SEPARATOR, '/', $relativePath),
(string)filesize($fullPath),
(string)filemtime($fullPath),
$fileHash,
]);
if (str_starts_with($relativePath, 'public' . DIRECTORY_SEPARATOR)) {
$publicPath = substr($relativePath, strlen('public'));
$assets[str_replace(DIRECTORY_SEPARATOR, '/', $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);