From e65757912c6d1b181d43b4d9bae4e037ddc9e602 Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 3 Jun 2024 21:10:40 +0800 Subject: [PATCH] bug fix: user map save ignored his default dir --- plugins/Common.php | 37 +++++++++++++++---- .../tajian/controller/FrontapiController.php | 2 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/plugins/Common.php b/plugins/Common.php index 2bf1e6a..b74a25f 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -49,16 +49,25 @@ Class Common { } //保存用户多收藏夹目录映射配置 - public static function saveUserDirMap($cellphone, $new_dir) { + public static function saveUserDirMap($cellphone, $username, $new_dir) { $tajian_user_map = FSC::$app['config']['tajian_user_map']; if (empty($tajian_user_map)) { $tajian_user_map = array(); $tajian_user_map[$cellphone] = array($new_dir); }else { $map = $tajian_user_map[$cellphone]; - if (empty($map)) { - $map = array($new_dir); - }else if (is_string($map)) { + if (empty($map)) { //如果之前没有配置过 + $map = array(); + + $defaultDir = self::getUserId($cellphone); //先获取用户自己的目录 + if (self::existUserDataDir($defaultDir, $username)) { + array_push($map, $defaultDir); + } + + if ($new_dir != $defaultDir) { + array_push($map, $new_dir); + } + }else if (is_string($map)) { //如果有配置过字符串格式的单个目录 $old = $map; $map = array($old, $new_dir); }else if (is_array($map) && !in_array($new_dir, $map)) { @@ -75,8 +84,7 @@ Class Common { } //获取新收藏夹目录名 - public static function getNewFavDir($cellphone) - { + public static function getNewFavDir($cellphone) { $new_dir = 2000; //默认从编号2000开始 $cache_filename = __DIR__ . '/../runtime/userCustomFavDirs.json'; @@ -132,7 +140,7 @@ Class Common { file_put_contents($cache_filename, json_encode($data, JSON_PRETTY_PRINT)); //保存用户手机和收藏夹映射关系 - self::saveUserDirMap($cellphone, $new_dir); + self::saveUserDirMap($cellphone, $username, $new_dir); }catch(Exception $e) { return false; } @@ -259,7 +267,7 @@ Class Common { return $nickname; } - //判断用户数据目录是否存在 + //获取用户数据目录 public static function getUserDataDir($cellphone, $currentUsername = '') { $rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; @@ -273,6 +281,19 @@ Class Common { return is_dir($userDir) ? $userDir : false; } + //判断用户数据目录是否存在 + public static function existUserDataDir($dir, $currentUsername = '') { + $rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; + + if (!empty($currentUsername)) { + $userDir = str_replace("/{$currentUsername}", "/{$dir}", $rootDir); + }else { + $userDir = "{$rootDir}{$dir}"; + } + + return is_dir($userDir) ? true : false; + } + //判断当前用户数据目录是否存在 public static function existCurrentUser() { $rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index 5e2f852..c63c49b 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -1316,7 +1316,7 @@ eof; } if (empty($err)) { //如果数据检查通过,尝试保存 - $saved = Common::saveUserDirMap($friends_cellphone, $share_dir); + $saved = Common::saveUserDirMap($friends_cellphone, $loginedUser['username'], $share_dir); if ($saved !== false) { $msg = "账号共享完成";