mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
refactor and to go mod
This commit is contained in:
51
server/web/api/cache.go
Normal file
51
server/web/api/cache.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"server/torr"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//Action: get
|
||||
type cacheReqJS struct {
|
||||
requestI
|
||||
Hash string `json:"hash,omitempty"`
|
||||
}
|
||||
|
||||
func cache(c *gin.Context) {
|
||||
var req cacheReqJS
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusBadRequest)
|
||||
switch req.Action {
|
||||
case "get":
|
||||
{
|
||||
getCache(req, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getCache(req cacheReqJS, c *gin.Context) {
|
||||
if req.Hash == "" {
|
||||
c.AbortWithError(http.StatusBadRequest, errors.New("hash is empty"))
|
||||
return
|
||||
}
|
||||
tor := torr.GetTorrent(req.Hash)
|
||||
|
||||
if tor != nil {
|
||||
st := tor.CacheState()
|
||||
if st == nil {
|
||||
c.JSON(200, struct{}{})
|
||||
} else {
|
||||
c.JSON(200, st)
|
||||
}
|
||||
} else {
|
||||
c.Status(http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user