From ba732b3075a06ad5bd0804fa17d5564e12d031a4 Mon Sep 17 00:00:00 2001 From: leoshine <71440988+leo220yuyaodog@users.noreply.github.com> Date: Mon, 15 Aug 2022 09:18:21 +0800 Subject: [PATCH] feat: use staticBaseUrl for all static resources (#1015) * feat: modify system image link * Update App.less Co-authored-by: Yang Luo --- conf/app.conf | 3 ++- object/init.go | 12 ++++++++---- web/src/App.less | 4 +++- web/src/ApplicationListPage.js | 2 +- web/src/OrganizationListPage.js | 4 ++-- web/src/ProductListPage.js | 2 +- web/src/UserListPage.js | 2 +- web/src/basic/HomePage.js | 2 +- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/conf/app.conf b/conf/app.conf index 6a353705..fbeac4f8 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -15,4 +15,5 @@ socks5Proxy = "127.0.0.1:10808" verificationCodeTimeout = 10 initScore = 2000 logPostOnly = true -origin = \ No newline at end of file +origin = +staticBaseUrl = "https://cdn.casbin.org" \ No newline at end of file diff --git a/object/init.go b/object/init.go index d2b09fbc..bd1498c7 100644 --- a/object/init.go +++ b/object/init.go @@ -16,8 +16,10 @@ package object import ( "encoding/gob" + "fmt" "os" + "github.com/astaxie/beego" "github.com/casdoor/casdoor/util" "github.com/duo-labs/webauthn/webauthn" ) @@ -36,6 +38,8 @@ func InitDb() { initWebAuthn() } +var staticBaseUrl = beego.AppConfig.String("staticBaseUrl") + func initBuiltInOrganization() bool { organization := getOrganization("admin", "built-in") if organization != nil { @@ -48,10 +52,10 @@ func initBuiltInOrganization() bool { CreatedTime: util.GetCurrentTime(), DisplayName: "Built-in Organization", WebsiteUrl: "https://example.com", - Favicon: "https://cdn.casbin.com/static/favicon.ico", + Favicon: fmt.Sprintf("%s/img/casbin/favicon.ico", staticBaseUrl), PasswordType: "plain", PhonePrefix: "86", - DefaultAvatar: "https://casbin.org/img/casbin.svg", + DefaultAvatar: fmt.Sprintf("%s/img/casbin.svg", staticBaseUrl), Tags: []string{}, AccountItems: []*AccountItem{ {Name: "Organization", Visible: true, ViewRule: "Public", ModifyRule: "Admin"}, @@ -100,7 +104,7 @@ func initBuiltInUser() { Type: "normal-user", Password: "123", DisplayName: "Admin", - Avatar: "https://casbin.org/img/casbin.svg", + Avatar: fmt.Sprintf("%s/img/casbin.svg", staticBaseUrl), Email: "admin@example.com", Phone: "12345678910", Address: []string{}, @@ -130,7 +134,7 @@ func initBuiltInApplication() { Name: "app-built-in", CreatedTime: util.GetCurrentTime(), DisplayName: "Casdoor", - Logo: "https://cdn.casbin.com/logo/logo_1024x256.png", + Logo: fmt.Sprintf("%s/img/casdoor-logo_1185x256.png", staticBaseUrl), HomepageUrl: "https://casdoor.org", Organization: "built-in", Cert: "cert-built-in", diff --git a/web/src/App.less b/web/src/App.less index d388891a..f48469b7 100644 --- a/web/src/App.less +++ b/web/src/App.less @@ -1,5 +1,7 @@ @import '~antd/dist/antd.less'; +@StaticBaseUrl:"https://cdn.casbin.org"; + .App { text-align: center; } @@ -46,7 +48,7 @@ } .language_box { - background: url("https://cdn.casbin.org/img/muti_language.svg"); + background: url("@{StaticBaseUrl}/img/muti_language.svg"); background-size: 25px, 25px; background-position: center; background-repeat: no-repeat; diff --git a/web/src/ApplicationListPage.js b/web/src/ApplicationListPage.js index 7cfc5ef4..522bbb1a 100644 --- a/web/src/ApplicationListPage.js +++ b/web/src/ApplicationListPage.js @@ -30,7 +30,7 @@ class ApplicationListPage extends BaseListPage { name: `application_${randomName}`, createdTime: moment().format(), displayName: `New Application - ${randomName}`, - logo: "https://cdn.casdoor.com/logo/casdoor-logo_1185x256.png", + logo: `${Setting.StaticBaseUrl}/img/casdoor-logo_1185x256.png`, enablePassword: true, enableSignUp: true, enableSigninSession: false, diff --git a/web/src/OrganizationListPage.js b/web/src/OrganizationListPage.js index 1924bd38..29122020 100644 --- a/web/src/OrganizationListPage.js +++ b/web/src/OrganizationListPage.js @@ -30,11 +30,11 @@ class OrganizationListPage extends BaseListPage { createdTime: moment().format(), displayName: `New Organization - ${randomName}`, websiteUrl: "https://door.casdoor.com", - favicon: "https://cdn.casdoor.com/static/favicon.png", + favicon: `${Setting.StaticBaseUrl}/img/favicon.png`, passwordType: "plain", PasswordSalt: "", phonePrefix: "86", - defaultAvatar: "https://casbin.org/img/casbin.svg", + defaultAvatar: `${Setting.StaticBaseUrl}/img/casbin.svg`, tags: [], masterPassword: "", enableSoftDeletion: false, diff --git a/web/src/ProductListPage.js b/web/src/ProductListPage.js index 2e4c3082..c50029c1 100644 --- a/web/src/ProductListPage.js +++ b/web/src/ProductListPage.js @@ -30,7 +30,7 @@ class ProductListPage extends BaseListPage { name: `product_${randomName}`, createdTime: moment().format(), displayName: `New Product - ${randomName}`, - image: "https://cdn.casdoor.com/logo/casdoor-logo_1185x256.png", + image: `${Setting.StaticBaseUrl}/img/casdoor-logo_1185x256.png`, tag: "Casdoor Summit 2022", currency: "USD", price: 300, diff --git a/web/src/UserListPage.js b/web/src/UserListPage.js index d00bf401..e5c41532 100644 --- a/web/src/UserListPage.js +++ b/web/src/UserListPage.js @@ -49,7 +49,7 @@ class UserListPage extends BaseListPage { password: "123", passwordSalt: "", displayName: `New User - ${randomName}`, - avatar: "https://casbin.org/img/casbin.svg", + avatar: `${Setting.StaticBaseUrl}/img/casbin.svg`, email: `${randomName}@example.com`, phone: Setting.getRandomNumber(), address: [], diff --git a/web/src/basic/HomePage.js b/web/src/basic/HomePage.js index ecb1af56..1a913ed0 100644 --- a/web/src/basic/HomePage.js +++ b/web/src/basic/HomePage.js @@ -56,7 +56,7 @@ class HomePage extends React.Component { if (filename === "/account") { filename = "/users"; } - items[i].logo = `https://cdn.casbin.com/static/img${filename}.png`; + items[i].logo = `${Setting.StaticBaseUrl}/img${filename}.png`; items[i].createdTime = ""; } } else {