royalcat refactoring
This commit is contained in:
parent
1da835cea6
commit
b245c9f451
81 changed files with 1476 additions and 1580 deletions
src/config
82
src/config/default.go
Normal file
82
src/config/default.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package config
|
||||
|
||||
const (
|
||||
metadataFolder = "./tstor-data/metadata"
|
||||
mountFolder = "./tstor-data/mount"
|
||||
logsFolder = "./tstor-data/logs"
|
||||
serverFolder = "./tstor-data/served-folders/server"
|
||||
)
|
||||
|
||||
var defaultConfig = Config{
|
||||
WebUi: WebUi{
|
||||
Port: 4444,
|
||||
IP: "0.0.0.0",
|
||||
},
|
||||
Mounts: Mounts{
|
||||
HttpFs: HttpFs{
|
||||
Enabled: true,
|
||||
Port: 4445,
|
||||
},
|
||||
WebDAV: WebDAV{
|
||||
Enabled: true,
|
||||
Port: 36911,
|
||||
User: "admin",
|
||||
Pass: "admin",
|
||||
},
|
||||
Fuse: Fuse{
|
||||
Enabled: false,
|
||||
AllowOther: false,
|
||||
Path: mountFolder,
|
||||
},
|
||||
},
|
||||
|
||||
TorrentClient: TorrentClient{
|
||||
GlobalCacheSize: 2048,
|
||||
MetadataFolder: metadataFolder,
|
||||
AddTimeout: 60,
|
||||
ReadTimeout: 120,
|
||||
},
|
||||
|
||||
Log: Log{
|
||||
Path: logsFolder,
|
||||
MaxBackups: 2,
|
||||
MaxSize: 50,
|
||||
},
|
||||
}
|
||||
|
||||
var defaultRoutes = []Route{
|
||||
{
|
||||
Name: "multimedia",
|
||||
Torrents: []Torrent{
|
||||
{
|
||||
MagnetURI: "magnet:?xt=urn:btih:c9e15763f722f23e98a29decdfae341b98d53056&dn=Cosmos+Laundromat&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fcosmos-laundromat.torrent",
|
||||
},
|
||||
{
|
||||
MagnetURI: "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent",
|
||||
},
|
||||
{
|
||||
MagnetURI: "magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent",
|
||||
},
|
||||
{
|
||||
MagnetURI: "magnet:?xt=urn:btih:209c8226b299b308beaf2b9cd3fb49212dbd13ec&dn=Tears+of+Steel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Ftears-of-steel.torrent",
|
||||
},
|
||||
{
|
||||
MagnetURI: "magnet:?xt=urn:btih:a88fda5954e89178c372716a6a78b8180ed4dad3&dn=The+WIRED+CD+-+Rip.+Sample.+Mash.+Share&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fwired-cd.torrent",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var defaultServers = []Server{
|
||||
{
|
||||
Name: "server",
|
||||
Path: serverFolder,
|
||||
Trackers: []string{
|
||||
"wss://tracker.btorrent.xyz",
|
||||
"wss://tracker.openwebtorrent.com",
|
||||
"http://p4p.arenabg.com:1337/announce",
|
||||
"udp://tracker.opentrackr.org:1337/announce",
|
||||
"udp://open.tracker.cl:1337/announce",
|
||||
"http://openbittorrent.com:80/announce",
|
||||
},
|
||||
},
|
||||
}
|
48
src/config/load.go
Normal file
48
src/config/load.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/knadh/koanf/parsers/yaml"
|
||||
"github.com/knadh/koanf/providers/env"
|
||||
"github.com/knadh/koanf/providers/file"
|
||||
"github.com/knadh/koanf/providers/structs"
|
||||
"github.com/knadh/koanf/v2"
|
||||
)
|
||||
|
||||
var k = koanf.New(".")
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
|
||||
err := k.Load(structs.Provider(defaultConfig, "koanf"), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if path != "" {
|
||||
_ = k.Load(file.Provider(path), yaml.Parser()) // its ok if file doesnt exist
|
||||
}
|
||||
|
||||
err = k.Load(env.Provider("tstor_", ".", func(s string) string {
|
||||
return strings.Replace(strings.ToLower(
|
||||
strings.TrimPrefix(s, "tstor_")), "_", ".", -1)
|
||||
}), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := k.Marshal(yaml.Parser())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = os.WriteFile(path, data, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conf := Config{}
|
||||
k.Unmarshal("", &conf)
|
||||
|
||||
return &conf, nil
|
||||
}
|
75
src/config/model.go
Normal file
75
src/config/model.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package config
|
||||
|
||||
// Config is the main config object
|
||||
type Config struct {
|
||||
WebUi WebUi `koanf:"webUi"`
|
||||
TorrentClient TorrentClient `koanf:"torrent"`
|
||||
Mounts Mounts `koanf:"mounts"`
|
||||
Log Log `koanf:"log"`
|
||||
}
|
||||
|
||||
type WebUi struct {
|
||||
Port int `koanf:"port"`
|
||||
IP string `koanf:"ip"`
|
||||
}
|
||||
|
||||
type Log struct {
|
||||
Debug bool `koanf:"debug"`
|
||||
MaxBackups int `koanf:"max_backups"`
|
||||
MaxSize int `koanf:"max_size"`
|
||||
MaxAge int `koanf:"max_age"`
|
||||
Path string `koanf:"path"`
|
||||
}
|
||||
|
||||
type TorrentClient struct {
|
||||
ReadTimeout int `koanf:"read_timeout,omitempty"`
|
||||
AddTimeout int `koanf:"add_timeout,omitempty"`
|
||||
GlobalCacheSize int64 `koanf:"global_cache_size,omitempty"`
|
||||
MetadataFolder string `koanf:"metadata_folder,omitempty"`
|
||||
DisableIPv6 bool `koanf:"disable_ipv6,omitempty"`
|
||||
|
||||
Routes []Route `koanf:"routes"`
|
||||
Servers []Server `koanf:"servers"`
|
||||
}
|
||||
|
||||
type Route struct {
|
||||
Name string `koanf:"name"`
|
||||
Torrents []Torrent `koanf:"torrents"`
|
||||
TorrentFolder string `koanf:"torrent_folder"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Name string `koanf:"name"`
|
||||
Path string `koanf:"path"`
|
||||
Trackers []string `koanf:"trackers"`
|
||||
TrackerURL string `koanf:"tracker_url"`
|
||||
}
|
||||
|
||||
type Torrent struct {
|
||||
MagnetURI string `koanf:"magnet_uri,omitempty"`
|
||||
TorrentPath string `koanf:"torrent_path,omitempty"`
|
||||
}
|
||||
|
||||
type Mounts struct {
|
||||
WebDAV WebDAV `koanf:"webdav"`
|
||||
HttpFs HttpFs `koanf:"httpfs"`
|
||||
Fuse Fuse `koanf:"fuse"`
|
||||
}
|
||||
|
||||
type HttpFs struct {
|
||||
Enabled bool `koanf:"enabled"`
|
||||
Port int `koanf:"port"`
|
||||
}
|
||||
|
||||
type WebDAV struct {
|
||||
Enabled bool `koanf:"enabled"`
|
||||
Port int `koanf:"port"`
|
||||
User string `koanf:"user"`
|
||||
Pass string `koanf:"pass"`
|
||||
}
|
||||
|
||||
type Fuse struct {
|
||||
Enabled bool `koanf:"enabled"`
|
||||
AllowOther bool `koanf:"allow_other,omitempty"`
|
||||
Path string `koanf:"path"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue