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{}) {
|
func getRoot() (ret []interface{}) {
|
||||||
|
|
||||||
// Torrents Object
|
// Torrents Object
|
||||||
tObj := upnpav.Object{
|
tObj := upnpav.Object{
|
||||||
ID: "%2FTR",
|
ID: "%2FTR",
|
||||||
@@ -37,18 +36,16 @@ func getRoot() (ret []interface{}) {
|
|||||||
ret = append(ret, cnt)
|
ret = append(ret, cnt)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTorrents() (ret []interface{}) {
|
func getTorrents() (ret []interface{}) {
|
||||||
|
|
||||||
torrs := torr.ListTorrent()
|
torrs := torr.ListTorrent()
|
||||||
// sort by title as in cds SortCaps
|
// sort by title as in cds SortCaps
|
||||||
sort.Slice(torrs, func(i, j int) bool {
|
sort.Slice(torrs, func(i, j int) bool {
|
||||||
return torrs[i].Title < torrs[j].Title
|
return torrs[i].Title < torrs[j].Title
|
||||||
})
|
})
|
||||||
|
|
||||||
var vol = 0
|
vol := 0
|
||||||
for _, t := range torrs {
|
for _, t := range torrs {
|
||||||
vol++
|
vol++
|
||||||
obj := upnpav.Object{
|
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{}) {
|
func getObjFromTorrent(path, parent, host string, torr *torr.Torrent, file *state.TorrentFileStat) (ret interface{}) {
|
||||||
|
|
||||||
mime, err := mt.MimeTypeByPath(file.Path)
|
mime, err := mt.MimeTypeByPath(file.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if settings.BTsets.EnableDebug {
|
if settings.BTsets.EnableDebug {
|
||||||
|
|||||||
@@ -12,20 +12,24 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logPath = ""
|
var (
|
||||||
var webLogPath = ""
|
logPath = ""
|
||||||
|
webLogPath = ""
|
||||||
|
)
|
||||||
|
|
||||||
var webLog *log.Logger
|
var webLog *log.Logger
|
||||||
|
|
||||||
var logFile *os.File
|
var (
|
||||||
var webLogFile *os.File
|
logFile *os.File
|
||||||
|
webLogFile *os.File
|
||||||
|
)
|
||||||
|
|
||||||
func Init(path, webpath string) {
|
func Init(path, webpath string) {
|
||||||
webLogPath = webpath
|
webLogPath = webpath
|
||||||
logPath = path
|
logPath = path
|
||||||
|
|
||||||
if webpath != "" {
|
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 {
|
if err != nil {
|
||||||
TLogln("Error create web log file:", err)
|
TLogln("Error create web log file:", err)
|
||||||
} else {
|
} else {
|
||||||
@@ -40,7 +44,7 @@ func Init(path, webpath string) {
|
|||||||
os.Remove(path)
|
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 {
|
if err != nil {
|
||||||
TLogln("Error create log file:", err)
|
TLogln("Error create log file:", err)
|
||||||
return
|
return
|
||||||
@@ -87,7 +91,7 @@ func WebLogger() gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
body := ""
|
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") {
|
if !strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data") {
|
||||||
body, _ := ioutil.ReadAll(c.Request.Body)
|
body, _ := ioutil.ReadAll(c.Request.Body)
|
||||||
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
// Add a minimal number of mime types to augment go's built in types
|
// 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.
|
// for environments which don't have access to a mime.types file (e.g.
|
||||||
// Termux on android)
|
// Termux on android)
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"server/rutor/models"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"server/rutor/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseChannel(t *testing.T) {
|
func TestParseChannel(t *testing.T) {
|
||||||
var channel = make(chan *models.TorrentDetails, 0)
|
channel := make(chan *models.TorrentDetails, 0)
|
||||||
var ftors []*models.TorrentDetails
|
var ftors []*models.TorrentDetails
|
||||||
go func() {
|
go func() {
|
||||||
for torr := range channel {
|
for torr := range channel {
|
||||||
|
|||||||
@@ -3,21 +3,23 @@ package rutor
|
|||||||
import (
|
import (
|
||||||
"compress/flate"
|
"compress/flate"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/agnivade/levenshtein"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/agnivade/levenshtein"
|
||||||
|
|
||||||
"server/log"
|
"server/log"
|
||||||
"server/rutor/models"
|
"server/rutor/models"
|
||||||
"server/rutor/torrsearch"
|
"server/rutor/torrsearch"
|
||||||
"server/rutor/utils"
|
"server/rutor/utils"
|
||||||
"server/settings"
|
"server/settings"
|
||||||
utils2 "server/torr/utils"
|
utils2 "server/torr/utils"
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ func analyze(text string) []string {
|
|||||||
tokens := tokenize(text)
|
tokens := tokenize(text)
|
||||||
tokens = lowercaseFilter(tokens)
|
tokens = lowercaseFilter(tokens)
|
||||||
tokens = stopwordFilter(tokens)
|
tokens = stopwordFilter(tokens)
|
||||||
//tokens = stemmerFilter(tokens)
|
// tokens = stemmerFilter(tokens)
|
||||||
return tokens
|
return tokens
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,7 @@ func (v *BTSets) String() string {
|
|||||||
return string(buf)
|
return string(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var BTsets *BTSets
|
||||||
BTsets *BTSets
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetBTSets(sets *BTSets) {
|
func SetBTSets(sets *BTSets) {
|
||||||
if ReadOnly {
|
if ReadOnly {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type TDB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTDB() *TDB {
|
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 {
|
if err != nil {
|
||||||
log.TLogln(err)
|
log.TLogln(err)
|
||||||
return nil
|
return nil
|
||||||
@@ -60,7 +60,6 @@ func (v *TDB) Get(xpath, name string) []byte {
|
|||||||
ret = buckt.Get([]byte(name))
|
ret = buckt.Get([]byte(name))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error get sets", xpath+"/"+name, ", error:", err)
|
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)
|
return buckt.Put([]byte(name), value)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error put sets", xpath+"/"+name, ", error:", err)
|
log.TLogln("Error put sets", xpath+"/"+name, ", error:", err)
|
||||||
log.TLogln("value:", value)
|
log.TLogln("value:", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *TDB) List(xpath string) []string {
|
func (v *TDB) List(xpath string) []string {
|
||||||
@@ -134,7 +131,6 @@ func (v *TDB) List(xpath string) []string {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error list sets", xpath, ", error:", err)
|
log.TLogln("Error list sets", xpath, ", error:", err)
|
||||||
}
|
}
|
||||||
@@ -169,9 +165,7 @@ func (v *TDB) Rem(xpath, name string) {
|
|||||||
|
|
||||||
return buckt.Delete([]byte(name))
|
return buckt.Delete([]byte(name))
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error rem sets", xpath+"/"+name, ", error:", err)
|
log.TLogln("Error rem sets", xpath+"/"+name, ", error:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import (
|
|||||||
"server/web/api/utils"
|
"server/web/api/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var dbTorrentsName = []byte("Torrents")
|
||||||
dbTorrentsName = []byte("Torrents")
|
|
||||||
)
|
|
||||||
|
|
||||||
type torrentOldDB struct {
|
type torrentOldDB struct {
|
||||||
Name string
|
Name string
|
||||||
@@ -29,7 +27,7 @@ func Migrate() {
|
|||||||
return
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func ListViewed(hash string) []*Viewed {
|
|||||||
err = json.Unmarshal(buf, &indeces)
|
err = json.Unmarshal(buf, &indeces)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
var ret []*Viewed
|
var ret []*Viewed
|
||||||
for i, _ := range indeces {
|
for i := range indeces {
|
||||||
ret = append(ret, &Viewed{hash, i})
|
ret = append(ret, &Viewed{hash, i})
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
@@ -85,7 +85,7 @@ func ListViewed(hash string) []*Viewed {
|
|||||||
var indeces map[int]struct{}
|
var indeces map[int]struct{}
|
||||||
err = json.Unmarshal(buf, &indeces)
|
err = json.Unmarshal(buf, &indeces)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for i, _ := range indeces {
|
for i := range indeces {
|
||||||
ret = append(ret, &Viewed{key, i})
|
ret = append(ret, &Viewed{key, i})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ import (
|
|||||||
sets "server/settings"
|
sets "server/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var bts *BTServer
|
||||||
bts *BTServer
|
|
||||||
)
|
|
||||||
|
|
||||||
func InitApiHelper(bt *BTServer) {
|
func InitApiHelper(bt *BTServer) {
|
||||||
bts = bt
|
bts = bt
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package torr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"server/torr/utils"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"server/torr/utils"
|
||||||
|
|
||||||
"server/settings"
|
"server/settings"
|
||||||
"server/torr/state"
|
"server/torr/state"
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (c *Cache) Init(info *metainfo.Info, hash metainfo.Hash) {
|
|||||||
|
|
||||||
if settings.BTsets.UseDisk {
|
if settings.BTsets.UseDisk {
|
||||||
name := filepath.Join(settings.BTsets.TorrentsSavePath, hash.HexString())
|
name := filepath.Join(settings.BTsets.TorrentsSavePath, hash.HexString())
|
||||||
err := os.MkdirAll(name, 0777)
|
err := os.MkdirAll(name, 0o777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Error create dir:", err)
|
log.TLogln("Error create dir:", err)
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ func (c *Cache) getRemPieces() []*Piece {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// on preload clean
|
// on preload clean
|
||||||
//TODO проверить
|
// TODO проверить
|
||||||
if p.Size > 0 && !c.isIdInFileBE(ranges, id) {
|
if p.Size > 0 && !c.isIdInFileBE(ranges, id) {
|
||||||
piecesRemove = append(piecesRemove, p)
|
piecesRemove = append(piecesRemove, p)
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,6 @@ func (c *Cache) getRemPieces() []*Piece {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) isIdInFileBE(ranges []Range, id int) bool {
|
func (c *Cache) isIdInFileBE(ranges []Range, id int) bool {
|
||||||
|
|
||||||
// keep 8/16 MB
|
// keep 8/16 MB
|
||||||
FileRangeNotDelete := int64(c.pieceLength)
|
FileRangeNotDelete := int64(c.pieceLength)
|
||||||
if FileRangeNotDelete < 8*1024*1024 {
|
if FileRangeNotDelete < 8*1024*1024 {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (p *DiskPiece) WriteAt(b []byte, off int64) (n int, err error) {
|
|||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
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 {
|
if err != nil {
|
||||||
log.TLogln("Error open file:", err)
|
log.TLogln("Error open file:", err)
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -55,7 +55,7 @@ func (p *DiskPiece) ReadAt(b []byte, off int64) (n int, err error) {
|
|||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
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) {
|
if os.IsNotExist(err) {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,21 +71,21 @@ func (r *Reader) Read(p []byte) (n int, err error) {
|
|||||||
r.readerOn()
|
r.readerOn()
|
||||||
n, err = r.Reader.Read(p)
|
n, err = r.Reader.Read(p)
|
||||||
|
|
||||||
//samsung tv fix xvid/divx
|
// samsung tv fix xvid/divx
|
||||||
if r.offset == 0 && len(p) >= 192 {
|
if r.offset == 0 && len(p) >= 192 {
|
||||||
str := strings.ToLower(string(p[112:116]))
|
str := strings.ToLower(string(p[112:116]))
|
||||||
if str == "xvid" || str == "divx" {
|
if str == "xvid" || str == "divx" {
|
||||||
p[112] = 0x4D //M
|
p[112] = 0x4D // M
|
||||||
p[113] = 0x50 //P
|
p[113] = 0x50 // P
|
||||||
p[114] = 0x34 //4
|
p[114] = 0x34 // 4
|
||||||
p[115] = 0x56 //V
|
p[115] = 0x56 // V
|
||||||
}
|
}
|
||||||
str = strings.ToLower(string(p[188:192]))
|
str = strings.ToLower(string(p[188:192]))
|
||||||
if str == "xvid" || str == "divx" {
|
if str == "xvid" || str == "divx" {
|
||||||
p[188] = 0x4D //M
|
p[188] = 0x4D // M
|
||||||
p[189] = 0x50 //P
|
p[189] = 0x50 // P
|
||||||
p[190] = 0x34 //4
|
p[190] = 0x34 // 4
|
||||||
p[191] = 0x56 //V
|
p[191] = 0x56 // V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"server/log"
|
"server/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"server/utils"
|
"server/utils"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|||||||
@@ -100,10 +100,10 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
|
|||||||
fn = f.Path
|
fn = f.Path
|
||||||
}
|
}
|
||||||
m3u += "#EXTINF:0," + fn + "\n"
|
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 {
|
if fileNamesakes != nil {
|
||||||
m3u += "#EXTVLCOPT:input-slave=" //include VLC option for external media
|
m3u += "#EXTVLCOPT:input-slave=" // include VLC option for external media
|
||||||
for _, namesake := range fileNamesakes { //include play-links to external media, with # splitter
|
for _, namesake := range fileNamesakes { // include play-links to external media, with # splitter
|
||||||
sname := filepath.Base(namesake.Path)
|
sname := filepath.Base(namesake.Path)
|
||||||
m3u += host + "/stream/" + url.PathEscape(sname) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(namesake.Id) + "&play#"
|
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 {
|
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)))
|
name := filepath.Base(strings.TrimSuffix(file.Path, filepath.Ext(file.Path)))
|
||||||
var namesakes []*state.TorrentFileStat
|
var namesakes []*state.TorrentFileStat
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if strings.Contains(f.Path, name) { //external tracks always include name of videofile
|
if strings.Contains(f.Path, name) { // external tracks always include name of videofile
|
||||||
if f != file { //exclude itself
|
if f != file { // exclude itself
|
||||||
namesakes = append(namesakes, f)
|
namesakes = append(namesakes, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"server/rutor"
|
"server/rutor"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|||||||
@@ -211,5 +211,4 @@ func streamNoAuth(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
c.Header("WWW-Authenticate", "Basic realm=Authorization Required")
|
c.Header("WWW-Authenticate", "Basic realm=Authorization Required")
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
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.
|
// Return the range the given IP is in. Returns nil if no range is found.
|
||||||
func (ipl *IPList) lookup(ip net.IP) (Range, bool) {
|
func (ipl *IPList) lookup(ip net.IP) (Range, bool) {
|
||||||
var rng Range
|
var rng Range
|
||||||
var ok = false
|
ok := false
|
||||||
for _, r := range ipl.ranges {
|
for _, r := range ipl.ranges {
|
||||||
ok = bytes.Compare(r.First, ip) <= 0 && bytes.Compare(ip, r.Last) <= 0
|
ok = bytes.Compare(r.First, ip) <= 0 && bytes.Compare(ip, r.Last) <= 0
|
||||||
if ok {
|
if ok {
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"server/rutor"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"server/rutor"
|
||||||
|
|
||||||
"github.com/gin-contrib/cors"
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-contrib/location"
|
"github.com/gin-contrib/location"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -42,11 +43,11 @@ func Start(port string) {
|
|||||||
|
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
||||||
//corsCfg := cors.DefaultConfig()
|
// corsCfg := cors.DefaultConfig()
|
||||||
//corsCfg.AllowAllOrigins = true
|
// corsCfg.AllowAllOrigins = true
|
||||||
//corsCfg.AllowHeaders = []string{"*"}
|
// corsCfg.AllowHeaders = []string{"*"}
|
||||||
//corsCfg.AllowMethods = []string{"*"}
|
// corsCfg.AllowMethods = []string{"*"}
|
||||||
//corsCfg.AllowPrivateNetwork = true
|
// corsCfg.AllowPrivateNetwork = true
|
||||||
corsCfg := cors.DefaultConfig()
|
corsCfg := cors.DefaultConfig()
|
||||||
corsCfg.AllowAllOrigins = true
|
corsCfg.AllowAllOrigins = true
|
||||||
corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}
|
corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}
|
||||||
|
|||||||
Reference in New Issue
Block a user