diff --git a/.gitignore b/.gitignore index 2187541..af7e4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -29,10 +29,14 @@ conf/user1.ini /src/backup/ script.php -# ignore all files in lib/ task/* cache/* log/* + +# ignore all files in lib/ +#task/* +#cache/* +#log/* # except for .gitkeep !.gitkeep # ignore TODO file in root directory,not subdir/TODO diff --git a/cache/.gitkeep b/cache/.gitkeep deleted file mode 100644 index a10d4fe..0000000 --- a/cache/.gitkeep +++ /dev/null @@ -1,3 +0,0 @@ -# Ignore everything in this directory -* -# Except this file !.gitkeep \ No newline at end of file diff --git a/conf/user.ini.example b/conf/user.ini.example index f5efb82..f2e25de 100644 --- a/conf/user.ini.example +++ b/conf/user.ini.example @@ -1,3 +1,5 @@ +version = 0.0.1 + ####################### # 账户设置 # ####################### @@ -265,10 +267,9 @@ proxy = "http://127.0.0.1:8888" [debug] enable = false -; 记录日志|日志路径|日志回调地址 +; 记录日志|日志回调地址 [log] enable = false -path = log callback = "http://www.example.com/api.send?text={account}[{level}]: {message}" # 错误回调级别 # diff --git a/log/.gitkeep b/log/.gitkeep deleted file mode 100644 index a10d4fe..0000000 --- a/log/.gitkeep +++ /dev/null @@ -1,3 +0,0 @@ -# Ignore everything in this directory -* -# Except this file !.gitkeep \ No newline at end of file diff --git a/src/core/App.php b/src/core/App.php index 39063b8..0866b3a 100644 --- a/src/core/App.php +++ b/src/core/App.php @@ -27,11 +27,29 @@ class App */ public function __construct(string $app_path) { - define('APP_CONF_PATH', $app_path . "/conf/"); - define('APP_DATA_PATH', $app_path . "/data/"); - define('APP_LOG_PATH', $app_path . "/log/"); - define('APP_TASK_PATH', $app_path . "/task/"); - define('APP_CACHE_PATH', $app_path . "/cache/"); + define('APP_CONF_PATH', $app_path . '/conf/'); + define('APP_DATA_PATH', $app_path . '/data/'); + define('APP_LOG_PATH', $app_path . '/log/'); + define('APP_TASK_PATH', $app_path . '/task/'); + define('APP_CACHE_PATH', $app_path . '/cache/'); + } + + /** + * @use 初始化数据文件夹 + * @param int $permissions + * @return $this + */ + private function initDataFolder(int $permissions = 0777): App + { + // log task cache + $data_folder = [APP_LOG_PATH, APP_TASK_PATH, APP_CACHE_PATH]; + foreach ($data_folder as $path) { + if (!file_exists($path)) { + mkdir($path); + chmod($path, $permissions); + } + } + return $this; } /** @@ -51,6 +69,7 @@ class App */ public function load($argv): App { + $this->initDataFolder(); $args = (new BCommand($argv))->run(); $filename = $args->args()[0] ?? 'user.ini'; // 加载配置 diff --git a/src/core/Log.php b/src/core/Log.php index a61839a..ed41b97 100644 --- a/src/core/Log.php +++ b/src/core/Log.php @@ -65,12 +65,8 @@ class Log if ($type == 'DEBUG' && !getConf('enable', 'debug')) { return; } - $path = './' . getConf('path', 'log') . '/'; - if (!file_exists($path)) { - mkdir($path); - chmod($path, 0777); - } - $filename = $path . getConf('username', 'login.account') . ".log"; + + $filename = APP_LOG_PATH . getConf('username', 'login.account') . ".log"; $date = date('[Y-m-d H:i:s] '); $data = $date . ' Log.' . $type . ' ' . $message . PHP_EOL; file_put_contents($filename, $data, FILE_APPEND); diff --git a/src/plugin/User.php b/src/plugin/User.php index c1ff67b..b9a77bb 100644 --- a/src/plugin/User.php +++ b/src/plugin/User.php @@ -191,7 +191,7 @@ class User * @param bool $un_follow * @return bool */ - public static function setUserFollow(int $follow_uid, bool $un_follow): bool + public static function setUserFollow(int $follow_uid, bool $un_follow = false): bool { $url = 'https://api.live.bilibili.com/relation/v1/Feed/SetUserFollow'; $payload = [ diff --git a/task/.gitkeep b/task/.gitkeep deleted file mode 100644 index a10d4fe..0000000 --- a/task/.gitkeep +++ /dev/null @@ -1,3 +0,0 @@ -# Ignore everything in this directory -* -# Except this file !.gitkeep \ No newline at end of file