From 635943e7423f43bbe020326553298fe5f9dc46a5 Mon Sep 17 00:00:00 2001 From: xboard Date: Sat, 11 Jan 2025 02:23:13 +0800 Subject: [PATCH] fix: feat: add theme public files initialization check --- app/Services/ThemeService.php | 2 +- routes/web.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Services/ThemeService.php b/app/Services/ThemeService.php index a7c3b50..c12593d 100644 --- a/app/Services/ThemeService.php +++ b/app/Services/ThemeService.php @@ -271,7 +271,7 @@ class ThemeService /** * 获取主题路径 */ - private function getThemePath(string $theme): ?string + public function getThemePath(string $theme): ?string { $systemPath = base_path(self::SYSTEM_THEME_DIR . $theme); if (File::exists($systemPath)) { diff --git a/routes/web.php b/routes/web.php index 3d7b6f1..0deb405 100755 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ use App\Services\ThemeService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\File; /* |-------------------------------------------------------------------------- @@ -42,6 +43,16 @@ Route::get('/', function (Request $request) { throw new Exception('主题视图文件不存在'); } + // 检查主题是否已复制到public目录 + $publicThemePath = public_path('theme/' . $theme); + if (!File::exists($publicThemePath)) { + $themePath = $themeService->getThemePath($theme); + if (!$themePath || !File::copyDirectory($themePath, $publicThemePath)) { + throw new Exception('主题初始化失败'); + } + Log::info('Theme initialized in public directory', ['theme' => $theme]); + } + $renderParams = [ 'title' => admin_setting('app_name', 'Xboard'), 'theme' => $theme,