Files
谢宇宁andClaude Opus 5.5 3639d2184a Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 14:47:17 +07:00

52 lines
1.2 KiB
Go

package seoser
import (
"path"
"strings"
"videoweb/app/appg"
)
// VerifyCodes 站长平台所有权验证(meta + 根路径文件)。
type VerifyCodes struct {
Baidu string
BaiduHTML string
IndexNowKey string
}
// VerifyFromConfig 读取 yaml 中的验证码与验证文件名。
func VerifyFromConfig() VerifyCodes {
seo := appg.Conf.SEO
return VerifyCodes{
Baidu: strings.TrimSpace(seo.BaiduSiteVerification),
BaiduHTML: sanitizeVerifyFile(seo.BaiduHTMLFile),
IndexNowKey: sanitizeIndexNowKey(seo.IndexNowKey),
}
}
func sanitizeVerifyFile(raw string) string {
raw = strings.TrimSpace(strings.ReplaceAll(raw, "\\", "/"))
raw = path.Base(raw)
if raw == "" || raw == "." || raw == "/" || strings.Contains(raw, "..") {
return ""
}
lower := strings.ToLower(raw)
if strings.HasSuffix(lower, ".html") || strings.HasSuffix(lower, ".htm") || strings.HasSuffix(lower, ".xml") {
return raw
}
return ""
}
func sanitizeIndexNowKey(raw string) string {
raw = strings.TrimSpace(raw)
if raw == "" {
return ""
}
for _, r := range raw {
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '-' || r == '_' {
continue
}
return ""
}
return raw
}