From 3ed89fb49692790293bfc46624fcdcfa576fec3d Mon Sep 17 00:00:00 2001 From: filesite Date: Sat, 29 Oct 2022 16:31:40 +0800 Subject: [PATCH] move dir improve, to support root directory --- controller/ApiController.php | 40 +++++++++++++++++++++++++++++++----- controller/Controller.php | 1 + www/content/README.md | 2 +- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/controller/ApiController.php b/controller/ApiController.php index bbc45f2..d18a221 100644 --- a/controller/ApiController.php +++ b/controller/ApiController.php @@ -49,9 +49,11 @@ Class ApiController extends Controller { } private function getParentDir($realpath) { + if ($realpath == '/') {return $realpath;} + $realpath = preg_replace('/\/$/', '', $realpath); $arr = explode('/', $realpath); - if (count($arr) < 2) {return $realpath;} + if (count($arr) < 2) {return '/';} array_pop($arr); return implode('/', $arr); @@ -61,6 +63,8 @@ Class ApiController extends Controller { protected function isParentDirectoryValid($parentDir) { if (empty($parentDir) || strpos($parentDir, '../') !== false) { return false; + }else if ($realpath == '/') { + return true; } $valid = true; @@ -288,7 +292,17 @@ Class ApiController extends Controller { $target = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; try { - $res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}"); + //兼容已经存在的目录,则移动进去,而不是重命名 + if ($toDir == '/') { + $basename = $this->basename($fromDir); + $res = rename("{$target}/{$fromDir}", "{$target}/{$basename}"); + }else if (!realpath("{$target}/{$toDir}")) { + $res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}"); + }else { + $basename = $this->basename($fromDir); + $res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}/{$basename}"); + } + if ($res) { $code = 1; $msg = '目录/文件移动完成'; @@ -340,9 +354,9 @@ Class ApiController extends Controller { $res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}"); if ($res) { $code = 1; - $msg = '目录移动完成'; + $msg = '重命名完成'; }else { - $err = '目录移动失败,请确认被移动目录存在及目标目录权限配置正确!'; + $err = '重命名失败,请确认被重命名目录/文件存在及目标目录权限配置正确!'; } }catch(Exception $e) { $err = $e->getMessage(); @@ -409,7 +423,8 @@ Class ApiController extends Controller { $refresh = (int)$this->post('refresh', 0); try { - $builder = new CaptchaBuilder; + $randNumber = rand(10000, 99999); + $builder = new CaptchaBuilder("{$randNumber}"); $builder->build(); $captcha_jpg = $builder->get(); $captcha_code = $builder->getPhrase(); @@ -724,6 +739,21 @@ Class ApiController extends Controller { if (!empty($contentDirectory)) { $jsonData['content_directory'] = $contentDirectory; + }else { + switch($themeName) { + case 'manual': + $jsonData['content_directory'] = 'content'; + break; + case 'webdirectory': + $jsonData['content_directory'] = 'navs'; + break; + case 'googleimage': + $jsonData['content_directory'] = 'girls'; + break; + case 'videoblog': + $jsonData['content_directory'] = 'videos'; + break; + } } if (file_exists($customConfigFile)) { diff --git a/controller/Controller.php b/controller/Controller.php index b704d20..8e5c839 100644 --- a/controller/Controller.php +++ b/controller/Controller.php @@ -279,6 +279,7 @@ Class Controller { //get basename of realpath, support chinese protected function basename($realpath) { + $realpath = preg_replace('/\/$/', '', $realpath); $arr = explode('/', $realpath); if (count($arr) < 2) {return $realpath;} diff --git a/www/content/README.md b/www/content/README.md index 7386537..30455a9 100644 --- a/www/content/README.md +++ b/www/content/README.md @@ -131,7 +131,7 @@ http://127.0.0.1:1080 FileSite.io官方提供的皮肤都包含在最新版的源码目录```themes/```中,详情如下: -| 皮肤名称 | 目录名 | 适用网站类型 | +| 皮肤名称 | 皮肤目录 | 适用网站类型 | | ---- | ---- | ---- | | WebDirectory | webdirectory | 导航站 | | Manual | manual | 文档站 |