// Copyright 2022 E99p1ant. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. package route import ( "github.com/sirupsen/logrus" "github.com/tamakyi/TamaBox/internal/context" "github.com/tamakyi/TamaBox/internal/i18n" "github.com/tamakyi/TamaBox/internal/stats" ) func Home(ctx context.Context) { if v, err := stats.Get(ctx.Request().Context()); err != nil { logrus.WithContext(ctx.Request().Context()).WithError(err).Warn("Failed to compute site stats") } else { ctx.Data["SiteStats"] = v } ctx.Success("home") } // SiteStatsAPI 返回首页"提问箱信息统计"的 JSON(服务端 30 分钟缓存), // 供前端 setInterval 定时刷新,避免重新加载整页。 func SiteStatsAPI(ctx context.Context) error { v, err := stats.Get(ctx.Request().Context()) if err != nil { return ctx.JSONError(50000, i18n.T(ctx.Lang(), "home.errStats")) } return ctx.JSON(v) } func Sponsor(ctx context.Context) { ctx.Success("sponsor") } func AboutMe(ctx context.Context) { ctx.Success("about-me") } // Rules 社区规则页。 // // 公开可访问:处置箱主时可以直接引用条款,不必每次临时解释; // 箱主也能在被处置前就知道边界在哪。内容是静态 i18n 文案,不走数据库。 func Rules(ctx context.Context) { ctx.SetTitle(i18n.T(ctx.Lang(), "rules.title")) ctx.Success("rules") } func ChangeLogs(ctx context.Context) { ctx.Success("change-logs") }