Source code of filesite.io.
https://filesite.io
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.2 KiB
78 lines
2.2 KiB
<?php |
|
/** |
|
* Api Controller |
|
*/ |
|
require_once __DIR__ . '/../lib/DirScanner.php'; |
|
|
|
Class ApiController extends Controller { |
|
protected $version = '1.0'; |
|
|
|
//show api list |
|
public function actionIndex() { |
|
$params = array( |
|
'version' => $this->version, |
|
'list' => array( |
|
'列表' => '/api/ls/', |
|
|
|
//文件操作 |
|
'重命名' => '/api/rename/', |
|
'删除文件' => '/api/delete/', |
|
'移动' => '/api/move/', |
|
|
|
//目录操作 |
|
'创建目录' => '/api/mkdir/', |
|
'删除目录' => '/api/rmdir/', |
|
), |
|
); |
|
return $this->renderJson($params); |
|
} |
|
|
|
//目录、文件列表 |
|
public function actionLs() { |
|
$code = 0; |
|
$msg = $err = ''; |
|
$data = array(); |
|
|
|
|
|
$scanner = new DirScanner(); |
|
$scanner->setWebRoot(FSC::$app['config']['content_directory']); |
|
$target = __DIR__ . '//../www/' . FSC::$app['config']['content_directory']; |
|
$maxLevels = 2; |
|
$dirTree = $scanner->scan($target, $maxLevels); |
|
$scanResults = $scanner->getScanResults(); |
|
|
|
//获取目录 |
|
$menus = $scanner->getMenus(); |
|
if (empty($menus)) { |
|
$err = '没有任何目录/文件'; |
|
return $this->renderJson(compact('code', 'msg', 'err', 'data')); |
|
} |
|
|
|
//排序 |
|
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序 |
|
$readmeFile = $scanner->getDefaultReadme(); |
|
if (!empty($readmeFile)) { |
|
if (!empty($readmeFile['sort'])) { |
|
$menus_sorted = explode("\n", $readmeFile['sort']); |
|
} |
|
} |
|
|
|
$sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree); |
|
if (!empty($sortedTree)) { |
|
$menus = $sortedTree['menus']; |
|
$dirTree = $sortedTree['dirTree']; |
|
} |
|
|
|
|
|
$cateId = $this->get('id', $menus[0]['id']); |
|
$data['menus'] = $menus; |
|
$data['dirTree'] = $scanResults[$cateId]; |
|
|
|
$code = 1; |
|
$msg = ''; |
|
$err = ''; |
|
|
|
return $this->renderJson(compact('code', 'msg', 'err', 'data')); |
|
} |
|
|
|
}
|
|
|