diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index bef82a8b..09bbbbd3 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -5,11 +5,13 @@ namespace App\Http\Controllers; use Utils; use Schema; use Option; +use Storage; use Artisan; use Database; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Validation\Validator; +use App\Exceptions\PrettyPageException; class SetupController extends Controller { @@ -121,10 +123,7 @@ class SetupController extends Controller protected function createDirectories() { - if (!is_dir(BASE_DIR.'/storage/textures/')) { - if (!mkdir(BASE_DIR.'/storage/textures/')) - throw new App\Exceptions\PrettyPageException('/storage/textures 文件夹创建失败,请检查目录权限是否正确,或者手动放置一个。', -1); - } + Utils::checkTextureDirectory(); } protected function checkTablesExist() diff --git a/app/Http/Controllers/TextureController.php b/app/Http/Controllers/TextureController.php index f0928589..c7675e43 100644 --- a/app/Http/Controllers/TextureController.php +++ b/app/Http/Controllers/TextureController.php @@ -100,7 +100,7 @@ class TextureController extends Controller if (isset($responses[0]) && $responses[0] instanceof \Symfony\Component\HttpFoundation\Response) { return $responses[0]; } else { - $filename = BASE_DIR."/storage/textures/{$t->hash}"; + $filename = storage_path("textures/{$t->hash}"); $png = Minecraft::generateAvatarFromSkin($filename, $size); imagepng($png); @@ -135,7 +135,7 @@ class TextureController extends Controller if (isset($responses[0]) && $responses[0] instanceof \Symfony\Component\HttpFoundation\Response) { return $responses[0]; } else { - $filename = BASE_DIR."/storage/textures/{$t->hash}"; + $filename = storage_path("textures/{$t->hash}"); if ($t->type == "cape") { $png = Minecraft::generatePreviewFromCape($filename, $size); diff --git a/app/Models/Player.php b/app/Models/Player.php index 46d6a35d..e646a5f5 100644 --- a/app/Models/Player.php +++ b/app/Models/Player.php @@ -121,7 +121,7 @@ class Player extends Model { if ($this->getTexture($type)) { $hash = $this->getTexture($type); - $path = BASE_DIR."/storage/textures/".$hash; + $path = storage_path("textures/$hash"); if (Storage::disk('textures')->has($hash)) { // Cache friendly @@ -202,7 +202,9 @@ class Player extends Model { // Support both CustomSkinLoader API & UniSkinAPI if ($api_type == self::CSL_API || $api_type == self::USM_API) { + $responses = Event::fire(new GetPlayerJson($this, $api_type)); + // if listeners return nothing if (isset($responses[0]) && $responses[0] !== null) { return $responses[0]; diff --git a/app/Providers/BootServiceProvider.php b/app/Providers/BootServiceProvider.php index e21ce9b7..fcee4609 100644 --- a/app/Providers/BootServiceProvider.php +++ b/app/Providers/BootServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use View; +use Utils; use Schema; use Illuminate\Http\Request; use Illuminate\Support\ServiceProvider; @@ -29,7 +30,7 @@ class BootServiceProvider extends ServiceProvider protected function checkFileExists() { - if (!file_exists(BASE_DIR."/.env")) { + if (!file_exists(base_path('.env'))) { throw new PrettyPageException(trans('setup.file.no-dot-env'), -1); } } @@ -63,10 +64,7 @@ class BootServiceProvider extends ServiceProvider return redirect('/setup')->send(); } - if (!is_dir(BASE_DIR.'/storage/textures/')) { - if (!mkdir(BASE_DIR.'/storage/textures/')) - throw new PrettyPageException(trans('setup.file.permission-error'), -1); - } + Utils::checkTextureDirectory(); if (version_compare(config('app.version'), option('version', ''), '>')) { return redirect('/setup/update')->send(); diff --git a/app/Services/Database/Migration.php b/app/Services/Database/Migration.php deleted file mode 100644 index c02ea51c..00000000 --- a/app/Services/Database/Migration.php +++ /dev/null @@ -1,28 +0,0 @@ -current_version = $current_version; - $this->update_sources = require BASE_DIR."/config/update.php"; + $this->update_sources = config('update'); $source = Option::get('update_source'); @@ -115,7 +115,7 @@ class Updater if (!$silent) echo "

下载完成。

"; - $update_cache = BASE_DIR."/setup/update_cache/"; + $update_cache = storage_path('update_cache'); if (!is_dir($update_cache)) { if (false === mkdir($update_cache)) { @@ -126,7 +126,7 @@ class Updater $zip_path = $update_cache."update_".time().".zip"; if (Storage::put($zip_path, $file) === false) { - Storage::removeDir(BASE_DIR.'/setup/update_cache/'); + Storage::removeDir($update_cache); return false; } diff --git a/app/Services/Utils.php b/app/Services/Utils.php index f4ebb83d..a3074f40 100644 --- a/app/Services/Utils.php +++ b/app/Services/Utils.php @@ -2,9 +2,9 @@ namespace App\Services; -use App\Exceptions\PrettyPageException; -use Storage; use Log; +use Storage; +use App\Exceptions\PrettyPageException; class Utils { @@ -17,11 +17,11 @@ class Utils public static function upload($file) { $path = 'tmp'.time(); - $absolute_path = BASE_DIR."/storage/textures/$path"; + $absolute_path = storage_path("textures/$path"); try { if (false === move_uploaded_file($file['tmp_name'], $absolute_path)) { - throw new Exception('Failed to remove uploaded files, please check the permission', 1); + throw new \Exception('Failed to remove uploaded files, please check the permission', 1); } } catch (\Exception $e) { Log::warning("Failed to move uploaded file, $e"); @@ -79,4 +79,13 @@ class Utils return $str; } + public static function checkTextureDirectory() + { + if (!Storage::disk('storage')->has('textures')) { + // mkdir + if (!Storage::disk('storage')->makeDirectory('textures')) + throw new PrettyPageException(trans('setup.file.permission-error'), -1); + } + } + } diff --git a/app/helpers.php b/app/helpers.php index fe4b740d..7f458988 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -137,7 +137,7 @@ if (! function_exists('bs_menu')) { function bs_menu($type) { - $menu = require BASE_DIR."/config/menu.php"; + $menu = config('menu'); event($type == "user" ? new App\Events\ConfigureUserMenu($menu) : new App\Events\ConfigureAdminMenu($menu)); diff --git a/artisan b/artisan index 894fa27b..df630d0d 100644 --- a/artisan +++ b/artisan @@ -1,8 +1,6 @@ #!/usr/bin/env php storage_path('app'), ], + 'storage' => [ + 'driver' => 'local', + 'root' => storage_path(), + ], + 'textures' => [ 'driver' => 'local', 'root' => storage_path('textures'), diff --git a/index.php b/index.php index 8f070142..b95cae4e 100755 --- a/index.php +++ b/index.php @@ -7,11 +7,9 @@ * @author printempw */ -define('BASE_DIR', __DIR__); +require __DIR__.'/bootstrap/autoload.php'; -require BASE_DIR.'/bootstrap/autoload.php'; - -$app = require_once BASE_DIR.'/bootstrap/app.php'; +$app = require_once __DIR__.'/bootstrap/app.php'; $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); diff --git a/resources/views/admin/download.tpl b/resources/views/admin/download.tpl index 5d8618ba..02a7ef16 100644 --- a/resources/views/admin/download.tpl +++ b/resources/views/admin/download.tpl @@ -31,7 +31,7 @@ } $zip = new ZipArchive(); - $extract_dir = BASE_DIR."/setup/update_cache/{$updater->latest_version}"; + $extract_dir = storage_path("update_cache/{$updater->latest_version}"); $res = $zip->open($zip_path); if ($res === true) { @@ -42,12 +42,12 @@ } $zip->close(); - if (Storage::copyDir($extract_dir, BASE_DIR) !== true) { - Storage::removeDir(BASE_DIR.'/setup/update_cache/'); + if (Storage::copyDir($extract_dir, base_path()) !== true) { + Storage::removeDir(storage_path('update_cache')); exit('无法覆盖文件。'); } else { echo "

正在覆盖文件

"; - Storage::removeDir(BASE_DIR.'/setup/update_cache/'); + Storage::removeDir(storage_path('update_cache')); echo "

正在清理

"; } echo "

更新完成。

"; @@ -57,7 +57,7 @@