This commit is contained in:
nikk gitanes
2024-06-12 22:46:53 +03:00
2 changed files with 23 additions and 25 deletions

View File

@@ -218,11 +218,13 @@ cd server; swag init -g web/server.go
swag fmt swag fmt
``` ```
### MSX Install ### Smart TV (using Media Station X)
Open msx and goto: Settings -> Start Parameter -> Setup 1. Install **Media Station X** on your Smart TV (see [platform support](https://msx.benzac.de/info/?tab=PlatformSupport))
Enter current ip address and port of server _e.g. 127.0.0.1:8090_ 2. Open it and go to: **Settings -> Start Parameter -> Setup**
3. Enter current ip and port of the TorrServe(r), e.g. `127.0.0.1:8090`
## API ## API

View File

@@ -56,7 +56,7 @@ func SetupRoute(r gin.IRouter) {
rsp(c, r, e) rsp(c, r, e)
}) })
authorized.GET("/msx/start.json", func(c *gin.Context) { authorized.GET("/msx/start.json", func(c *gin.Context) {
c.JSON(200, map[string]any{ c.JSON(http.StatusOK, map[string]any{
"name": "TorrServer", "name": "TorrServer",
"version": version.Version, "version": version.Version,
"parameter": param, "parameter": param,
@@ -80,7 +80,7 @@ func SetupRoute(r gin.IRouter) {
} }
} }
} }
c.JSON(200, r) c.JSON(http.StatusOK, r)
}) })
authorized.POST("/msx/trn", func(c *gin.Context) { authorized.POST("/msx/trn", func(c *gin.Context) {
var r struct { var r struct {
@@ -114,7 +114,7 @@ func SetupRoute(r gin.IRouter) {
r.R.S, r.R.D = http.StatusOK, map[string]any{"action": j.Data, "data": r.R.D} r.R.S, r.R.D = http.StatusOK, map[string]any{"action": j.Data, "data": r.R.D}
} }
r.R.T = http.StatusText(r.R.S) r.R.T = http.StatusText(r.R.S)
c.JSON(200, &r) c.JSON(http.StatusOK, &r)
}) })
authorized.Any("/msx/proxy", func(c *gin.Context) { authorized.Any("/msx/proxy", func(c *gin.Context) {
if u := c.Query("url"); u == "" { if u := c.Query("url"); u == "" {
@@ -132,36 +132,32 @@ func SetupRoute(r gin.IRouter) {
} }
}) })
authorized.GET("/msx/imdb/:id", func(c *gin.Context) { authorized.GET("/msx/imdb/:id", func(c *gin.Context) {
i, l, j := strings.TrimPrefix(c.Param("id"), "/"), "", false i, j := strings.TrimPrefix(c.Param("id"), "/"), false
if j = strings.HasSuffix(i, ".json"); !j { if j = strings.HasSuffix(i, ".json"); !j {
i += ".json" i += ".json"
} }
if r, e := http.Get("https://v2.sg.media-imdb.com/suggestion/h/" + i); e == nil { if r, e := http.Get("https://v2.sg.media-imdb.com/suggestion/h/" + i); e != nil || r.StatusCode != http.StatusOK || j {
if r.StatusCode == http.StatusOK { rsp(c, r, e)
} else {
var j struct { var j struct {
D []struct{ I struct{ ImageUrl string } } D []struct{ I struct{ ImageUrl string } }
} }
if e = json.NewDecoder(r.Body).Decode(&j); e == nil && len(j.D) > 0 { if e = json.NewDecoder(r.Body).Decode(&j); e != nil {
l = j.D[0].I.ImageUrl c.AbortWithError(http.StatusInternalServerError, e)
} } else if len(j.D) == 0 || j.D[0].I.ImageUrl == "" {
}
r.Body.Close()
}
if j {
c.JSON(200, l)
} else if l == "" {
c.Status(http.StatusNotFound) c.Status(http.StatusNotFound)
} else { } else {
c.Redirect(http.StatusMovedPermanently, l) c.Redirect(http.StatusMovedPermanently, j.D[0].I.ImageUrl)
}
} }
}) })
// Files: // Files:
authorized.StaticFS("/files/", gin.Dir(filepath.Join(settings.Path, files), true)) authorized.StaticFS("/files/", gin.Dir(filepath.Join(settings.Path, files), true))
authorized.GET("/files", func(c *gin.Context) { authorized.GET("/files", func(c *gin.Context) {
if l, e := os.Readlink(filepath.Join(settings.Path, files)); e == nil || os.IsNotExist(e) { if l, e := os.Readlink(filepath.Join(settings.Path, files)); e == nil || os.IsNotExist(e) {
c.JSON(200, l) c.JSON(http.StatusOK, l)
} else { } else {
c.AbortWithError(http.StatusInternalServerError, e) c.JSON(http.StatusInternalServerError, e.Error)
} }
}) })
authorized.POST("/files", func(c *gin.Context) { authorized.POST("/files", func(c *gin.Context) {