Browse Source

function getFilePath v1 done

master
filesite 3 years ago
parent
commit
263705221a
  1. 35
      lib/DirScanner.php
  2. 22
      test/DirScannerTest.php

35
lib/DirScanner.php

@ -69,11 +69,11 @@ Class DirScanner {
//解析描述文件内容 //解析描述文件内容
private function parseDescriptionFiles() { private function parseDescriptionFiles($realpath) {
} }
//解析快捷方式文件内容 //解析快捷方式文件内容
private function parseShortCuts() { private function parseShortCuts($realpath) {
} }
//根据文件路径生成唯一编号 //根据文件路径生成唯一编号
@ -107,7 +107,34 @@ Class DirScanner {
} }
//根据文件生成相对路径 //根据文件生成相对路径
protected function getFilePath() { protected function getFilePath($directory, $filename, $extension) {
$extensionPathMap = [ //默认每种文件读取内容最大大小
'txt' => '',
'md' => '/view/',
'url' => '/link/',
'm3u8' => '/m3u8/',
'jpg' => "{$directory}{$filename}.{$extension}",
'png' => "{$directory}{$filename}.{$extension}",
'gif' => "{$directory}{$filename}.{$extension}",
'ico' => "{$directory}{$filename}.{$extension}",
'mp4' => "{$directory}{$filename}.{$extension}",
'ts' => "{$directory}{$filename}.{$extension}",
];
$path = isset($extensionPathMap[$extension]) ? $extensionPathMap[$extension] : '';
if (!empty($path) && in_array($extension, ['md', 'url', 'm3u8'])) {
if ($this->nginxSecureOn && $extension == 'm3u8') {
$path = $this->getSecureLink($path);
$path = "{$path}&file=" . urlencode($filename);
}else {
$path = "{$path}?file=" . urlencode($filename);
}
}else if (!empty($path) && $this->nginxSecureOn) {
$path = $this->getSecureLink($path);
}
return $path;
} }
@ -116,6 +143,8 @@ Class DirScanner {
$status = false; $status = false;
if (is_string($secureOn) && strtolower($secureOn) == 'on') { if (is_string($secureOn) && strtolower($secureOn) == 'on') {
$status = true; $status = true;
}else if (is_string($secureOn) && strtolower($secureOn) == 'off') {
$status = false;
}else if ((bool)$secureOn == true) { }else if ((bool)$secureOn == true) {
$status = true; $status = true;
} }

22
test/DirScannerTest.php

@ -22,7 +22,7 @@ class DirScannerTest extends DirScanner {
} }
echo "\n"; echo "\n";
echo "==function secureLink==\n"; echo "==function secureLinkTest==\n";
echo "secret: " . $this->getNginxSecret() . "\n"; echo "secret: " . $this->getNginxSecret() . "\n";
echo "user ip: " . $this->getUserIp() . "\n"; echo "user ip: " . $this->getUserIp() . "\n";
echo "timeout: " . $this->getNginxSecureTimeout() . " seconds\n"; echo "timeout: " . $this->getNginxSecureTimeout() . " seconds\n";
@ -33,9 +33,29 @@ class DirScannerTest extends DirScanner {
echo "\n"; echo "\n";
} }
public function getFilePathTest($directory, $filename, $extension) {
echo "\n";
echo "==function getFilePathTest==\n";
echo "directory: {$directory}\n";
echo "filename: {$filename}\n";
echo "extension: {$extension}\n";
$url = $this->getFilePath($directory, $filename, $extension);
echo "path: {$url}\n";
$this->setNginxSecure('on', 'Tester');
$secure_url = $this->getFilePath($directory, $filename, $extension);
echo "secure path: {$secure_url}\n";
$this->setNginxSecure('off');
echo "\n";
}
} }
//--调用测试方法-- //--调用测试方法--
$scanner = new DirScannerTest(); $scanner = new DirScannerTest();
$scanner->secureLinkTest('/default/', 'foo=bar', '127.0.0.1'); $scanner->secureLinkTest('/default/', 'foo=bar', '127.0.0.1');
$scanner->getFilePathTest('/content/小说/金庸/', '书剑恩仇录', 'md');
$scanner->getFilePathTest('/content/小说/金庸/', '封面图', 'jpg');
$scanner->getFilePathTest('/content/视频/游戏/', 'demo', 'm3u8');
$scanner->getFilePathTest('/content/视频/游戏/', '推荐', 'url');
$scanner->getFilePathTest('/content/视频/游戏/', '测试', 'mp4');

Loading…
Cancel
Save