Browse Source

add mtime for static files' path

master
filesite 3 years ago
parent
commit
dae43f6b76
  1. 10
      lib/DirScanner.php
  2. 11
      test/DirScannerTest.php

10
lib/DirScanner.php

@ -165,7 +165,7 @@ Class DirScanner {
'ctime' => $fstat['ctime'], 'ctime' => $fstat['ctime'],
], ],
'realpath' => $realpath, 'realpath' => $realpath,
'path' => $this->getFilePath( $id, $this->getDirectoryName($pathinfo['dirname'], $dirLevel), $pathinfo['filename'], $extension ), 'path' => $this->getFilePath( $id, $this->getDirectoryName($pathinfo['dirname'], $dirLevel), $pathinfo['filename'], $extension, $fstat['mtime'] ),
]; ];
if ($extension == 'url') { if ($extension == 'url') {
@ -264,7 +264,8 @@ Class DirScanner {
} }
//根据文件生成相对路径 //根据文件生成相对路径
protected function getFilePath($id, $directory, $filename, $extension) { //@ver: 增加静态文件的更新时间戳作为文件版本参数
protected function getFilePath($id, $directory, $filename, $extension, $mtime) {
if (empty($directory)) { if (empty($directory)) {
$directory = '/'; $directory = '/';
} }
@ -301,6 +302,11 @@ Class DirScanner {
$path = $this->getSecureLink($path); $path = $this->getSecureLink($path);
} }
//增加版本号ver参数
if (!in_array($extension, ['md', 'url', 'txt'])) {
$path .= strpos($path, '?') !== false ? "&ver={$mtime}" : "?ver={$mtime}";
}
return $path; return $path;
} }

11
test/DirScannerTest.php

@ -72,7 +72,10 @@ echo "\n";
$readme_id = '34528ca632426cd2cd570dd32c9dcf4c'; $readme_id = '34528ca632426cd2cd570dd32c9dcf4c';
$readme_titles = $scanner->getMDTitles($readme_id); $readme_titles = $scanner->getMDTitles($readme_id);
echo "Titles of MD file {$readme_id}:\n";
print_r($readme_titles); print_r($readme_titles);
echo "\n";
echo "\n";
//$menus = $scanner->getMenus(); //$menus = $scanner->getMenus();
//echo "Directories:\n"; //echo "Directories:\n";
@ -81,10 +84,10 @@ print_r($readme_titles);
//echo "\n"; //echo "\n";
//echo "Directories and files' tree:\n"; echo "Directories and files' tree:\n";
//print_r($dirTree); print_r($dirTree);
//echo "\n"; echo "\n";
//echo "\n"; echo "\n";
//$scanResults = $scanner->getScanResults(); //$scanResults = $scanner->getScanResults();

Loading…
Cancel
Save