Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
89 lines
3.1 KiB
Go
89 lines
3.1 KiB
Go
package configser
|
||
|
||
import (
|
||
"fmt"
|
||
"strings"
|
||
)
|
||
|
||
// HomeRoadLinkVM 是“回家的路”页面中的可访问线路。
|
||
type HomeRoadLinkVM struct {
|
||
Label string
|
||
URL string
|
||
}
|
||
|
||
// HomeRoadContactVM 是防失联联系方式。
|
||
type HomeRoadContactVM struct {
|
||
Title string
|
||
Description string
|
||
Action string
|
||
URL string
|
||
}
|
||
|
||
// HomeRoadPageVM 将 config/info 中的地址字段整理成页面所需结构。
|
||
type HomeRoadPageVM struct {
|
||
MainURL string
|
||
Routes []HomeRoadLinkVM
|
||
Permanent []HomeRoadLinkVM
|
||
Contacts []HomeRoadContactVM
|
||
}
|
||
|
||
func firstHomeRoadURL(values ...string) string {
|
||
for _, value := range values {
|
||
if value = strings.TrimSpace(value); value != "" {
|
||
return value
|
||
}
|
||
}
|
||
return "/"
|
||
}
|
||
|
||
// BuildHomeRoadPageVM 使用服务端动态配置组装“回家的路”页面。
|
||
func BuildHomeRoadPageVM(cfg AppConfigVM) HomeRoadPageVM {
|
||
mainURL := firstHomeRoadURL(cfg.NewURLAddr, cfg.ForeverURLAddr)
|
||
routes := make([]HomeRoadLinkVM, 0, 3)
|
||
for _, item := range cfg.NavPageList {
|
||
if len(routes) == 3 {
|
||
break
|
||
}
|
||
if url := strings.TrimSpace(item.URL); url != "" {
|
||
routes = append(routes, HomeRoadLinkVM{Label: fmt.Sprintf("备用地址 %02d", len(routes)+1), URL: url})
|
||
}
|
||
}
|
||
for _, url := range []string{cfg.NewURLAddr, cfg.NewURLAddr1, cfg.NewURLAddr2} {
|
||
if len(routes) == 3 {
|
||
break
|
||
}
|
||
if url = strings.TrimSpace(url); url != "" {
|
||
routes = append(routes, HomeRoadLinkVM{Label: fmt.Sprintf("备用地址 %02d", len(routes)+1), URL: url})
|
||
}
|
||
}
|
||
for len(routes) < 3 {
|
||
routes = append(routes, HomeRoadLinkVM{Label: fmt.Sprintf("备用地址 %02d", len(routes)+1), URL: mainURL})
|
||
}
|
||
|
||
permanent := make([]HomeRoadLinkVM, 0, 3)
|
||
for _, item := range []HomeRoadLinkVM{
|
||
{Label: "永久地址", URL: cfg.ForeverURLAddr},
|
||
{Label: "永久中转页", URL: cfg.NewURLAddr},
|
||
{Label: "最新中转页(免翻墙)", URL: cfg.NewURLAddr1},
|
||
} {
|
||
item.URL = strings.TrimSpace(item.URL)
|
||
if item.URL != "" {
|
||
permanent = append(permanent, item)
|
||
}
|
||
}
|
||
|
||
email := strings.TrimSpace(cfg.GmailAddr)
|
||
emailURL := ""
|
||
if email != "" {
|
||
emailURL = "mailto:" + email
|
||
}
|
||
contacts := []HomeRoadContactVM{
|
||
{Title: "✉ 邮箱自动回复", Description: "发送任意邮件到下方地址,30秒内自动回复当前所有可用入口的最新汇总。", Action: firstHomeRoadURL(email, "huangguoaiai@gmail.com") + " →", URL: firstHomeRoadURL(emailURL, "mailto:huangguoaiai@gmail.com")},
|
||
{Title: "➤ TG 官方交流群", Description: "获取域名变更通知的首选渠道,实时播报并加入用户互助社区。", Action: "立即订阅最新动态 →", URL: firstHomeRoadURL(cfg.TGGroup, "/")},
|
||
{Title: "◆ 官方商务合作", Description: "联系官方商务合作,洽谈商务事宜,精诚合作,财富共赢。", Action: "立即联系 →", URL: firstHomeRoadURL(cfg.Telegram, "/")},
|
||
{Title: "𝕏 推特社区", Description: "关注官方推特社区,第一时间获取地址变更与官方公告。", Action: "快速访问 →", URL: firstHomeRoadURL(cfg.TwitterAddr, "/")},
|
||
}
|
||
|
||
return HomeRoadPageVM{MainURL: mainURL, Routes: routes, Permanent: permanent, Contacts: contacts}
|
||
}
|