diff --git a/server/dlna/list.go b/server/dlna/list.go index f16eafa..fa216a4 100644 --- a/server/dlna/list.go +++ b/server/dlna/list.go @@ -20,7 +20,6 @@ import ( ) func getRoot() (ret []interface{}) { - // Torrents Object tObj := upnpav.Object{ ID: "%2FTR", @@ -37,18 +36,16 @@ func getRoot() (ret []interface{}) { ret = append(ret, cnt) return - } func getTorrents() (ret []interface{}) { - torrs := torr.ListTorrent() // sort by title as in cds SortCaps sort.Slice(torrs, func(i, j int) bool { return torrs[i].Title < torrs[j].Title }) - var vol = 0 + vol := 0 for _, t := range torrs { vol++ obj := upnpav.Object{ @@ -251,7 +248,6 @@ func getLink(host, path string) string { } func getObjFromTorrent(path, parent, host string, torr *torr.Torrent, file *state.TorrentFileStat) (ret interface{}) { - mime, err := mt.MimeTypeByPath(file.Path) if err != nil { if settings.BTsets.EnableDebug { diff --git a/server/log/log.go b/server/log/log.go index b92343d..ae730ec 100644 --- a/server/log/log.go +++ b/server/log/log.go @@ -12,20 +12,24 @@ import ( "github.com/gin-gonic/gin" ) -var logPath = "" -var webLogPath = "" +var ( + logPath = "" + webLogPath = "" +) var webLog *log.Logger -var logFile *os.File -var webLogFile *os.File +var ( + logFile *os.File + webLogFile *os.File +) func Init(path, webpath string) { webLogPath = webpath logPath = path if webpath != "" { - ff, err := os.OpenFile(webLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + ff, err := os.OpenFile(webLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666) if err != nil { TLogln("Error create web log file:", err) } else { @@ -40,7 +44,7 @@ func Init(path, webpath string) { os.Remove(path) } } - ff, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + ff, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666) if err != nil { TLogln("Error create log file:", err) return @@ -87,7 +91,7 @@ func WebLogger() gin.HandlerFunc { return } body := "" - //save body if not form or file + // save body if not form or file if !strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data") { body, _ := ioutil.ReadAll(c.Request.Body) c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) diff --git a/server/mimetype/mimetype.go b/server/mimetype/mimetype.go index c9b91f7..03685aa 100644 --- a/server/mimetype/mimetype.go +++ b/server/mimetype/mimetype.go @@ -10,7 +10,6 @@ import ( ) func init() { - // Add a minimal number of mime types to augment go's built in types // for environments which don't have access to a mime.types file (e.g. // Termux on android) diff --git a/server/rutor/mem_test.go b/server/rutor/mem_test.go index 273314f..70e1400 100644 --- a/server/rutor/mem_test.go +++ b/server/rutor/mem_test.go @@ -6,12 +6,13 @@ import ( "fmt" "os" "path/filepath" - "server/rutor/models" "testing" + + "server/rutor/models" ) func TestParseChannel(t *testing.T) { - var channel = make(chan *models.TorrentDetails, 0) + channel := make(chan *models.TorrentDetails, 0) var ftors []*models.TorrentDetails go func() { for torr := range channel { diff --git a/server/rutor/rutor.go b/server/rutor/rutor.go index fb6eaed..5565e59 100644 --- a/server/rutor/rutor.go +++ b/server/rutor/rutor.go @@ -3,21 +3,23 @@ package rutor import ( "compress/flate" "encoding/json" - "github.com/agnivade/levenshtein" "io" "net/http" "os" "path/filepath" + "sort" + "strconv" + "strings" + "time" + + "github.com/agnivade/levenshtein" + "server/log" "server/rutor/models" "server/rutor/torrsearch" "server/rutor/utils" "server/settings" utils2 "server/torr/utils" - "sort" - "strconv" - "strings" - "time" ) var ( diff --git a/server/rutor/torrsearch/tokenizer.go b/server/rutor/torrsearch/tokenizer.go index 58c3cff..be75275 100644 --- a/server/rutor/torrsearch/tokenizer.go +++ b/server/rutor/torrsearch/tokenizer.go @@ -18,6 +18,6 @@ func analyze(text string) []string { tokens := tokenize(text) tokens = lowercaseFilter(tokens) tokens = stopwordFilter(tokens) - //tokens = stemmerFilter(tokens) + // tokens = stemmerFilter(tokens) return tokens } diff --git a/server/settings/btsets.go b/server/settings/btsets.go index 5c57696..6dc4299 100644 --- a/server/settings/btsets.go +++ b/server/settings/btsets.go @@ -53,9 +53,7 @@ func (v *BTSets) String() string { return string(buf) } -var ( - BTsets *BTSets -) +var BTsets *BTSets func SetBTSets(sets *BTSets) { if ReadOnly { diff --git a/server/settings/db.go b/server/settings/db.go index 05c9c92..03ec985 100644 --- a/server/settings/db.go +++ b/server/settings/db.go @@ -16,7 +16,7 @@ type TDB struct { } func NewTDB() *TDB { - db, err := bolt.Open(filepath.Join(Path, "config.db"), 0666, &bolt.Options{Timeout: 5 * time.Second}) + db, err := bolt.Open(filepath.Join(Path, "config.db"), 0o666, &bolt.Options{Timeout: 5 * time.Second}) if err != nil { log.TLogln(err) return nil @@ -60,7 +60,6 @@ func (v *TDB) Get(xpath, name string) []byte { ret = buckt.Get([]byte(name)) return nil }) - if err != nil { log.TLogln("Error get sets", xpath+"/"+name, ", error:", err) } @@ -95,12 +94,10 @@ func (v *TDB) Set(xpath, name string, value []byte) { return buckt.Put([]byte(name), value) }) - if err != nil { log.TLogln("Error put sets", xpath+"/"+name, ", error:", err) log.TLogln("value:", value) } - } func (v *TDB) List(xpath string) []string { @@ -134,7 +131,6 @@ func (v *TDB) List(xpath string) []string { return nil }) - if err != nil { log.TLogln("Error list sets", xpath, ", error:", err) } @@ -169,9 +165,7 @@ func (v *TDB) Rem(xpath, name string) { return buckt.Delete([]byte(name)) }) - if err != nil { log.TLogln("Error rem sets", xpath+"/"+name, ", error:", err) } - } diff --git a/server/settings/migrate.go b/server/settings/migrate.go index d0ed0ed..e0c6ce1 100644 --- a/server/settings/migrate.go +++ b/server/settings/migrate.go @@ -11,9 +11,7 @@ import ( "server/web/api/utils" ) -var ( - dbTorrentsName = []byte("Torrents") -) +var dbTorrentsName = []byte("Torrents") type torrentOldDB struct { Name string @@ -29,7 +27,7 @@ func Migrate() { return } - db, err := bolt.Open(filepath.Join(Path, "torrserver.db"), 0666, nil) + db, err := bolt.Open(filepath.Join(Path, "torrserver.db"), 0o666, nil) if err != nil { return } diff --git a/server/settings/viewed.go b/server/settings/viewed.go index 55e4e73..bf02562 100644 --- a/server/settings/viewed.go +++ b/server/settings/viewed.go @@ -69,7 +69,7 @@ func ListViewed(hash string) []*Viewed { err = json.Unmarshal(buf, &indeces) if err == nil { var ret []*Viewed - for i, _ := range indeces { + for i := range indeces { ret = append(ret, &Viewed{hash, i}) } return ret @@ -85,7 +85,7 @@ func ListViewed(hash string) []*Viewed { var indeces map[int]struct{} err = json.Unmarshal(buf, &indeces) if err == nil { - for i, _ := range indeces { + for i := range indeces { ret = append(ret, &Viewed{key, i}) } } diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 93d9ee2..e2773a4 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -15,9 +15,7 @@ import ( sets "server/settings" ) -var ( - bts *BTServer -) +var bts *BTServer func InitApiHelper(bt *BTServer) { bts = bt diff --git a/server/torr/dbwrapper.go b/server/torr/dbwrapper.go index 1eb532d..4aca82f 100644 --- a/server/torr/dbwrapper.go +++ b/server/torr/dbwrapper.go @@ -2,9 +2,10 @@ package torr import ( "encoding/json" - "server/torr/utils" "time" + "server/torr/utils" + "server/settings" "server/torr/state" diff --git a/server/torr/storage/torrstor/cache.go b/server/torr/storage/torrstor/cache.go index b84365b..e8657d6 100644 --- a/server/torr/storage/torrstor/cache.go +++ b/server/torr/storage/torrstor/cache.go @@ -64,7 +64,7 @@ func (c *Cache) Init(info *metainfo.Info, hash metainfo.Hash) { if settings.BTsets.UseDisk { name := filepath.Join(settings.BTsets.TorrentsSavePath, hash.HexString()) - err := os.MkdirAll(name, 0777) + err := os.MkdirAll(name, 0o777) if err != nil { log.TLogln("Error create dir:", err) } @@ -235,7 +235,7 @@ func (c *Cache) getRemPieces() []*Piece { } } else { // on preload clean - //TODO проверить + // TODO проверить if p.Size > 0 && !c.isIdInFileBE(ranges, id) { piecesRemove = append(piecesRemove, p) } @@ -288,7 +288,6 @@ func (c *Cache) getRemPieces() []*Piece { } func (c *Cache) isIdInFileBE(ranges []Range, id int) bool { - // keep 8/16 MB FileRangeNotDelete := int64(c.pieceLength) if FileRangeNotDelete < 8*1024*1024 { diff --git a/server/torr/storage/torrstor/diskpiece.go b/server/torr/storage/torrstor/diskpiece.go index b20de74..822a68e 100644 --- a/server/torr/storage/torrstor/diskpiece.go +++ b/server/torr/storage/torrstor/diskpiece.go @@ -35,7 +35,7 @@ func (p *DiskPiece) WriteAt(b []byte, off int64) (n int, err error) { p.mu.Lock() defer p.mu.Unlock() - ff, err := os.OpenFile(p.name, os.O_RDWR|os.O_CREATE, 0666) + ff, err := os.OpenFile(p.name, os.O_RDWR|os.O_CREATE, 0o666) if err != nil { log.TLogln("Error open file:", err) return 0, err @@ -55,7 +55,7 @@ func (p *DiskPiece) ReadAt(b []byte, off int64) (n int, err error) { p.mu.Lock() defer p.mu.Unlock() - ff, err := os.OpenFile(p.name, os.O_RDONLY, 0666) + ff, err := os.OpenFile(p.name, os.O_RDONLY, 0o666) if os.IsNotExist(err) { return 0, io.EOF } diff --git a/server/torr/storage/torrstor/reader.go b/server/torr/storage/torrstor/reader.go index 80afb8a..ffb2cf6 100644 --- a/server/torr/storage/torrstor/reader.go +++ b/server/torr/storage/torrstor/reader.go @@ -71,21 +71,21 @@ func (r *Reader) Read(p []byte) (n int, err error) { r.readerOn() n, err = r.Reader.Read(p) - //samsung tv fix xvid/divx + // samsung tv fix xvid/divx if r.offset == 0 && len(p) >= 192 { str := strings.ToLower(string(p[112:116])) if str == "xvid" || str == "divx" { - p[112] = 0x4D //M - p[113] = 0x50 //P - p[114] = 0x34 //4 - p[115] = 0x56 //V + p[112] = 0x4D // M + p[113] = 0x50 // P + p[114] = 0x34 // 4 + p[115] = 0x56 // V } str = strings.ToLower(string(p[188:192])) if str == "xvid" || str == "divx" { - p[188] = 0x4D //M - p[189] = 0x50 //P - p[190] = 0x34 //4 - p[191] = 0x56 //V + p[188] = 0x4D // M + p[189] = 0x50 // P + p[190] = 0x34 // 4 + p[191] = 0x56 // V } } diff --git a/server/torr/utils/webImageChecker.go b/server/torr/utils/webImageChecker.go index 11d83d4..3b457d7 100644 --- a/server/torr/utils/webImageChecker.go +++ b/server/torr/utils/webImageChecker.go @@ -5,6 +5,7 @@ import ( _ "image/jpeg" _ "image/png" "net/http" + "server/log" ) diff --git a/server/web/api/ffprobe.go b/server/web/api/ffprobe.go index 1ca2894..f8a3f33 100644 --- a/server/web/api/ffprobe.go +++ b/server/web/api/ffprobe.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "server/utils" "github.com/gin-gonic/gin" diff --git a/server/web/api/m3u.go b/server/web/api/m3u.go index afce025..076e492 100644 --- a/server/web/api/m3u.go +++ b/server/web/api/m3u.go @@ -100,10 +100,10 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string { fn = f.Path } m3u += "#EXTINF:0," + fn + "\n" - fileNamesakes := findFileNamesakes(tor.FileStats, f) //find external media with same name (audio/subtiles tracks) + fileNamesakes := findFileNamesakes(tor.FileStats, f) // find external media with same name (audio/subtiles tracks) if fileNamesakes != nil { - m3u += "#EXTVLCOPT:input-slave=" //include VLC option for external media - for _, namesake := range fileNamesakes { //include play-links to external media, with # splitter + m3u += "#EXTVLCOPT:input-slave=" // include VLC option for external media + for _, namesake := range fileNamesakes { // include play-links to external media, with # splitter sname := filepath.Base(namesake.Path) m3u += host + "/stream/" + url.PathEscape(sname) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(namesake.Id) + "&play#" } @@ -118,12 +118,12 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string { } func findFileNamesakes(files []*state.TorrentFileStat, file *state.TorrentFileStat) []*state.TorrentFileStat { - //find files with the same name in torrent + // find files with the same name in torrent name := filepath.Base(strings.TrimSuffix(file.Path, filepath.Ext(file.Path))) var namesakes []*state.TorrentFileStat for _, f := range files { - if strings.Contains(f.Path, name) { //external tracks always include name of videofile - if f != file { //exclude itself + if strings.Contains(f.Path, name) { // external tracks always include name of videofile + if f != file { // exclude itself namesakes = append(namesakes, f) } } diff --git a/server/web/api/settings.go b/server/web/api/settings.go index 42ae959..6edf6c1 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" diff --git a/server/web/api/stream.go b/server/web/api/stream.go index 9c5f39e..b33f22b 100644 --- a/server/web/api/stream.go +++ b/server/web/api/stream.go @@ -211,5 +211,4 @@ func streamNoAuth(c *gin.Context) { } c.Header("WWW-Authenticate", "Basic realm=Authorization Required") c.AbortWithStatus(http.StatusUnauthorized) - } diff --git a/server/web/blocker/iplist.go b/server/web/blocker/iplist.go index 105fb43..690a7d0 100644 --- a/server/web/blocker/iplist.go +++ b/server/web/blocker/iplist.go @@ -68,7 +68,7 @@ func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool) { // Return the range the given IP is in. Returns nil if no range is found. func (ipl *IPList) lookup(ip net.IP) (Range, bool) { var rng Range - var ok = false + ok := false for _, r := range ipl.ranges { ok = bytes.Compare(r.First, ip) <= 0 && bytes.Compare(ip, r.Last) <= 0 if ok { diff --git a/server/web/server.go b/server/web/server.go index e3f3cc1..c7de238 100644 --- a/server/web/server.go +++ b/server/web/server.go @@ -2,9 +2,10 @@ package web import ( "net" - "server/rutor" "sort" + "server/rutor" + "github.com/gin-contrib/cors" "github.com/gin-contrib/location" "github.com/gin-gonic/gin" @@ -42,11 +43,11 @@ func Start(port string) { gin.SetMode(gin.ReleaseMode) - //corsCfg := cors.DefaultConfig() - //corsCfg.AllowAllOrigins = true - //corsCfg.AllowHeaders = []string{"*"} - //corsCfg.AllowMethods = []string{"*"} - //corsCfg.AllowPrivateNetwork = true + // corsCfg := cors.DefaultConfig() + // corsCfg.AllowAllOrigins = true + // corsCfg.AllowHeaders = []string{"*"} + // corsCfg.AllowMethods = []string{"*"} + // corsCfg.AllowPrivateNetwork = true corsCfg := cors.DefaultConfig() corsCfg.AllowAllOrigins = true corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}