Merge branch 'feat/1.0.7/short-id' into test
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
||||
|
||||
const PermaLinkQuestionIDAndTitle = 1
|
||||
const PermaLinkQuestionID = 2
|
||||
const PermaLinkQuestionIDAndTitleByShortID = 3
|
||||
const PermaLinkQuestionIDByShortID = 4
|
||||
|
||||
// SiteGeneralReq site general request
|
||||
type SiteGeneralReq struct {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/entity"
|
||||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/pkg/uid"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
)
|
||||
|
||||
//go:generate mockgen -source=./siteinfo_service.go -destination=../mock/siteinfo_repo_mock.go -package=mock
|
||||
@@ -22,9 +24,18 @@ type SiteInfoCommonService struct {
|
||||
|
||||
// NewSiteInfoCommonService new site info common service
|
||||
func NewSiteInfoCommonService(siteInfoRepo SiteInfoRepo) *SiteInfoCommonService {
|
||||
return &SiteInfoCommonService{
|
||||
siteInfo := &SiteInfoCommonService{
|
||||
siteInfoRepo: siteInfoRepo,
|
||||
}
|
||||
seoinfo, err := siteInfo.GetSiteSeo(context.Background())
|
||||
if err != nil {
|
||||
log.Error("seoinfo error", err)
|
||||
}
|
||||
if seoinfo.PermaLink == schema.PermaLinkQuestionIDAndTitleByShortID || seoinfo.PermaLink == schema.PermaLinkQuestionIDByShortID {
|
||||
uid.ShortIDSwitch = true
|
||||
}
|
||||
|
||||
return siteInfo
|
||||
}
|
||||
|
||||
// GetSiteGeneral get site info general
|
||||
|
||||
+10
-4
@@ -6,6 +6,8 @@ import (
|
||||
|
||||
const salt = int64(0)
|
||||
|
||||
var ShortIDSwitch = false
|
||||
|
||||
var AlphanumericSet = []rune{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
@@ -84,12 +86,16 @@ func ShortIDToNum(code string) int64 {
|
||||
}
|
||||
|
||||
func EnShortID(id string) string {
|
||||
num, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
return ""
|
||||
if ShortIDSwitch {
|
||||
num, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return NumToShortID(num)
|
||||
}
|
||||
return NumToShortID(num)
|
||||
return id
|
||||
}
|
||||
|
||||
func DeShortID(sid string) string {
|
||||
num, err := strconv.ParseInt(sid, 10, 64)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user