From d6a9b5cae341a81c19f9a36c771f146597330494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Wed, 3 Aug 2022 11:34:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BC=98=E5=8C=96=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=88=86=E5=8F=91=E7=BD=91=E7=BB=9CURL=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Index.php | 1 + app/api/controller/Index.php | 1 + app/common.php | 14 ++++++++++---- config/buildadmin.php | 2 ++ web/src/stores/interface/index.ts | 1 + web/src/stores/siteConfig.ts | 1 + 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 7f8799a0..dc4729e4 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -31,6 +31,7 @@ class Index extends Backend 'siteConfig' => [ 'site_name' => get_sys_config('site_name'), 'version' => get_sys_config('version'), + 'cdn_url' => full_url(), ], 'terminal' => [ 'install_service_port' => Config::get('buildadmin.install_service_port'), diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 3d0715d8..515e34b3 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -21,6 +21,7 @@ class Index extends Frontend 'site_name' => get_sys_config('site_name'), 'record_number' => get_sys_config('record_number'), 'version' => get_sys_config('version'), + 'cdn_url' => full_url(), ], 'open_member_center' => Config::get('buildadmin.open_member_center'), ]); diff --git a/app/common.php b/app/common.php index f69c51bf..83ae4820 100644 --- a/app/common.php +++ b/app/common.php @@ -150,15 +150,21 @@ if (!function_exists('full_url')) { */ function full_url($relativeUrl = false, $domain = true, $default = '') { - $relativeUrl = $relativeUrl ? $relativeUrl : $default; - if (!$relativeUrl) { - return $domain === true ? request()->domain() : $domain; + $cdnUrl = Config::get('buildadmin.cdn_url'); + if ($domain === true) { + $domain = $cdnUrl ? $cdnUrl : request()->domain(); + } elseif ($domain === false) { + $domain = ''; } + + $relativeUrl = $relativeUrl ? $relativeUrl : $default; + if (!$relativeUrl) return $domain; + $regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i"; if (preg_match('/^http(s)?:\/\//', $relativeUrl) || preg_match($regex, $relativeUrl) || $domain === false) { return $relativeUrl; } - return $domain === true ? request()->domain() . $relativeUrl : $domain . $relativeUrl; + return $domain . $relativeUrl; } } diff --git a/config/buildadmin.php b/config/buildadmin.php index 2a9338d7..cf61ab29 100644 --- a/config/buildadmin.php +++ b/config/buildadmin.php @@ -99,6 +99,8 @@ return [ 'auto_write_admin_log' => true, // 缺省头像图片路径 'default_avatar' => '/static/images/avatar.png', + // 内容分发网络URL + 'cdn_url' => '', // 版本号 'version' => 'v1.0.3', ]; \ No newline at end of file diff --git a/web/src/stores/interface/index.ts b/web/src/stores/interface/index.ts index 5d6c39a4..3a60c734 100644 --- a/web/src/stores/interface/index.ts +++ b/web/src/stores/interface/index.ts @@ -121,4 +121,5 @@ export interface SiteConfig { site_name: string record_number?: string version: string + cdn_url: string } diff --git a/web/src/stores/siteConfig.ts b/web/src/stores/siteConfig.ts index c0ab5855..31e0033c 100644 --- a/web/src/stores/siteConfig.ts +++ b/web/src/stores/siteConfig.ts @@ -7,6 +7,7 @@ export const useSiteConfig = defineStore('siteConfig', { site_name: '', record_number: '', version: '', + cdn_url: '', } }, })