Files

52 lines
1.2 KiB
Go
Raw Permalink Normal View History

2023-07-04 23:47:01 +08:00
package main
import (
"net/http"
"path/filepath"
"github.com/gin-gonic/gin"
)
func main() {
initMovie()
// 初始化缓存系统512MB内存缓存TTL 60分钟
InitCache(512, 60)
2023-07-04 23:47:01 +08:00
2025-08-14 00:28:29 +08:00
// 设置为发布模式
gin.SetMode(gin.ReleaseMode)
2023-07-04 23:47:01 +08:00
eg := gin.Default()
eg.Use(Cors())
eg.Use(gin.Recovery())
// 使用支持 Range 请求的视频流处理器(优化大文件加载性能)
// 这个处理器会处理所有 /res/ 下的文件,包括视频和缩略图
eg.GET("/res/:filename", StreamVideo)
2023-07-04 23:47:01 +08:00
eg.Static("/static", "../build/static")
2023-07-10 00:50:11 +08:00
eg.StaticFile("/manifest.json", "../build/manifest.json")
eg.StaticFile("/favicon.ico", "../build/favicon.ico")
eg.StaticFile("/logo512.png", "../build/logo512.png")
eg.StaticFile("/logo192.png", "../build/logo192.png")
2023-07-04 23:47:01 +08:00
eg.NoRoute(func(c *gin.Context) {
path := c.Request.URL.Path
if filepath.Ext(path) == "" {
c.File("../build/index.html")
} else {
c.Status(http.StatusNotFound)
}
})
2023-07-09 03:00:29 +08:00
api := eg.Group("/api")
api.POST("/login", loginHandler)
2023-07-04 23:47:01 +08:00
movie := eg.Group("movie")
2023-07-09 03:00:29 +08:00
movie.Use(jwtMiddleware())
2025-06-02 21:29:31 +08:00
movie.GET("/list/category", GetCategoryList)
movie.GET("/list", MovieList)
movie.POST("/rename", PostRename)
movie.POST("/delete", PostDelete)
2023-07-04 23:47:01 +08:00
2024-06-12 12:51:12 +08:00
eg.Run("0.0.0.0:4444")
}