에셋 리로드 파일별 캐시 검증 보강
This commit is contained in:
+6
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user