This commit is contained in:
damiva
2024-05-17 18:02:24 +03:00
committed by GitHub
parent fb22cfa6c9
commit 65e08ebe6b

View File

@@ -2,6 +2,8 @@ package msx
import ( import (
"encoding/json" "encoding/json"
"errors"
"io/fs"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@@ -22,18 +24,39 @@ var parameter = param
func SetupRoute(r gin.IRouter) { func SetupRoute(r gin.IRouter) {
authorized := r.Group("/", auth.CheckAuth()) authorized := r.Group("/", auth.CheckAuth())
authorized.GET("/msx/inf", func(c *gin.Context) { authorized.GET("/msx/stg", func(c *gin.Context) {
r := map[string]any{"version": version.Version, "search": settings.BTsets.EnableRutorSearch}
if p, o := c.GetQuery("parameter"); o { if p, o := c.GetQuery("parameter"); o {
if p == "" { if p == "" {
p = param p = param
} }
parameter = p parameter = p
} }
r := map[string]any{"version": version.Version, "search": settings.BTsets.EnableRutorSearch} r["parameter"] = parameter
if f, e := os.Stat(files); e == nil { if p, o := c.GetQuery(files); o {
r[files] = !f.IsDir() e := os.Remove(files)
if os.IsNotExist(e) {
e = nil
}
if e == nil && p != "" {
var f fs.FileInfo
if f, e = os.Stat(p); e == nil {
if !f.IsDir() {
e = errors.New(p + " is not a folder")
} else {
e = os.Symlink(p, files)
}
}
}
if e == nil {
r[files] = p
} else {
r = map[string]any{"error": e.Error()}
}
} else if l, e := os.Readlink(files); e == nil {
r[files] = l
} else if !os.IsNotExist(e) { } else if !os.IsNotExist(e) {
r[files] = e.Error() r["error"] = e.Error()
} }
c.JSON(200, r) c.JSON(200, r)
}) })
@@ -76,8 +99,8 @@ func SetupRoute(r gin.IRouter) {
authorized.GET("/msx/start.json", func(c *gin.Context) { authorized.GET("/msx/start.json", func(c *gin.Context) {
c.JSON(200, map[string]any{"name": "TorrServer", "version": version.Version, "parameter": parameter}) c.JSON(200, map[string]any{"name": "TorrServer", "version": version.Version, "parameter": parameter})
}) })
authorized.GET("/msx/:pth", func(c *gin.Context) { authorized.GET("/msx/", func(c *gin.Context) {
proxy(c, "https://damiva.github.io"+c.Request.URL.Path) proxy(c, "https://damiva.github.io"+c.Request.URL.EscapedPath())
}) })
authorized.GET("/imdb/:id", func(c *gin.Context) { authorized.GET("/imdb/:id", func(c *gin.Context) {
i, l, j := c.Param("id"), "", false i, l, j := c.Param("id"), "", false