Changing how filepath is handled for Windows

This commit is contained in:
2018-01-20 17:16:13 -05:00
parent c87443ca40
commit 83a03b3ef6
7 changed files with 69 additions and 39 deletions

View File

@@ -4,10 +4,11 @@
ServerPort = ":8000" #leave format as is it expects a string with colon
ServerAddr = "" #blank will bind to default IP address, usually fine to leave be
LogLevel = "Warn" # Options = Debug, Info, Warn, Error, Fatal, Panic
LogOutput = "file" #Options = file, stdout #file will print it to logs/server.log
LogOutput = "stdout" #Options = file, stdout #file will print it to logs/server.log
SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio
DefaultMoveFolder = "downloaded" #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
#Relative or absolute path accepted, the server will convert any relative path to an absolute path.
DefaultMoveFolder = 'downloaded' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
[notifications]
@@ -23,14 +24,14 @@
[torrentClientConfig]
DownloadDir = "downloading" #the full OR relative path where the torrent server stores in-progress torrents
DownloadDir = 'downloading' #the full OR relative path where the torrent server stores in-progress torrents
Seed = true #boolean #seed after download
# Never send chunks to peers.
NoUpload = false #boolean
#The address to listen for new uTP and TCP bittorrent protocolconnections. DHT shares a UDP socket with uTP unless configured otherwise.
#The address to listen for new uTP and TCP bittorrent protocol connections. DHT shares a UDP socket with uTP unless configured otherwise.
ListenAddr = "" #Leave Blank for default, syntax "HOST:PORT"
#Don't announce to trackers. This only leaves DHT to discover peers.
@@ -88,7 +89,7 @@
# Don't respond to queries from other nodes.
Passive = false # boolean
# the default addressses are "router.utorrent.com:6881","router.bittorrent.com:6881","dht.transmissionbt.com:6881","dht.aelitis.com:6881",
# the default addresses are "router.utorrent.com:6881","router.bittorrent.com:6881","dht.transmissionbt.com:6881","dht.aelitis.com:6881",
#https:#github.com/anacrolix/dht/blob/master/dht.go
StartingNodes = "dht.GlobalBootstrapAddrs"
@@ -108,5 +109,5 @@
#Called when a peer successfully announces to us.
OnAnnouncePeer = "func(infoHash metainfo.Hash, peer Peer)"
#How long to wait before resending queries that haven't received a response. Defaults to a random value between 4.5 and 5.5s.
#How long to wait before re-sending queries that haven't received a response. Defaults to a random value between 4.5 and 5.5s.
QueryResendDelay = "func() time.Duration"

View File

@@ -107,7 +107,10 @@ func readTorrentFileFromDB(element *Storage.TorrentLocal, tclient *torrent.Clien
//StartTorrent creates the storage.db entry and starts A NEW TORRENT and adds to the running torrent array
func StartTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage Storage.TorrentLocal, torrentDbStorage *storm.DB, dataDir string, torrentType string, torrentFileName string, torrentStoragePath string) {
timeOutInfo(clientTorrent, 45) //seeing if adding the torrrent times out (giving 45 seconds)
timedOut := timeOutInfo(clientTorrent, 45) //seeing if adding the torrrent times out (giving 45 seconds)
if timedOut { //if we fail to add the torrent return
return
}
var TempHash metainfo.Hash
TempHash = clientTorrent.InfoHash()
allStoredTorrents := Storage.FetchAllStoredTorrents(torrentDbStorage)
@@ -132,7 +135,7 @@ func StartTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage Storage.To
}
torrentLocalStorage.TorrentFile = torrentfile //storing the entire file in to database
}
Logger.WithFields(logrus.Fields{"Storage Path": torrentStoragePath, "Torrent Name": clientTorrent.Name()}).Error("Adding Torrent with following storage path")
Logger.WithFields(logrus.Fields{"Storage Path": torrentStoragePath, "Torrent Name": clientTorrent.Name()}).Info("Adding Torrent with following storage path")
torrentFiles := clientTorrent.Files() //storing all of the files in the database along with the priority
var TorrentFilePriorityArray = []Storage.TorrentFilePriority{}
for _, singleFile := range torrentFiles { //creating the database setup for the file array

View File

@@ -2,15 +2,13 @@ package engine
import (
"fmt"
"github.com/sirupsen/logrus"
"golang.org/x/time/rate"
"path/filepath"
"github.com/anacrolix/dht"
"github.com/anacrolix/torrent"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"golang.org/x/time/rate"
)
//FullClientSettings contains all of the settings for our entire application
@@ -31,7 +29,7 @@ func defaultConfig() FullClientSettings {
var Config FullClientSettings
Config.Version = 1.0
Config.LoggingLevel = 3 //Warn level
Config.TorrentConfig.DataDir = "downloads" //the full OR relative path of the default download directory for torrents
Config.TorrentConfig.DataDir = "downloads" //the absolute or relative path of the default download directory for torrents
Config.TFileUploadFolder = "uploadedTorrents"
Config.TorrentConfig.Seed = true
Config.HTTPAddr = ":8000"
@@ -68,9 +66,18 @@ func FullClientSettingsNew() FullClientSettings {
seedRatioStop := viper.GetFloat64("serverConfig.SeedRatioStop")
httpAddr = httpAddrIP + httpAddrPort
pushBulletToken := viper.GetString("notifications.PushBulletToken")
defaultMoveFolder := viper.GetString("serverConfig.DefaultMoveFolder")
defaultMoveFolder := filepath.ToSlash(viper.GetString("serverConfig.DefaultMoveFolder")) //Converting the string literal into a filepath
defaultMoveFolderAbs, err := filepath.Abs(defaultMoveFolder)
if err != nil {
fmt.Println("Failed creating absolute path for defaultMoveFolder", err)
}
dataDir := filepath.ToSlash(viper.GetString("torrentClientConfig.DownloadDir")) //Converting the string literal into a filepath
dataDirAbs, err := filepath.Abs(dataDir) //Converting to an absolute file path
if err != nil {
fmt.Println("Failed creating absolute path for dataDir", err)
}
dataDir := viper.GetString("torrentClientConfig.DownloadDir")
listenAddr := viper.GetString("torrentClientConfig.ListenAddr")
disablePex := viper.GetBool("torrentClientConfig.DisablePEX")
noDHT := viper.GetBool("torrentClientConfig.NoDHT")
@@ -124,7 +131,7 @@ func FullClientSettingsNew() FullClientSettings {
}
tConfig := torrent.Config{
DataDir: dataDir,
DataDir: dataDirAbs,
ListenAddr: listenAddr,
DisablePEX: disablePex,
NoDHT: noDHT,
@@ -149,7 +156,7 @@ func FullClientSettingsNew() FullClientSettings {
TorrentConfig: tConfig,
TFileUploadFolder: "uploadedTorrents",
PushBulletToken: pushBulletToken,
DefaultMoveFolder: defaultMoveFolder,
DefaultMoveFolder: defaultMoveFolderAbs,
}
return Config

View File

@@ -44,7 +44,7 @@ export default class addTorrentFilePopup extends React.Component {
open: false,
torrentFileName: "",
torrentFileValue: [],
storageValue: "",
storageValue: ``, //raw string for possible windows filepath
showDrop: true,
};
@@ -74,7 +74,7 @@ export default class addTorrentFilePopup extends React.Component {
}
console.log("Sending magnet link: ", torrentFileMessage);
ws.send(JSON.stringify(torrentFileMessage));
this.setState({torrentFileName: "", storageValue: "", torrentFileValue: [], showDrop: true})
this.setState({torrentFileName: "", storageValue: ``, torrentFileValue: [], showDrop: true})
}
}

View File

@@ -36,7 +36,7 @@ export default class addTorrentPopup extends React.Component {
state = {
open: false,
magnetLinkValue: "",
storageValue: "",
storageValue: ``,
};

33
main.go
View File

@@ -60,12 +60,12 @@ func main() {
Storage.Logger = Logger
Config := Engine.FullClientSettingsNew() //grabbing from settings.go
if Config.LoggingOutput == "file" {
_, err := os.Stat("logs/server.log")
_, err := os.Stat("logs")
if os.IsNotExist(err) {
err := os.Mkdir("logs", 0755)
if err != nil {
fmt.Println("Unable to create 'log' folder for logging.... please check permissions.. forcing output to stdout")
}
fmt.Println("Unable to create 'log' folder for logging.... please check permissions.. forcing output to stdout", err)
Logger.Out = os.Stdout
} else {
os.Remove("logs/server.log") //cleanup the old log on every restart
file, err := os.OpenFile("logs/server.log", os.O_CREATE|os.O_WRONLY, 0755) //creating the log file
@@ -76,6 +76,7 @@ func main() {
}
Logger.Out = file
}
}
} else {
Logger.Out = os.Stdout
}
@@ -107,9 +108,9 @@ func main() {
TorrentLocalArray = Storage.FetchAllStoredTorrents(db) //pulling in all the already added torrents
if TorrentLocalArray != nil { //the first creation of the running torrent array //since we are adding all of them in we use a coroutine... just allows the web ui to load then it will load in the torrents
//go func() { //TODO instead of running all torrent fetches in coroutine see if possible to run each single one in a routine so we don't wait for ALL of them to be verified
go func() { //TODO instead of running all torrent fetches in coroutine see if possible to run each single one in a routine so we don't wait for ALL of them to be verified
RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db)
//}()
}()
} else {
Logger.Info("Database is empty, no torrents loaded")
}
@@ -240,7 +241,16 @@ func main() {
case "magnetLinkSubmit": //if we detect a magnet link we will be adding a magnet torrent
storageValue := msg.MessageDetail
if storageValue == "" {
storageValue = Config.DefaultMoveFolder
storageValue, err = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": Config.DefaultMoveFolder}).Error("Unable to add Storage Path")
}
} else {
storageValue, err = filepath.Abs(filepath.ToSlash(storageValue))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": storageValue}).Error("Unable to add Storage Path")
storageValue, _ = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
}
}
for _, magnetLink := range msg.Payload {
clientTorrent, err := tclient.AddMagnet(magnetLink) //reading the payload into the torrent client
@@ -262,7 +272,16 @@ func main() {
FileName := msg.MessageDetail
storageValue := msg.MessageDetailTwo
if storageValue == "" {
storageValue = Config.DefaultMoveFolder
storageValue, err = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": Config.DefaultMoveFolder}).Error("Unable to add Storage Path")
}
} else {
storageValue, err = filepath.Abs(filepath.ToSlash(storageValue))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": storageValue}).Error("Unable to add Storage Path")
storageValue, _ = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
}
}
filePath := filepath.Join(Config.TFileUploadFolder, FileName) //creating a full filepath to store the .torrent files

View File

@@ -85237,7 +85237,7 @@ var addTorrentPopup = function (_React$Component) {
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = addTorrentPopup.__proto__ || Object.getPrototypeOf(addTorrentPopup)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
open: false,
magnetLinkValue: "",
storageValue: ""
storageValue: ''
}, _this.handleClickOpen = function () {
_this.setState({ open: true });
@@ -93502,7 +93502,7 @@ var addTorrentFilePopup = function (_React$Component) {
open: false,
torrentFileName: "",
torrentFileValue: [],
storageValue: "",
storageValue: '', //raw string for possible windows filepath
showDrop: true
}, _this.handleClickOpen = function () {
_this.setState({ open: true });
@@ -93526,7 +93526,7 @@ var addTorrentFilePopup = function (_React$Component) {
};
console.log("Sending magnet link: ", torrentFileMessage);
ws.send(JSON.stringify(torrentFileMessage));
_this.setState({ torrentFileName: "", storageValue: "", torrentFileValue: [], showDrop: true });
_this.setState({ torrentFileName: "", storageValue: '', torrentFileValue: [], showDrop: true });
};
}, _this.onFileLoad = function (file) {
_this.setState({ torrentFileName: file[0].name });