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