Skip to content

Commit

Permalink
🎨 #9
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 28, 2019
1 parent 2cbe34c commit ad79351
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions service/initsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ func initBasicSettings(tx *gorm.DB, blogAdmin *model.User, blogID uint64) error
if err := tx.Create(&model.Setting{
Category: model.SettingCategoryBasic,
Name: model.SettingNameBasicFaviconURL,
Value: "https://img.hacpai.com/pipe.ico",
Value: util.CommunityFileURL + "/pipe.ico",
BlogID: blogID}).Error; nil != err {
return err
}
if err := tx.Create(&model.Setting{
Category: model.SettingCategoryBasic,
Name: model.SettingNameBasicLogoURL,
Value: "https://img.hacpai.com/pipe192.png",
Value: util.CommunityFileURL + "/pipe192.png",
BlogID: blogID}).Error; nil != err {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions util/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ package util
import (
"math/rand"
"strconv"
"time"
"strings"
"time"
)

// CommunityFileURL is the community file service URL.
const CommunityFileURL = "https://img.hacpai.com"

// ImageSize returns image URL of Qiniu image processing style with the specified width and height.
func ImageSize(imageURL string, width, height int) string {
if strings.Contains(imageURL, "imageView") || !strings.Contains(imageURL, "img.hacpai.com") {
if strings.Contains(imageURL, "imageView") {
return imageURL
}

Expand All @@ -40,7 +43,7 @@ func RandImage() string {
delta := max - min
sec := rand.Int63n(delta) + min

return time.Unix(sec, 0).Format("https://img.hacpai.com/bing/20060102.jpg")
return time.Unix(sec, 0).Format(CommunityFileURL + "/bing/20060102.jpg")
}

// RandImages returns random image URLs.
Expand Down
2 changes: 1 addition & 1 deletion util/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestRandImage(t *testing.T) {
url := RandImage()
if !strings.Contains(url, "img.hacpai.com") {
if !strings.Contains(url, CommunityFileURL) {
t.Errorf(url)
}
}
Expand Down

0 comments on commit ad79351

Please sign in to comment.