From ff1c05a6bf6905cb4f6fe2c7a1dcfc792e0e280b Mon Sep 17 00:00:00 2001 From: YouROK <8YouROK8@mail.ru> Date: Sun, 29 Jan 2023 20:04:48 +0300 Subject: [PATCH] add rutor api --- server/go.mod | 2 ++ server/go.sum | 8 ++++++++ server/settings/btsets.go | 3 +++ server/web/api/route.go | 1 + server/web/api/settings.go | 6 +++++- server/web/server.go | 3 +++ 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/server/go.mod b/server/go.mod index 79088ec..7b6ec0b 100644 --- a/server/go.mod +++ b/server/go.mod @@ -3,6 +3,7 @@ module server go 1.18 require ( + github.com/agnivade/levenshtein v1.1.1 github.com/alexflint/go-arg v1.4.3 github.com/anacrolix/dms v1.5.0 github.com/anacrolix/log v0.13.2-0.20221123232138-02e2764801c3 @@ -12,6 +13,7 @@ require ( github.com/gin-contrib/cors v1.4.0 github.com/gin-contrib/location v0.0.2 github.com/gin-gonic/gin v1.8.2 + github.com/kljensen/snowball v0.6.0 github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 github.com/pkg/errors v0.9.1 go.etcd.io/bbolt v1.3.6 diff --git a/server/go.sum b/server/go.sum index b956373..c3bd987 100644 --- a/server/go.sum +++ b/server/go.sum @@ -14,6 +14,8 @@ github.com/RoaringBitmap/roaring v1.2.1 h1:58/LJlg/81wfEHd5L9qsHduznOIhyv4qb1yWc github.com/RoaringBitmap/roaring v1.2.1/go.mod h1:icnadbWcNyfEHlYdr+tDlOTih1Bf/h+rzPpv4sbomAA= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= +github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0 h1:byYvvbfSo3+9efR4IeReh77gVs4PnNDR3AMOE9NJ7a0= github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0/go.mod h1:q37NoqncT41qKc048STsifIt69LfUJ8SrWWcz/yam5k= github.com/alecthomas/assert/v2 v2.0.0-alpha3 h1:pcHeMvQ3OMstAWgaeaXIAL8uzB9xMm2zlxt+/4ml8lk= @@ -92,6 +94,8 @@ github.com/anacrolix/upnp v0.1.3-0.20220123035249-922794e51c96/go.mod h1:Wa6n8cY github.com/anacrolix/utp v0.1.0 h1:FOpQOmIwYsnENnz7tAGohA+r6iXpRjrq8ssKSre2Cp4= github.com/anacrolix/utp v0.1.0/go.mod h1:MDwc+vsGEq7RMw6lr2GKOEqjWny5hO5OZXRVNaBJ2Dk= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/benbjohnson/immutable v0.2.0/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI= @@ -113,6 +117,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -229,6 +235,8 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kljensen/snowball v0.6.0 h1:6DZLCcZeL0cLfodx+Md4/OLC6b/bfurWUOUGs1ydfOU= +github.com/kljensen/snowball v0.6.0/go.mod h1:27N7E8fVU5H68RlUmnWwZCfxgt4POBJfENGMvNRhldw= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= diff --git a/server/settings/btsets.go b/server/settings/btsets.go index bad2116..5c57696 100644 --- a/server/settings/btsets.go +++ b/server/settings/btsets.go @@ -31,6 +31,9 @@ type BTSets struct { EnableDLNA bool FriendlyName string + // Rutor + EnableRutorSearch bool + // BT Config EnableIPv6 bool DisableTCP bool diff --git a/server/web/api/route.go b/server/web/api/route.go index 9860aa5..771aaba 100644 --- a/server/web/api/route.go +++ b/server/web/api/route.go @@ -39,6 +39,7 @@ func SetupRoute(route *gin.RouterGroup) { route.GET("/playlist/*fname", playList) route.GET("/download/:size", download) + route.GET("/search/*query", rutorSearch) } func shutdown(c *gin.Context) { diff --git a/server/web/api/settings.go b/server/web/api/settings.go index afdeb30..42ae959 100644 --- a/server/web/api/settings.go +++ b/server/web/api/settings.go @@ -2,6 +2,7 @@ package api import ( "net/http" + "server/rutor" "github.com/gin-gonic/gin" "github.com/pkg/errors" @@ -11,7 +12,7 @@ import ( "server/torr" ) -//Action: get, set, def +// Action: get, set, def type setsReqJS struct { requestI Sets *sets.BTSets `json:"sets,omitempty"` @@ -34,11 +35,14 @@ func settings(c *gin.Context) { if req.Sets.EnableDLNA { dlna.Start() } + rutor.Stop() + rutor.Start() c.Status(200) return } else if req.Action == "def" { torr.SetDefSettings() dlna.Stop() + rutor.Stop() c.Status(200) return } diff --git a/server/web/server.go b/server/web/server.go index 6a75da6..f05caa4 100644 --- a/server/web/server.go +++ b/server/web/server.go @@ -2,6 +2,7 @@ package web import ( "net" + "server/rutor" "sort" "github.com/gin-contrib/cors" @@ -37,6 +38,8 @@ func Start(port string) { waitChan <- err return } + rutor.Start() + gin.SetMode(gin.ReleaseMode) //corsCfg := cors.DefaultConfig()