From f9d7e888e6a5eb683448ee6ffaf172dd830c5317 Mon Sep 17 00:00:00 2001 From: damiva <96115589+damiva@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:33:28 +0300 Subject: [PATCH] MSX: extended search posters in IMDB (#418) --- server/web/msx/msx.go | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/server/web/msx/msx.go b/server/web/msx/msx.go index 7b892e9..eb991d3 100644 --- a/server/web/msx/msx.go +++ b/server/web/msx/msx.go @@ -56,7 +56,7 @@ func SetupRoute(r gin.IRouter) { rsp(c, r, e) }) authorized.GET("/msx/start.json", func(c *gin.Context) { - c.JSON(200, map[string]any{ + c.JSON(http.StatusOK, map[string]any{ "name": "TorrServer", "version": version.Version, "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) { 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.T = http.StatusText(r.R.S) - c.JSON(200, &r) + c.JSON(http.StatusOK, &r) }) authorized.Any("/msx/proxy", func(c *gin.Context) { if u := c.Query("url"); u == "" { @@ -132,36 +132,32 @@ func SetupRoute(r gin.IRouter) { } }) 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 { i += ".json" } - if r, e := http.Get("https://v2.sg.media-imdb.com/suggestion/h/" + i); e == nil { - if r.StatusCode == http.StatusOK { - var j struct { - D []struct{ I struct{ ImageUrl string } } - } - if e = json.NewDecoder(r.Body).Decode(&j); e == nil && len(j.D) > 0 { - l = j.D[0].I.ImageUrl - } - } - r.Body.Close() - } - if j { - c.JSON(200, l) - } else if l == "" { - c.Status(http.StatusNotFound) + if r, e := http.Get("https://v2.sg.media-imdb.com/suggestion/h/" + i); e != nil || r.StatusCode != http.StatusOK || j { + rsp(c, r, e) } else { - c.Redirect(http.StatusMovedPermanently, l) + var j struct { + D []struct{ I struct{ ImageUrl string } } + } + if e = json.NewDecoder(r.Body).Decode(&j); e != nil { + c.AbortWithError(http.StatusInternalServerError, e) + } else if len(j.D) == 0 || j.D[0].I.ImageUrl == "" { + c.Status(http.StatusNotFound) + } else { + c.Redirect(http.StatusMovedPermanently, j.D[0].I.ImageUrl) + } } }) // Files: authorized.StaticFS("/files/", gin.Dir(filepath.Join(settings.Path, files), true)) authorized.GET("/files", func(c *gin.Context) { 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 { - c.AbortWithError(http.StatusInternalServerError, e) + c.JSON(http.StatusInternalServerError, e.Error) } }) authorized.POST("/files", func(c *gin.Context) {