diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index cdb98132..983c853f 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -10,4 +10,14 @@ class HomeController extends Controller ->with('transparent_navbar', option('transparent_navbar', false)) ->with('home_pic_url', option('home_pic_url') ?: config('options.home_pic_url')); } + + public function apiRoot() + { + return response()->json([ + 'blessing_skin' => config('app.version'), + 'spec' => 0, + 'copyright' => bs_copyright(), + 'site_name' => option('site_name'), + ]); + } } diff --git a/app/helpers.php b/app/helpers.php index a979ba80..04c22d1c 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -178,6 +178,22 @@ if (! function_exists('bs_menu')) { } } +if (! function_exists('bs_copyright')) { + function bs_copyright() + { + return Arr::get( + [ + 'Powered with ❤ by Blessing Skin Server.', + 'Powered by Blessing Skin Server.', + 'Proudly powered by Blessing Skin Server.', + '由 Blessing Skin Server 强力驱动。', + '自豪地采用 Blessing Skin Server。' + ], + option_localized('copyright_prefer', 0) + ); + } +} + if (! function_exists('option')) { /** * Get / set the specified option value. diff --git a/resources/views/common/copyright.blade.php b/resources/views/common/copyright.blade.php index 8f01b1bd..9175e825 100644 --- a/resources/views/common/copyright.blade.php +++ b/resources/views/common/copyright.blade.php @@ -1,12 +1,7 @@ {!! -Arr::get( - [ - 'Powered with ❤ by Blessing Skin Server.', - 'Powered by Blessing Skin Server.', - 'Proudly powered by Blessing Skin Server.', - '由 Blessing Skin Server 强力驱动。', - '自豪地采用 Blessing Skin Server。' - ], - option_localized('copyright_prefer', 0) -) + str_replace( + 'Blessing Skin Server', + 'Blessing Skin Server', + bs_copyright() + ) !!} diff --git a/routes/api.php b/routes/api.php index a2b3adf4..8a281f5f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,7 @@ group(function () { Route::post('login', 'AuthController@jwtLogin'); Route::post('logout', 'AuthController@jwtLogout')->middleware('auth:jwt'); diff --git a/tests/Api/tests/main.rs b/tests/Api/tests/main.rs index 9e9ca9f0..1f8a50f5 100644 --- a/tests/Api/tests/main.rs +++ b/tests/Api/tests/main.rs @@ -4,6 +4,9 @@ mod auth; #[cfg(test)] mod closet; +#[cfg(test)] +mod misc; + #[cfg(test)] mod players; diff --git a/tests/Api/tests/misc.rs b/tests/Api/tests/misc.rs new file mode 100644 index 00000000..ebc1a73d --- /dev/null +++ b/tests/Api/tests/misc.rs @@ -0,0 +1,21 @@ +use serde::Deserialize; + +#[derive(Deserialize)] +struct RootInfo { + blessing_skin: String, + spec: u8, + copyright: String, + site_name: String, +} + +#[test] +fn api_root() { + let body = reqwest::get("http://127.0.0.1:32123/api") + .unwrap() + .json::() + .unwrap(); + assert!(body.blessing_skin.starts_with("4")); + assert_eq!(body.spec, 0); + assert_eq!(body.copyright, "Powered with ❤ by Blessing Skin Server."); + assert_eq!(body.site_name, "Blessing Skin"); +} diff --git a/tests/HomeControllerTest.php b/tests/HomeControllerTest.php index 3e28698b..9a46c1f5 100644 --- a/tests/HomeControllerTest.php +++ b/tests/HomeControllerTest.php @@ -42,4 +42,9 @@ class HomeControllerTest extends TestCase }); $this->get('/'); } + + public function testApiRoot() + { + $this->get('/api')->assertJson(['spec' => 0]); + } }