Skip to content

Commit 4e819cb

Browse files
committed
feat: add static files and update season handling for 2024
1 parent 1019b87 commit 4e819cb

File tree

8 files changed

+2119
-4
lines changed

8 files changed

+2119
-4
lines changed

internal/handler/group_rank_info.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@ import (
88
)
99

1010
const (
11-
GroupRankInfoStatic = true
11+
GroupRankInfoStatic = false
1212
GroupRankInfoCacheControl = "public, max-age=5"
1313
)
1414

15+
var SeasonGroupRankInfoMap = map[string][]byte{
16+
"2024": static.GroupRankInfoBytes2024,
17+
}
18+
1519
func GroupRankInfoHandler(c iris.Context) {
20+
season := c.URLParam("season")
21+
if data, ok := SeasonGroupRankInfoMap[season]; ok {
22+
c.Header("Cache-Control", "public, max-age=60")
23+
c.ContentType("application/json")
24+
c.Write(data)
25+
return
26+
}
27+
1628
if GroupRankInfoStatic {
1729
c.Header("Cache-Control", "public, max-age=60")
1830
c.ContentType("application/json")

internal/handler/rank_list.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,29 @@ type CompleteForm struct {
3333
InitialCoinTotal int `json:"initialCoinTotal"`
3434
}
3535

36+
var SeasonCompleteFormMap = map[string][]byte{
37+
"2024": static.CompleteFormBytes2024,
38+
}
39+
40+
var SeasonRankScoreMap = map[string][]byte{
41+
"2024": static.RankScoreBytes2024,
42+
}
43+
3644
func RankListHandler(c iris.Context) {
45+
season := c.URLParam("season")
46+
var completeFormBytes []byte
47+
var rankScoreBytes []byte
48+
if data, ok := SeasonCompleteFormMap[season]; ok {
49+
completeFormBytes = data
50+
} else {
51+
completeFormBytes = static.CompleteFormBytes
52+
}
53+
if data, ok := SeasonRankScoreMap[season]; ok {
54+
rankScoreBytes = data
55+
} else {
56+
rankScoreBytes = static.RankScoreBytes
57+
}
58+
3759
schoolName := c.URLParam("school_name")
3860
if schoolName == "" {
3961
c.StatusCode(400)
@@ -44,7 +66,7 @@ func RankListHandler(c iris.Context) {
4466
completedFormMap, ok := svc.Cache.Get("completed_form")
4567
if !ok {
4668
completedFormJson := make([]CompleteForm, 0)
47-
err := json.Unmarshal(static.CompleteFormBytes, &completedFormJson)
69+
err := json.Unmarshal(completeFormBytes, &completedFormJson)
4870
if err != nil {
4971
log.Printf("Failed to parse completed form: %v\n", err)
5072
c.StatusCode(500)
@@ -69,7 +91,7 @@ func RankListHandler(c iris.Context) {
6991
rankScoreMap, ok := svc.Cache.Get("rank_score")
7092
if !ok {
7193
rankScoreJson := make([]RankScoreItem, 0)
72-
err := json.Unmarshal(static.RankScoreBytes, &rankScoreJson)
94+
err := json.Unmarshal(rankScoreBytes, &rankScoreJson)
7395
if err != nil {
7496
log.Printf("Failed to parse rank list: %v\n", err)
7597
c.StatusCode(500)

internal/handler/schedule.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ import (
88
)
99

1010
const (
11-
ScheduleStatic = true
11+
ScheduleStatic = false
1212
ScheduleCacheControl = "public, max-age=5"
1313
)
1414

15+
// SeasonScheduleMap 赛季赛程映射
16+
var SeasonScheduleMap = map[string][]byte{
17+
"2024": static.ScheduleBytes2024,
18+
}
19+
1520
func ScheduleHandler(c iris.Context) {
21+
season := c.URLParam("season")
22+
if data, ok := SeasonScheduleMap[season]; ok {
23+
c.Header("Cache-Control", "public, max-age=60")
24+
c.ContentType("application/json")
25+
c.Write(data)
26+
return
27+
}
28+
1629
if ScheduleStatic {
1730
c.Header("Cache-Control", "public, max-age=60")
1831
c.ContentType("application/json")

internal/static/load_embed.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package static
22

33
import _ "embed"
44

5+
// 公共的静态文件
6+
57
//go:embed complete_form.json
68
var CompleteFormBytes []byte
79

@@ -13,3 +15,17 @@ var ScheduleBytes []byte
1315

1416
//go:embed group_rank_info.json
1517
var GroupRankInfoBytes []byte
18+
19+
// 2024 赛季的静态文件
20+
21+
//go:embed season_2024/complete_form.json
22+
var CompleteFormBytes2024 []byte
23+
24+
//go:embed season_2024/rank_score.json
25+
var RankScoreBytes2024 []byte
26+
27+
//go:embed season_2024/schedule.json
28+
var ScheduleBytes2024 []byte
29+
30+
//go:embed season_2024/group_rank_info.json
31+
var GroupRankInfoBytes2024 []byte

0 commit comments

Comments
 (0)