Started adding frontend notifications, fixing firefox file upload bug
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/asdine/storm"
|
||||
Storage "github.com/deranjer/goTorrent/storage"
|
||||
@@ -19,8 +23,37 @@ func InitializeCronEngine() *cron.Cron {
|
||||
return c
|
||||
}
|
||||
|
||||
//CheckTorrentWatchFolder adds torrents from a watch folder //TODO see if you can use filepath.Abs instead of changing directory
|
||||
func CheckTorrentWatchFolder(c *cron.Cron, db *storm.DB, tclient *torrent.Client, torrentLocalStorage Storage.TorrentLocal, config FullClientSettings) {
|
||||
c.AddFunc("@every 5m", func() {
|
||||
Logger.WithFields(logrus.Fields{"Watch Folder": config.TorrentWatchFolder}).Info("Running the watch folder cron job")
|
||||
torrentFiles, err := ioutil.ReadDir(config.TorrentWatchFolder)
|
||||
if err != nil {
|
||||
Logger.WithFields(logrus.Fields{"Folder": config.TorrentWatchFolder, "Error": err}).Error("Unable to read from the torrent upload folder")
|
||||
return
|
||||
}
|
||||
for _, file := range torrentFiles {
|
||||
if filepath.Ext(file.Name()) != ".torrent" {
|
||||
Logger.WithFields(logrus.Fields{"File": file.Name(), "error": err}).Error("Not a torrent file..")
|
||||
} else {
|
||||
fullFilePath := filepath.Join(config.TorrentWatchFolder, file.Name())
|
||||
clientTorrent, err := tclient.AddTorrentFromFile(fullFilePath)
|
||||
if err != nil {
|
||||
Logger.WithFields(logrus.Fields{"err": err, "Torrent": file.Name()}).Warn("Unable to add torrent to torrent client!")
|
||||
break //break out of the loop entirely for this message since we hit an error
|
||||
}
|
||||
fullNewFilePath := filepath.Join(config.TFileUploadFolder, file.Name())
|
||||
StartTorrent(clientTorrent, torrentLocalStorage, db, config.TorrentConfig.DataDir, "file", file.Name(), config.DefaultMoveFolder)
|
||||
CopyFile(fullFilePath, fullNewFilePath)
|
||||
os.Remove(fullFilePath) //delete the torrent after adding it and copying it over
|
||||
Logger.WithFields(logrus.Fields{"Source Folder": config.TorrentWatchFolder, "Destination Folder": config.TFileUploadFolder, "Torrent": file.Name()}).Info("Added torrent from watch folder, and moved torrent file")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//RefreshRSSCron refreshes all of the RSS feeds on an hourly basis
|
||||
func RefreshRSSCron(c *cron.Cron, db *storm.DB, tclient *torrent.Client, torrentLocalStorage Storage.TorrentLocal, dataDir string) {
|
||||
func RefreshRSSCron(c *cron.Cron, db *storm.DB, tclient *torrent.Client, torrentLocalStorage Storage.TorrentLocal, config FullClientSettings) {
|
||||
c.AddFunc("@hourly", func() {
|
||||
torrentHashHistory := Storage.FetchHashHistory(db)
|
||||
RSSFeedStore := Storage.FetchRSSFeeds(db)
|
||||
@@ -48,7 +81,7 @@ func RefreshRSSCron(c *cron.Cron, db *storm.DB, tclient *torrent.Client, torrent
|
||||
Logger.WithFields(logrus.Fields{"err": err, "Torrent": RSSTorrent.Title}).Warn("Unable to add torrent to torrent client!")
|
||||
break //break out of the loop entirely for this message since we hit an error
|
||||
}
|
||||
StartTorrent(clientTorrent, torrentLocalStorage, db, dataDir, "magnet", "", dataDir) //TODO let user specify torrent default storage location and let change on fly
|
||||
StartTorrent(clientTorrent, torrentLocalStorage, db, config.TorrentConfig.DataDir, "magnet", "", config.DefaultMoveFolder) //TODO let user specify torrent default storage location and let change on fly
|
||||
singleFeed.Torrents = append(singleFeed.Torrents, singleRSSTorrent)
|
||||
|
||||
}
|
||||
|
@@ -2,10 +2,13 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/deranjer/goTorrent/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func secondsToMinutes(inSeconds int64) string {
|
||||
@@ -35,6 +38,25 @@ func HumanizeBytes(bytes float32) string {
|
||||
return pBytes
|
||||
}
|
||||
|
||||
//CopyFile takes a source file string and a destination file string and copies the file
|
||||
func CopyFile(srcFile string, destFile string) {
|
||||
fileContents, err := os.Open(srcFile)
|
||||
defer fileContents.Close()
|
||||
if err != nil {
|
||||
Logger.WithFields(logrus.Fields{"File": srcFile, "Error": err}).Error("Cannot open source file")
|
||||
}
|
||||
outfileContents, err := os.Open(destFile)
|
||||
defer outfileContents.Close()
|
||||
if err != nil {
|
||||
Logger.WithFields(logrus.Fields{"File": destFile, "Error": err}).Error("Cannot open destination file")
|
||||
}
|
||||
_, err = io.Copy(outfileContents, fileContents)
|
||||
if err != nil {
|
||||
Logger.WithFields(logrus.Fields{"Source File": srcFile, "Destination File": destFile, "Error": err}).Error("Cannot write contents to destination file")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//CalculateTorrentSpeed is used to calculate the torrent upload and download speed over time c is current clientdb, oc is last client db to calculate speed over time
|
||||
func CalculateTorrentSpeed(t *torrent.Torrent, c *ClientDB, oc ClientDB) {
|
||||
now := time.Now()
|
@@ -13,15 +13,16 @@ import (
|
||||
|
||||
//FullClientSettings contains all of the settings for our entire application
|
||||
type FullClientSettings struct {
|
||||
LoggingLevel logrus.Level
|
||||
LoggingOutput string
|
||||
HTTPAddr string
|
||||
Version int
|
||||
TorrentConfig torrent.Config
|
||||
TFileUploadFolder string
|
||||
SeedRatioStop float64
|
||||
PushBulletToken string
|
||||
DefaultMoveFolder string
|
||||
LoggingLevel logrus.Level
|
||||
LoggingOutput string
|
||||
HTTPAddr string
|
||||
Version int
|
||||
TorrentConfig torrent.Config
|
||||
TFileUploadFolder string
|
||||
SeedRatioStop float64
|
||||
PushBulletToken string
|
||||
DefaultMoveFolder string
|
||||
TorrentWatchFolder string
|
||||
}
|
||||
|
||||
//default is called if there is a parsing error
|
||||
@@ -71,6 +72,11 @@ func FullClientSettingsNew() FullClientSettings {
|
||||
if err != nil {
|
||||
fmt.Println("Failed creating absolute path for defaultMoveFolder", err)
|
||||
}
|
||||
torrentWatchFolder := filepath.ToSlash(viper.GetString("serverConfig.TorrentWatchFolder"))
|
||||
torrentWatchFolderAbs, err := filepath.Abs(torrentWatchFolder)
|
||||
if err != nil {
|
||||
fmt.Println("Failed creating absolute path for torrentWatchFolderAbs", 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
|
||||
@@ -149,14 +155,15 @@ func FullClientSettingsNew() FullClientSettings {
|
||||
}
|
||||
|
||||
Config := FullClientSettings{
|
||||
LoggingLevel: logLevel,
|
||||
LoggingOutput: logOutput,
|
||||
SeedRatioStop: seedRatioStop,
|
||||
HTTPAddr: httpAddr,
|
||||
TorrentConfig: tConfig,
|
||||
TFileUploadFolder: "uploadedTorrents",
|
||||
PushBulletToken: pushBulletToken,
|
||||
DefaultMoveFolder: defaultMoveFolderAbs,
|
||||
LoggingLevel: logLevel,
|
||||
LoggingOutput: logOutput,
|
||||
SeedRatioStop: seedRatioStop,
|
||||
HTTPAddr: httpAddr,
|
||||
TorrentConfig: tConfig,
|
||||
TFileUploadFolder: "uploadedTorrents",
|
||||
PushBulletToken: pushBulletToken,
|
||||
DefaultMoveFolder: defaultMoveFolderAbs,
|
||||
TorrentWatchFolder: torrentWatchFolderAbs,
|
||||
}
|
||||
|
||||
return Config
|
||||
|
Reference in New Issue
Block a user