add: frontend

This commit is contained in:
Nite07 2024-11-29 03:55:45 +08:00
parent 47f6ba2104
commit 45c9bd3b40

View File

@ -31,13 +31,13 @@ func initRoute(app *gin.Engine) {
func initFrontend(app *gin.Engine) {
app.Static("/static", "server/static")
layoutFiles, err := filepath.Glob("server/templates/layouts/*.tmpl")
layoutFiles, err := filepath.Glob("server/templates/layouts/*.html")
if err != nil {
log.Logger.Fatal("Error loading layout templates", zap.Error(err))
return
}
rootFiles, err := filepath.Glob("server/templates/*.tmpl")
rootFiles, err := filepath.Glob("server/templates/*.html")
if err != nil {
log.Logger.Fatal("Error loading root templates", zap.Error(err))
return
@ -48,10 +48,10 @@ func initFrontend(app *gin.Engine) {
app.GET("/", func(ctx *gin.Context) {
infos, err := crawler.GetSteam250MonthTop50()
if err != nil {
ctx.HTML(500, "500.tmpl", err)
ctx.HTML(500, "500.html", err)
return
}
ctx.HTML(200, "index.tmpl", gin.H{
ctx.HTML(200, "index.html", gin.H{
"MonthTop": infos,
})
})
@ -60,22 +60,22 @@ func initFrontend(app *gin.Engine) {
idStr := ctx.Param("id")
id, err := primitive.ObjectIDFromHex(idStr)
if err != nil {
ctx.HTML(400, "400.tmpl", nil)
ctx.HTML(400, "400.html", nil)
return
}
info, err := db.GetGameInfoByID(id)
if err != nil {
ctx.HTML(500, "500.tmpl", err)
ctx.HTML(500, "500.html", err)
return
}
games, err := db.GetGameItemsByIDs(info.GameIDs)
if err != nil {
ctx.HTML(500, "500.tmpl", err)
ctx.HTML(500, "500.html", err)
return
}
info.Games = games
//TODO: fix this
ctx.HTML(200, "game.tmpl", info)
ctx.HTML(200, "game.html", info)
})
}