优化部分代码

This commit is contained in:
dragon
2025-01-09 17:27:06 +08:00
parent f0c8fa5547
commit 2f7fa13240
10 changed files with 229 additions and 157 deletions

View File

@@ -6,14 +6,19 @@ import (
"io"
"net/http"
"os"
"regexp"
"strings"
"time"
"go.uber.org/zap"
"github.com/pkg/errors"
"code.d7z.net/d7z-project/gitea-pages/pkg/utils"
)
var regexpHostname = regexp.MustCompile(`^(?:([a-z0-9-]+|\*)\.)?([a-z0-9-]{1,61})\.([a-z0-9]{2,7})$`)
type ServerMeta struct {
Backend
@@ -111,7 +116,12 @@ func (s *ServerMeta) GetMeta(owner, repo, branch string) (*PageMetaContent, erro
if cname, err := s.ReadString(owner, repo, rel.CommitID, "CNAME"); err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, err
} else {
rel.Domain = strings.TrimSpace(cname)
cname = strings.TrimSpace(cname)
if regexpHostname.MatchString(cname) {
rel.Domain = cname
} else {
zap.L().Debug("指定的 CNAME 不合法", zap.String("cname", cname))
}
}
if find, _ := s.FileExists(owner, repo, rel.CommitID, ".history"); find {
rel.HistoryRouteMode = true