From 262ce70998fa52dec3120589f51c47e96fb96df4 Mon Sep 17 00:00:00 2001
From: 905086 <k2049@qq.com>
Date: Tue, 03 Nov 2026 17:04:19 +0800
Subject: [PATCH] feat: 完成游戏盒子前后端基础功能开发
---
server/main.go | 76 ++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/server/main.go b/server/main.go
new file mode 100644
index 0000000..77abc99
--- /dev/null
+++ b/server/main.go
@@ -0,0 +1,76 @@
+package main
+
+import (
+ "gamebox-server/config"
+ "gamebox-server/handlers"
+ "gamebox-server/middleware"
+
+ "github.com/gin-gonic/gin"
+)
+
+func main() {
+ config.InitDB()
+
+ r := gin.Default()
+ r.MaxMultipartMemory = 64 << 20 // 64MB
+
+ // 静态资源(封面/视频/游戏包)
+ r.Static("/static", "./uploads")
+
+ // ---------- 客户端 API ----------
+ api := r.Group("/api")
+ {
+ api.GET("/captcha", handlers.GetCaptcha)
+ api.POST("/register", handlers.Register)
+ api.POST("/login", handlers.Login)
+ api.POST("/reset_password", handlers.ResetPassword)
+ api.GET("/categories", handlers.GetCategories)
+ api.GET("/games", handlers.GetGames)
+ api.GET("/banners", handlers.GetBanners)
+ api.GET("/tools", handlers.GetTools)
+ api.GET("/announcements", handlers.GetAnnouncements)
+ api.GET("/games/:id", handlers.GetGameDetail) // 支持可选登录
+
+ auth := api.Group("", middleware.UserAuth())
+ {
+ auth.GET("/user/info", handlers.GetUserInfo)
+ auth.POST("/favorites", handlers.ToggleFavorite)
+ auth.GET("/favorites", handlers.GetFavorites)
+ auth.POST("/library", handlers.AddToLibrary)
+ auth.GET("/library", handlers.GetLibrary)
+ auth.DELETE("/library/:gameId", handlers.RemoveFromLibrary)
+ auth.GET("/download/:id", handlers.GetDownloadInfo)
+ auth.POST("/keys/activate", handlers.ActivateKey)
+ }
+ }
+
+ // ---------- 管理后台 ----------
+ r.GET("/admin", func(c *gin.Context) {
+ c.File("./admin/index.html")
+ })
+ admin := r.Group("/admin/api")
+ {
+ admin.POST("/login", handlers.AdminLogin)
+
+ a := admin.Group("", middleware.AdminAuth())
+ {
+ a.GET("/stats", handlers.AdminStats)
+ a.GET("/keys", handlers.ListKeys)
+ a.POST("/keys/generate", handlers.GenerateKeys)
+ a.POST("/keys/:id/reset", handlers.ResetKey)
+ a.DELETE("/keys/:id", handlers.DeleteKey)
+
+ a.GET("/games", handlers.AdminListGames)
+ a.POST("/games", handlers.AdminSaveGame)
+ a.DELETE("/games/:id", handlers.AdminDeleteGame)
+
+ a.GET("/categories", handlers.AdminListCategories)
+ a.POST("/categories", handlers.AdminSaveCategory)
+ a.DELETE("/categories/:id", handlers.AdminDeleteCategory)
+
+ a.POST("/upload", handlers.UploadFile)
+ }
+ }
+
+ r.Run(":8080")
+}
--
Gitblit v1.10.0