refactor and to go mod

This commit is contained in:
YouROK
2021-02-18 16:56:55 +03:00
parent 0e49a98626
commit 94f212fa75
50 changed files with 13 additions and 29 deletions

55
server/web/api/route.go Normal file
View File

@@ -0,0 +1,55 @@
package api
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
sets "server/settings"
"server/torr"
"server/version"
)
type requestI struct {
Action string `json:"action,omitempty"`
}
func SetupRoute(route *gin.Engine) {
route.GET("/echo", echo)
route.GET("/shutdown", shutdown)
route.POST("/settings", settings)
route.POST("/torrents", torrents)
route.POST("/torrent/upload", torrentUpload)
route.POST("/cache", cache)
route.HEAD("/stream", stream)
route.HEAD("/stream/*fname", stream)
route.GET("/stream", stream)
route.GET("/stream/*fname", stream)
route.POST("/viewed", viewed)
route.GET("/playlistall/all.m3u", allPlayList)
route.GET("/playlist", playList)
route.GET("/playlist/*fname", playList)
}
func echo(c *gin.Context) {
c.String(200, "%v", version.Version)
}
func shutdown(c *gin.Context) {
if sets.ReadOnly {
c.Status(http.StatusForbidden)
return
}
c.Status(200)
go func() {
time.Sleep(1000)
torr.Shutdown()
}()
}