mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
gofumpt
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -53,9 +53,7 @@ func (v *BTSets) String() string {
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
var (
|
||||
BTsets *BTSets
|
||||
)
|
||||
var BTsets *BTSets
|
||||
|
||||
func SetBTSets(sets *BTSets) {
|
||||
if ReadOnly {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@ import (
|
||||
sets "server/settings"
|
||||
)
|
||||
|
||||
var (
|
||||
bts *BTServer
|
||||
)
|
||||
var bts *BTServer
|
||||
|
||||
func InitApiHelper(bt *BTServer) {
|
||||
bts = bt
|
||||
|
||||
@@ -2,9 +2,10 @@ package torr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"server/torr/utils"
|
||||
"time"
|
||||
|
||||
"server/torr/utils"
|
||||
|
||||
"server/settings"
|
||||
"server/torr/state"
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"net/http"
|
||||
|
||||
"server/log"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"server/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"server/rutor"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -211,5 +211,4 @@ func streamNoAuth(c *gin.Context) {
|
||||
}
|
||||
c.Header("WWW-Authenticate", "Basic realm=Authorization Required")
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user