diff --git a/conf/app.php b/conf/app.php index 04fc1b3..b3112fb 100644 --- a/conf/app.php +++ b/conf/app.php @@ -26,7 +26,7 @@ return array( 'error_layout' => 'error', //exception layout, show error title and content //for debug, log directory: ../runtime/logs/ - 'debug' => false, + 'debug' => true, //for themes /* diff --git a/controller/ApiController.php b/controller/ApiController.php new file mode 100644 index 0000000..4ab8b96 --- /dev/null +++ b/controller/ApiController.php @@ -0,0 +1,78 @@ + $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')); + } + +} diff --git a/controller/Controller.php b/controller/Controller.php index f609098..2008895 100644 --- a/controller/Controller.php +++ b/controller/Controller.php @@ -80,6 +80,11 @@ Class Controller { //render json data protected function renderJson($data) { + if (!empty(FSC::$app['config']['debug'])) { + $end_time = microtime(true); + $data['page_time_cost'] = ceil( ($end_time - FSC::$app['start_time']) * 1000 ); //ms + } + header("Content-Type: application/json; charset=utf-8"); echo json_encode($data); exit;