started adding the back to front api via websocket and json
82
engine/clientStructs.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package engine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/anacrolix/torrent"
|
||||||
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
|
)
|
||||||
|
|
||||||
|
//All the message types are first, first the server handling messages from the client
|
||||||
|
|
||||||
|
//Message contains the JSON messages from the client, we first unmarshal to get the messagetype, then each module unmarshalls the actual message once we know the type
|
||||||
|
type Message struct {
|
||||||
|
MessageType string
|
||||||
|
Payload json.RawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
//GenericPayload is for any request to the server that only requires the TorrentHashString for matching (which is a lot of requests)
|
||||||
|
type GenericPayload struct {
|
||||||
|
TorrentHashString string
|
||||||
|
}
|
||||||
|
|
||||||
|
//MagnetMessage contains the magnet link entered by the user under ADD MAGNET link on the top toolbar
|
||||||
|
type MagnetMessage struct {
|
||||||
|
MagnetLink string `json:MagnetLink`
|
||||||
|
}
|
||||||
|
|
||||||
|
//TorrentCommandMessage contains a slice of strings that has the list of torrents to be acted on.
|
||||||
|
type TorrentCommandMessage struct {
|
||||||
|
TorrentHashStrings []string
|
||||||
|
}
|
||||||
|
|
||||||
|
//Next are the messages the server sends to the client
|
||||||
|
|
||||||
|
//TorrentList struct contains the torrent list that is sent to the client
|
||||||
|
type TorrentList struct { //helps create the JSON structure that react expects to recieve
|
||||||
|
MessageType string `json:"MessageType"`
|
||||||
|
Totaltorrents int `json:"total"`
|
||||||
|
ClientDBstruct []ClientDB `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//TorrentFileList supplies a list of files attached to a single torrent along with some additional information
|
||||||
|
type TorrentFileList struct {
|
||||||
|
MessageType string
|
||||||
|
TotalFiles int `json:"total"`
|
||||||
|
FileList []torrent.File `json:"fileList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//PeerFileList returns a slice of peers
|
||||||
|
type PeerFileList struct {
|
||||||
|
MessageType string
|
||||||
|
TotalPeers int
|
||||||
|
PeerList []torrent.Peer
|
||||||
|
}
|
||||||
|
|
||||||
|
//ClientDB struct contains the struct that is used to compose the torrentlist
|
||||||
|
type ClientDB struct {
|
||||||
|
TorrentName string `json:"TorrentName"`
|
||||||
|
DownloadedSize string `json:"DownloadedSize"`
|
||||||
|
Size string `json:"Size"`
|
||||||
|
DownloadSpeed string `json:"DownloadSpeed"`
|
||||||
|
downloadSpeedInt int64
|
||||||
|
UploadSpeed string `json:"UploadSpeed"`
|
||||||
|
//UploadSpeedInt int64
|
||||||
|
DataBytesWritten int64
|
||||||
|
DataBytesRead int64
|
||||||
|
ActivePeers string `json:"ActivePeers"`
|
||||||
|
TorrentHashString string `json:"TorrentHashString"`
|
||||||
|
PercentDone string `json:"PercentDone"`
|
||||||
|
TorrentHash metainfo.Hash
|
||||||
|
StoragePath string `json:"StorageLocation"`
|
||||||
|
DateAdded string
|
||||||
|
KnownSwarm []torrent.Peer
|
||||||
|
Status string `json:"Status"`
|
||||||
|
BytesCompleted int64
|
||||||
|
UpdatedAt time.Time
|
||||||
|
AddedAt string
|
||||||
|
ETA string `json:"ETA"`
|
||||||
|
Label string
|
||||||
|
SourceLocation string
|
||||||
|
}
|
245
engine/engine.go
@@ -1,104 +1,185 @@
|
|||||||
package engine //main file for all the calculations and data gathering needed for creating the running torrent array
|
package engine //main file for all the calculations and data gathering needed for creating the running torrent arrays
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
Main "github.com/deranjer/goTorrent"
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
|
"github.com/boltdb/bolt"
|
||||||
|
Storage "github.com/deranjer/goTorrent/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func secondsToMinutes(inSeconds int64) string {
|
func timeOutInfo(clientTorrent *torrent.Torrent, seconds time.Duration) (deleted bool) { //forcing a timeout of the torrent if it doesn't load
|
||||||
minutes := inSeconds / 60
|
timeout := make(chan bool, 1) //creating a timeout channel for our gotinfo
|
||||||
seconds := inSeconds % 60
|
go func() {
|
||||||
minutesString := fmt.Sprintf("%d", minutes)
|
time.Sleep(seconds * time.Second)
|
||||||
secondsString := fmt.Sprintf("%d", seconds)
|
timeout <- true
|
||||||
str := minutesString + " Min/ " + secondsString + " Sec"
|
}()
|
||||||
return str
|
select {
|
||||||
|
case <-clientTorrent.GotInfo(): //attempting to retrieve info for torrent
|
||||||
|
fmt.Println("Recieved torrent info for...", clientTorrent.Name())
|
||||||
|
clientTorrent.DownloadAll()
|
||||||
|
return false
|
||||||
|
case <-timeout: // getting info for torrent has timed out so purging the torrent
|
||||||
|
fmt.Println("Dropping Torrent")
|
||||||
|
clientTorrent.Drop()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertSizetoGB(t float32, d float32) (tDelta string, dDelta string) { //converting sizes to MB or GB as needed and adding string
|
//StartTorrent creates the storage.db entry and starts the torrent and adds to the running torrent array
|
||||||
if t > 1024 && d > 1024 {
|
func StartTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage *Storage.TorrentLocal, torrentDbStorage *bolt.DB, dataDir string, torrentFile string, torrentFileName string) {
|
||||||
t := fmt.Sprintf("%.2f", t/1024)
|
|
||||||
t = t + " GB"
|
timeOutInfo(clientTorrent, 45) //seeing if adding the torrrent times out (giving 45 seconds)
|
||||||
d := fmt.Sprintf("%.2f", d/1024)
|
var TempHash metainfo.Hash
|
||||||
d = d + " GB"
|
TempHash = clientTorrent.InfoHash()
|
||||||
return t, d
|
fmt.Println(clientTorrent.Info().Source)
|
||||||
} else if d > 1024 || t > 1024 {
|
torrentLocalStorage.Hash = TempHash.String() // we will store the infohash to add it back later on client restart (if needed)
|
||||||
if d > 1024 {
|
torrentLocalStorage.DateAdded = time.Now().Format("Jan _2 2006")
|
||||||
d := fmt.Sprintf("%.2f", d/1024)
|
torrentLocalStorage.StoragePath = dataDir //TODO check full path information for torrent storage
|
||||||
d = d + " GB"
|
torrentLocalStorage.TorrentName = clientTorrent.Name()
|
||||||
t := fmt.Sprintf("%.2f", t)
|
torrentLocalStorage.TorrentStatus = "downloading" //by default start all the torrents as downloading.
|
||||||
t = t + " MB"
|
torrentLocalStorage.TorrentType = torrentFile //either "file" or "magnet" maybe more in the future
|
||||||
return t, d
|
if torrentFile == "file" {
|
||||||
|
torrentLocalStorage.TorrentFileName = torrentFileName
|
||||||
|
} else {
|
||||||
|
torrentLocalStorage.TorrentFileName = ""
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v\n", torrentLocalStorage)
|
||||||
|
Storage.AddTorrentLocalStorage(torrentDbStorage, torrentLocalStorage) //writing all of the data to the database
|
||||||
|
clientTorrent.DownloadAll() //starting the download
|
||||||
|
}
|
||||||
|
|
||||||
|
//CreateRunningTorrentArray creates the entire torrent list to pass to client
|
||||||
|
func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Storage.TorrentLocal, PreviousTorrentArray []ClientDB, config FullClientSettings, db *bolt.DB) (RunningTorrentArray []ClientDB) {
|
||||||
|
|
||||||
|
for _, element := range TorrentLocalArray { //re-adding all the torrents we had stored from last shutdown or just added via file or magnet link
|
||||||
|
|
||||||
|
var singleTorrent *torrent.Torrent
|
||||||
|
|
||||||
|
if element.TorrentType == "file" { //if it is a file pull it from the uploaded torrent folder
|
||||||
|
//fmt.Println("Filename", element.TorrentFileName)
|
||||||
|
if _, err := os.Stat(element.TorrentFileName); err == nil { //if we CAN find the torrent, add it
|
||||||
|
//fmt.Println("Adding file name...", element.TorrentFileName)
|
||||||
|
singleTorrent, _ = tclient.AddTorrentFromFile(element.TorrentFileName)
|
||||||
|
} else { //if we cant find the torrent delete it
|
||||||
|
fmt.Println("File Error", err)
|
||||||
|
Storage.DelTorrentLocalStorage(db, element)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
elementMagnet := "magnet:?xt=urn:btih:" + element.Hash //For magnet links just need to prepend the magnet part to the hash to readd
|
||||||
|
singleTorrent, _ = tclient.AddMagnet(elementMagnet)
|
||||||
}
|
}
|
||||||
d := fmt.Sprintf("%.2f", d)
|
|
||||||
d = d + " MB"
|
timeOut := timeOutInfo(singleTorrent, 45)
|
||||||
t := fmt.Sprintf("%.2f", t/1024)
|
if timeOut == true { // if we did timeout then drop the torrent from the boltdb database
|
||||||
t = t + " GB"
|
Storage.DelTorrentLocalStorage(db, element) //purging torrent from the local database
|
||||||
return t, d
|
}
|
||||||
} else {
|
|
||||||
d := fmt.Sprintf("%.2f", d)
|
fullClientDB := new(ClientDB)
|
||||||
t := fmt.Sprintf("%.2f", t)
|
fullStruct := singleTorrent.Stats()
|
||||||
t = t + " MB"
|
|
||||||
d = d + " MB"
|
//ranging over the previous torrent array to calculate the speed for each torrent
|
||||||
return t, d
|
if len(PreviousTorrentArray) > 0 { //if we actually have a previous array
|
||||||
|
for _, previousElement := range PreviousTorrentArray {
|
||||||
|
TempHash := singleTorrent.InfoHash()
|
||||||
|
if previousElement.TorrentHashString == TempHash.AsString() { //matching previous to new
|
||||||
|
CalculateTorrentSpeed(singleTorrent, fullClientDB, previousElement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activePeersString := fmt.Sprintf("%v", fullStruct.ActivePeers) //converting to strings
|
||||||
|
totalPeersString := fmt.Sprintf("%v", fullStruct.TotalPeers)
|
||||||
|
bytesCompletedMB := float32(singleTorrent.BytesCompleted() / 1024 / 1024)
|
||||||
|
totalSizeMB := float32(singleTorrent.Length() / 1024 / 1024)
|
||||||
|
//downloadSizeString := fmt.Sprintf("%d", bytesCompletedMB)
|
||||||
|
|
||||||
|
tSize, dSize := ConvertSizetoGB(totalSizeMB, bytesCompletedMB) //convert size to GB if needed
|
||||||
|
var TempHash metainfo.Hash
|
||||||
|
TempHash = singleTorrent.InfoHash()
|
||||||
|
|
||||||
|
fullClientDB.DownloadedSize = dSize
|
||||||
|
fullClientDB.Size = tSize
|
||||||
|
PercentDone := fmt.Sprintf("%.2f", bytesCompletedMB/totalSizeMB)
|
||||||
|
fullClientDB.TorrentHash = TempHash
|
||||||
|
fullClientDB.PercentDone = PercentDone
|
||||||
|
fullClientDB.DataBytesRead = fullStruct.ConnStats.DataBytesRead
|
||||||
|
fullClientDB.DataBytesWritten = fullStruct.ConnStats.DataBytesWritten
|
||||||
|
fullClientDB.ActivePeers = activePeersString + " / (" + totalPeersString + ")"
|
||||||
|
fullClientDB.TorrentHashString = TempHash.AsString()
|
||||||
|
fullClientDB.StoragePath = element.StoragePath
|
||||||
|
fullClientDB.TorrentName = element.TorrentName
|
||||||
|
fullClientDB.DateAdded = element.DateAdded
|
||||||
|
fullClientDB.BytesCompleted = singleTorrent.BytesCompleted()
|
||||||
|
CalculateTorrentETA(singleTorrent, fullClientDB) //calculating the ETA for the torrent
|
||||||
|
//fmt.Println("Download Speed: ", fullClientDB.DownloadSpeed)
|
||||||
|
//fmt.Println("Percent Done: ", fullClientDB.PercentDone)
|
||||||
|
//tclient.WriteStatus(os.Stdout)
|
||||||
|
CalculateTorrentStatus(singleTorrent, fullClientDB) //calculate the status of the torrent, ie downloading seeding etc
|
||||||
|
|
||||||
|
RunningTorrentArray = append(RunningTorrentArray, *fullClientDB)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
fmt.Println("RunningTorrentArrayCreated...")
|
||||||
|
return RunningTorrentArray
|
||||||
}
|
}
|
||||||
|
|
||||||
func CalculateTorrentSpeed(t *torrent.Torrent, c *Main.ClientDB, oc Main.ClientDB) {
|
//CreateFileListArray creates a file list for a single torrent that is selected and sent to the server
|
||||||
now := time.Now()
|
func CreateFileListArray(tclient *torrent.Client, selectedHash string) TorrentFileList {
|
||||||
bytes := t.BytesCompleted()
|
runningTorrents := tclient.Torrents() //don't need running torrent array since we aren't adding or deleting from storage
|
||||||
bytesUpload := t.Stats().DataBytesWritten
|
TorrentFileListSelected := TorrentFileList{}
|
||||||
dt := float32(now.Sub(oc.UpdatedAt)) // get the delta time length between now and last updated
|
for _, singleTorrent := range runningTorrents {
|
||||||
db := float32(bytes - oc.BytesCompleted) //getting the delta bytes
|
tempHash := singleTorrent.InfoHash()
|
||||||
rate := db * (float32(time.Second) / dt) // converting into seconds
|
if tempHash.AsString() == selectedHash { // if our selection hash equals our torrent hash
|
||||||
dbU := float32(bytesUpload - oc.DataBytesWritten)
|
TorrentFileListSelected.FileList = singleTorrent.Files()
|
||||||
fmt.Println("BytesWritten", bytesUpload)
|
TorrentFileListSelected.MessageType = "torrentFileList"
|
||||||
fmt.Println("WireBytes", t.Stats().DataBytesWritten)
|
TorrentFileListSelected.TotalFiles = len(singleTorrent.Files())
|
||||||
fmt.Println("ChunksWritten", t.Stats().ChunksWritten)
|
return TorrentFileListSelected
|
||||||
rateUpload := dbU * (float32(time.Second) / dt)
|
}
|
||||||
if rate >= 0 {
|
|
||||||
rate = rate / 1024 / 1024 //creating integer to calculate ETA
|
|
||||||
c.DownloadSpeed = fmt.Sprintf("%.2f", rate)
|
|
||||||
c.DownloadSpeed = c.DownloadSpeed + " MB/s"
|
|
||||||
c.downloadSpeedInt = int64(rate)
|
|
||||||
}
|
}
|
||||||
if rateUpload >= 0 {
|
return TorrentFileListSelected
|
||||||
rateUpload = rateUpload / 1024 / 1024
|
|
||||||
c.UploadSpeed = fmt.Sprintf("%.2f", rateUpload)
|
|
||||||
c.UploadSpeed = c.UploadSpeed + " MB/s"
|
|
||||||
//c.UploadSpeedInt = int64(rateUpload)
|
|
||||||
}
|
|
||||||
//c.DownloadSpeed = fmt.Sprintf("%.2f", rate) //setting zero for download speed
|
|
||||||
//c.DownloadSpeed = c.DownloadSpeed + " MB/s"
|
|
||||||
c.UpdatedAt = now
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateTorrentETA(t *torrent.Torrent, c *Main.ClientDB) {
|
//CreatePeerListArray create a list of peers for the torrent and displays them
|
||||||
missingBytes := t.Length() - t.BytesCompleted()
|
func CreatePeerListArray(tclient *torrent.Client, selectedHash string) PeerFileList {
|
||||||
missingMB := missingBytes / 1024 / 1024
|
runningTorrents := tclient.Torrents()
|
||||||
if missingMB == 0 {
|
|
||||||
c.ETA = "Done"
|
TorrentPeerList := PeerFileList{}
|
||||||
} else if c.downloadSpeedInt == 0 {
|
for _, singleTorrent := range runningTorrents {
|
||||||
c.ETA = "N/A"
|
tempHash := singleTorrent.InfoHash()
|
||||||
} else {
|
if tempHash.AsString() == selectedHash {
|
||||||
ETASeconds := missingMB / c.downloadSpeedInt
|
TorrentPeerList.MessageType = "torrentPeerList"
|
||||||
str := secondsToMinutes(ETASeconds) //converting seconds to minutes + seconds
|
TorrentPeerList.TotalPeers = len(TorrentPeerList.PeerList)
|
||||||
c.ETA = str
|
TorrentPeerList.PeerList = singleTorrent.KnownSwarm()
|
||||||
|
return TorrentPeerList
|
||||||
|
break //only looking for one result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return TorrentPeerList
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateTorrentStatus(t *torrent.Torrent, c *Main.ClientDB) {
|
//CreateTorrentDetailJSON creates the json response for a request for more torrent information
|
||||||
if t.Seeding() && t.Stats().ActivePeers > 0 && t.BytesMissing() == 0 {
|
func CreateTorrentDetailJSON(tclient *torrent.Client, selectedHash string, torrentStorage *bolt.DB) ClientDB {
|
||||||
c.Status = "Seeding"
|
|
||||||
} else if t.Stats().ActivePeers > 0 && t.BytesMissing() > 0 {
|
localTorrentInfo := Storage.FetchTorrentFromStorage(torrentStorage, []byte(selectedHash))
|
||||||
c.Status = "Downloading"
|
|
||||||
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() == 0 {
|
runningTorrents := tclient.Torrents()
|
||||||
c.Status = "Completed"
|
|
||||||
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() > 0 {
|
TorrentDetailStruct := ClientDB{}
|
||||||
c.Status = "Awaiting Peers"
|
for _, singleTorrent := range runningTorrents { //ranging through the running torrents to find the one we are looking for
|
||||||
} else {
|
tempHash := singleTorrent.InfoHash()
|
||||||
c.Status = "Unknown"
|
if tempHash.AsString() == selectedHash {
|
||||||
|
fmt.Println("CreateTorrentDetail", localTorrentInfo)
|
||||||
|
return TorrentDetailStruct
|
||||||
|
break //only looking for one result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return TorrentDetailStruct
|
||||||
}
|
}
|
||||||
|
105
engine/engineMaths.go
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package engine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/anacrolix/torrent"
|
||||||
|
)
|
||||||
|
|
||||||
|
func secondsToMinutes(inSeconds int64) string {
|
||||||
|
minutes := inSeconds / 60
|
||||||
|
seconds := inSeconds % 60
|
||||||
|
minutesString := fmt.Sprintf("%d", minutes)
|
||||||
|
secondsString := fmt.Sprintf("%d", seconds)
|
||||||
|
str := minutesString + " Min/ " + secondsString + " Sec"
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
//ConvertSizetoGB changes the sizes
|
||||||
|
func ConvertSizetoGB(t float32, d float32) (tDelta string, dDelta string) { //converting sizes to MB or GB as needed and adding string
|
||||||
|
if t > 1024 && d > 1024 {
|
||||||
|
t := fmt.Sprintf("%.2f", t/1024)
|
||||||
|
t = t + " GB"
|
||||||
|
d := fmt.Sprintf("%.2f", d/1024)
|
||||||
|
d = d + " GB"
|
||||||
|
return t, d
|
||||||
|
} else if d > 1024 || t > 1024 {
|
||||||
|
if d > 1024 {
|
||||||
|
d := fmt.Sprintf("%.2f", d/1024)
|
||||||
|
d = d + " GB"
|
||||||
|
t := fmt.Sprintf("%.2f", t)
|
||||||
|
t = t + " MB"
|
||||||
|
return t, d
|
||||||
|
}
|
||||||
|
d := fmt.Sprintf("%.2f", d)
|
||||||
|
d = d + " MB"
|
||||||
|
t := fmt.Sprintf("%.2f", t/1024)
|
||||||
|
t = t + " GB"
|
||||||
|
return t, d
|
||||||
|
} else {
|
||||||
|
d := fmt.Sprintf("%.2f", d)
|
||||||
|
t := fmt.Sprintf("%.2f", t)
|
||||||
|
t = t + " MB"
|
||||||
|
d = d + " MB"
|
||||||
|
return t, d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//CalculateTorrentSpeed is used to calculate the torrent upload and download speed over time
|
||||||
|
func CalculateTorrentSpeed(t *torrent.Torrent, c *ClientDB, oc ClientDB) {
|
||||||
|
now := time.Now()
|
||||||
|
bytes := t.BytesCompleted()
|
||||||
|
bytesUpload := t.Stats().DataBytesWritten
|
||||||
|
dt := float32(now.Sub(oc.UpdatedAt)) // get the delta time length between now and last updated
|
||||||
|
db := float32(bytes - oc.BytesCompleted) //getting the delta bytes
|
||||||
|
rate := db * (float32(time.Second) / dt) // converting into seconds
|
||||||
|
dbU := float32(bytesUpload - oc.DataBytesWritten)
|
||||||
|
//fmt.Println("BytesWritten", bytesUpload)
|
||||||
|
//fmt.Println("WireBytes", t.Stats().DataBytesWritten)
|
||||||
|
//fmt.Println("ChunksWritten", t.Stats().ChunksWritten)
|
||||||
|
rateUpload := dbU * (float32(time.Second) / dt)
|
||||||
|
if rate >= 0 {
|
||||||
|
rate = rate / 1024 / 1024 //creating integer to calculate ETA
|
||||||
|
c.DownloadSpeed = fmt.Sprintf("%.2f", rate)
|
||||||
|
c.DownloadSpeed = c.DownloadSpeed + " MB/s"
|
||||||
|
c.downloadSpeedInt = int64(rate)
|
||||||
|
}
|
||||||
|
if rateUpload >= 0 {
|
||||||
|
rateUpload = rateUpload / 1024 / 1024
|
||||||
|
c.UploadSpeed = fmt.Sprintf("%.2f", rateUpload)
|
||||||
|
c.UploadSpeed = c.UploadSpeed + " MB/s"
|
||||||
|
|
||||||
|
}
|
||||||
|
c.UpdatedAt = now
|
||||||
|
}
|
||||||
|
|
||||||
|
//CalculateTorrentETA is used to estimate the remaining dl time of the torrent based on the speed that the MB are being downloaded
|
||||||
|
func CalculateTorrentETA(t *torrent.Torrent, c *ClientDB) {
|
||||||
|
missingBytes := t.Length() - t.BytesCompleted()
|
||||||
|
missingMB := missingBytes / 1024 / 1024
|
||||||
|
if missingMB == 0 {
|
||||||
|
c.ETA = "Done"
|
||||||
|
} else if c.downloadSpeedInt == 0 {
|
||||||
|
c.ETA = "N/A"
|
||||||
|
} else {
|
||||||
|
ETASeconds := missingMB / c.downloadSpeedInt
|
||||||
|
str := secondsToMinutes(ETASeconds) //converting seconds to minutes + seconds
|
||||||
|
c.ETA = str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//CalculateTorrentStatus is used to determine what the STATUS column of the frontend will display ll2
|
||||||
|
func CalculateTorrentStatus(t *torrent.Torrent, c *ClientDB) {
|
||||||
|
if t.Seeding() && t.Stats().ActivePeers > 0 && t.BytesMissing() == 0 {
|
||||||
|
c.Status = "Seeding"
|
||||||
|
} else if t.Stats().ActivePeers > 0 && t.BytesMissing() > 0 {
|
||||||
|
c.Status = "Downloading"
|
||||||
|
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() == 0 {
|
||||||
|
c.Status = "Completed"
|
||||||
|
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() > 0 {
|
||||||
|
c.Status = "Awaiting Peers"
|
||||||
|
} else {
|
||||||
|
c.Status = "Unknown"
|
||||||
|
}
|
||||||
|
}
|
32
engine/settings.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package engine //Settings.go contains all of the program settings
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/anacrolix/dht"
|
||||||
|
"github.com/anacrolix/torrent"
|
||||||
|
)
|
||||||
|
|
||||||
|
//FullCLientSettings struct is a struct that can be read into anacrolix/torrent to setup a torrent client
|
||||||
|
type FullClientSettings struct {
|
||||||
|
Version int
|
||||||
|
torrent.Config
|
||||||
|
TFileUploadFolder string
|
||||||
|
}
|
||||||
|
|
||||||
|
//FullClientSettingsNew creates a new torrent client config TODO read from a TOML file
|
||||||
|
func FullClientSettingsNew() FullClientSettings {
|
||||||
|
//Config := fullClientSettings //generate a new struct
|
||||||
|
|
||||||
|
var Config FullClientSettings
|
||||||
|
|
||||||
|
Config.Version = 1.0
|
||||||
|
Config.DataDir = "downloads" //the full OR relative path of the default download directory for torrents
|
||||||
|
Config.TFileUploadFolder = "uploadedTorrents"
|
||||||
|
Config.Seed = true
|
||||||
|
|
||||||
|
Config.DHTConfig = dht.ServerConfig{
|
||||||
|
StartingNodes: dht.GlobalBootstrapAddrs,
|
||||||
|
}
|
||||||
|
|
||||||
|
return Config
|
||||||
|
|
||||||
|
}
|
282
main.go
@@ -10,17 +10,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent/metainfo"
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
Engine "github.com/deranjer/goTorrent/engine"
|
Engine "github.com/deranjer/goTorrent/engine"
|
||||||
Settings "github.com/deranjer/goTorrent/settings"
|
|
||||||
Storage "github.com/deranjer/goTorrent/storage"
|
Storage "github.com/deranjer/goTorrent/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,160 +33,18 @@ var upgrader = websocket.Upgrader{
|
|||||||
WriteBufferSize: 1024,
|
WriteBufferSize: 1024,
|
||||||
}
|
}
|
||||||
|
|
||||||
type torrentList struct { //helps create the JSON structure that react expects to recieve
|
|
||||||
Totaltorrents int `json:"total"`
|
|
||||||
ClientDBstruct []ClientDB `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ClientDB struct {
|
|
||||||
TorrentName string `json:"TorrentName"`
|
|
||||||
DownloadedSize string `json:"DownloadedSize"`
|
|
||||||
Size string `json:"Size"`
|
|
||||||
DownloadSpeed string `json:"DownloadSpeed"`
|
|
||||||
downloadSpeedInt int64
|
|
||||||
UploadSpeed string `json:"UploadSpeed"`
|
|
||||||
//UploadSpeedInt int64
|
|
||||||
DataBytesWritten int64
|
|
||||||
DataBytesRead int64
|
|
||||||
ActivePeers string `json:"ActivePeers"`
|
|
||||||
TorrentHashString string `json:"TorrentHashString"`
|
|
||||||
PercentDone string `json:"PercentDone"`
|
|
||||||
TorrentHash metainfo.Hash
|
|
||||||
StoragePath string `json:"StorageLocation"`
|
|
||||||
DateAdded string
|
|
||||||
KnownSwarm []torrent.Peer
|
|
||||||
Status string `json:"Status"`
|
|
||||||
BytesCompleted int64
|
|
||||||
UpdatedAt time.Time
|
|
||||||
ETA string `json:"ETA"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func serveHome(w http.ResponseWriter, r *http.Request) {
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
||||||
s1, _ := template.ParseFiles("templates/home.tmpl")
|
s1, _ := template.ParseFiles("templates/home.tmpl")
|
||||||
s1.ExecuteTemplate(w, "base", map[string]string{"APP_ID": APP_ID})
|
s1.ExecuteTemplate(w, "base", map[string]string{"APP_ID": APP_ID})
|
||||||
}
|
}
|
||||||
|
|
||||||
func timeOutInfo(clientTorrent *torrent.Torrent, seconds time.Duration) (deleted bool) { //forcing a timeout of the
|
func updateClient(torrentstats []Engine.ClientDB, conn *websocket.Conn) { //get the torrent client and the websocket connection to write msg
|
||||||
timeout := make(chan bool, 1) //creating a timeout channel for our gotinfo
|
|
||||||
go func() {
|
|
||||||
time.Sleep(seconds * time.Second)
|
|
||||||
timeout <- true
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-clientTorrent.GotInfo(): //attempting to retrieve info for torrent
|
|
||||||
fmt.Println("Recieved torrent info..")
|
|
||||||
clientTorrent.DownloadAll()
|
|
||||||
return false
|
|
||||||
case <-timeout: // getting info for torrent has timed out so purging the torrent
|
|
||||||
fmt.Println("Dropping Torrent")
|
|
||||||
clientTorrent.Drop()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func startTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage *Storage.TorrentLocal, torrentDbStorage *bolt.DB, dataDir string, torrentFile string, torrentFileName string) {
|
|
||||||
|
|
||||||
timeOutInfo(clientTorrent, 45) //seeing if adding the torrrent times out (giving 45 seconds)
|
|
||||||
var TempHash metainfo.Hash
|
|
||||||
TempHash = clientTorrent.InfoHash()
|
|
||||||
fmt.Println(clientTorrent.Info().Source)
|
|
||||||
torrentLocalStorage.Hash = TempHash.String() // we will store the infohash to add it back later on client restart (if needed)
|
|
||||||
torrentLocalStorage.DateAdded = time.Now().Format("Jan _2 2006")
|
|
||||||
torrentLocalStorage.StoragePath = dataDir //TODO check full path information for torrent storage
|
|
||||||
torrentLocalStorage.TorrentName = clientTorrent.Name()
|
|
||||||
torrentLocalStorage.TorrentStatus = "downloading" //by default start all the torrents as downloading.
|
|
||||||
torrentLocalStorage.TorrentType = torrentFile //either "file" or "magnet" maybe more in the future
|
|
||||||
if torrentFile == "file" {
|
|
||||||
torrentLocalStorage.TorrentFileName = torrentFileName
|
|
||||||
} else {
|
|
||||||
torrentLocalStorage.TorrentFileName = ""
|
|
||||||
}
|
|
||||||
fmt.Printf("%+v\n", torrentLocalStorage)
|
|
||||||
Storage.AddTorrentLocalStorage(torrentDbStorage, torrentLocalStorage) //writing all of the data to the database
|
|
||||||
clientTorrent.DownloadAll() //starting the download
|
|
||||||
}
|
|
||||||
|
|
||||||
func createRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Storage.TorrentLocal, PreviousTorrentArray []clientDB, config Settings.FullClientSettings, db *bolt.DB) (RunningTorrentArray []clientDB) {
|
|
||||||
for _, element := range TorrentLocalArray { //re-adding all the torrents we had stored from last shutdown
|
|
||||||
|
|
||||||
var singleTorrent *torrent.Torrent
|
|
||||||
|
|
||||||
if element.TorrentType == "file" { //if it is a file pull it from the uploaded torrent folder
|
|
||||||
//fmt.Println("Filename", element.TorrentFileName)
|
|
||||||
if _, err := os.Stat(element.TorrentFileName); err == nil { //if we CAN find the torrent, add it
|
|
||||||
//fmt.Println("Adding file name...", element.TorrentFileName)
|
|
||||||
singleTorrent, _ = tclient.AddTorrentFromFile(element.TorrentFileName)
|
|
||||||
} else { //if we cant find the torrent delete it
|
|
||||||
fmt.Println("File Error", err)
|
|
||||||
Storage.DelTorrentLocalStorage(db, element)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
elementMagnet := "magnet:?xt=urn:btih:" + element.Hash //For magnet links just need to prepend the magnet part to the hash to readd
|
|
||||||
singleTorrent, _ = tclient.AddMagnet(elementMagnet)
|
|
||||||
}
|
|
||||||
|
|
||||||
timeOut := timeOutInfo(singleTorrent, 45)
|
|
||||||
if timeOut == true { // if we did timeout then drop the torrent from the boltdb database
|
|
||||||
Storage.DelTorrentLocalStorage(db, element) //purging torrent from the local database
|
|
||||||
}
|
|
||||||
|
|
||||||
fullClientDB := new(ClientDB)
|
|
||||||
fullStruct := singleTorrent.Stats()
|
|
||||||
|
|
||||||
//ranging over the previous torrent array to calculate the speed for each torrent
|
|
||||||
if len(PreviousTorrentArray) > 0 { //if we actually have a previous array
|
|
||||||
for _, previousElement := range PreviousTorrentArray {
|
|
||||||
TempHash := singleTorrent.InfoHash()
|
|
||||||
if previousElement.TorrentHashString == TempHash.AsString() { //matching previous to new
|
|
||||||
Engine.CalculateTorrentSpeed(singleTorrent, fullClientDB, previousElement)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
activePeersString := fmt.Sprintf("%v", fullStruct.ActivePeers) //converting to strings
|
|
||||||
totalPeersString := fmt.Sprintf("%v", fullStruct.TotalPeers)
|
|
||||||
bytesCompletedMB := float32(singleTorrent.BytesCompleted() / 1024 / 1024)
|
|
||||||
totalSizeMB := float32(singleTorrent.Length() / 1024 / 1024)
|
|
||||||
//downloadSizeString := fmt.Sprintf("%d", bytesCompletedMB)
|
|
||||||
|
|
||||||
tSize, dSize := convertSizetoGB(totalSizeMB, bytesCompletedMB) //convert size to GB if needed
|
|
||||||
var TempHash metainfo.Hash
|
|
||||||
TempHash = singleTorrent.InfoHash()
|
|
||||||
|
|
||||||
fullClientDB.DownloadedSize = dSize
|
|
||||||
fullClientDB.Size = tSize
|
|
||||||
PercentDone := fmt.Sprintf("%.2f", bytesCompletedMB/totalSizeMB)
|
|
||||||
fullClientDB.TorrentHash = TempHash
|
|
||||||
fullClientDB.PercentDone = PercentDone
|
|
||||||
fullClientDB.DataBytesRead = fullStruct.ConnStats.DataBytesRead
|
|
||||||
fullClientDB.DataBytesWritten = fullStruct.ConnStats.DataBytesWritten
|
|
||||||
fullClientDB.ActivePeers = activePeersString + " / (" + totalPeersString + ")"
|
|
||||||
fullClientDB.TorrentHashString = TempHash.AsString()
|
|
||||||
fullClientDB.StoragePath = element.StoragePath
|
|
||||||
fullClientDB.TorrentName = element.TorrentName
|
|
||||||
fullClientDB.DateAdded = element.DateAdded
|
|
||||||
fullClientDB.BytesCompleted = singleTorrent.BytesCompleted()
|
|
||||||
calculateTorrentETA(singleTorrent, fullClientDB) //calculating the ETA for the torrent
|
|
||||||
//fmt.Println("Download Speed: ", fullClientDB.DownloadSpeed)
|
|
||||||
//fmt.Println("Percent Done: ", fullClientDB.PercentDone)
|
|
||||||
//tclient.WriteStatus(os.Stdout)
|
|
||||||
calculateTorrentStatus(singleTorrent, fullClientDB) //calculate the status of the torrent, ie downloading seeding etc
|
|
||||||
|
|
||||||
RunningTorrentArray = append(RunningTorrentArray, *fullClientDB)
|
|
||||||
|
|
||||||
}
|
|
||||||
return RunningTorrentArray
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateClient(torrentstats []clientDB, conn *websocket.Conn) { //get the torrent client and the websocket connection to write msg
|
|
||||||
conn.WriteJSON(torrentstats) //converting to JSON and writing to the client
|
conn.WriteJSON(torrentstats) //converting to JSON and writing to the client
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//setting up the torrent client
|
//setting up the torrent client
|
||||||
Config := Settings.FullClientSettingsNew() //grabbing from settings.go
|
Config := Engine.FullClientSettingsNew() //grabbing from settings.go
|
||||||
os.Mkdir(Config.TFileUploadFolder, os.ModeDir) //creating a directory to store uploaded torrent files
|
os.Mkdir(Config.TFileUploadFolder, os.ModeDir) //creating a directory to store uploaded torrent files
|
||||||
torrentLocalStorage := new(Storage.TorrentLocal) //creating a new struct that stores all of our local storage info
|
torrentLocalStorage := new(Storage.TorrentLocal) //creating a new struct that stores all of our local storage info
|
||||||
|
|
||||||
@@ -208,13 +62,13 @@ func main() {
|
|||||||
defer db.Close() //defering closing the database until the program closes
|
defer db.Close() //defering closing the database until the program closes
|
||||||
|
|
||||||
var TorrentLocalArray = []*Storage.TorrentLocal{} //this is an array of ALL of the local storage torrents, they will be added back in via hash
|
var TorrentLocalArray = []*Storage.TorrentLocal{} //this is an array of ALL of the local storage torrents, they will be added back in via hash
|
||||||
var RunningTorrentArray = []clientDB{} //this stores ALL of the torrents that are running, used for client update pushes combines Local Storage and Running tclient info
|
var RunningTorrentArray = []Engine.ClientDB{} //this stores ALL of the torrents that are running, used for client update pushes combines Local Storage and Running tclient info
|
||||||
var PreviousTorrentArray = []clientDB{}
|
var PreviousTorrentArray = []Engine.ClientDB{}
|
||||||
|
|
||||||
TorrentLocalArray = Storage.ReadInTorrents(db) //pulling in all the already added torrents
|
TorrentLocalArray = Storage.ReadInTorrents(db) //pulling in all the already added torrents
|
||||||
|
|
||||||
if TorrentLocalArray != nil { //the first creation of the running torrent array
|
if TorrentLocalArray != nil { //the first creation of the running torrent array
|
||||||
RunningTorrentArray = createRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Database is empty!")
|
fmt.Println("Database is empty!")
|
||||||
@@ -224,12 +78,14 @@ func main() {
|
|||||||
router.HandleFunc("/", serveHome) //Serving the main page for our SPA
|
router.HandleFunc("/", serveHome) //Serving the main page for our SPA
|
||||||
http.Handle("/static/", http.FileServer(http.Dir("public")))
|
http.Handle("/static/", http.FileServer(http.Dir("public")))
|
||||||
http.Handle("/", router)
|
http.Handle("/", router)
|
||||||
http.HandleFunc("/uploadTorrent", func(w http.ResponseWriter, r *http.Request) { //grabbing the uploaded Torrent File and adding it to the client
|
http.HandleFunc("/uploadTorrent", func(w http.ResponseWriter, r *http.Request) { //grabbing the uploaded Torrent File and adding it to the client TODO figure out websocket
|
||||||
defer http.Redirect(w, r, "/", 301)
|
defer http.Redirect(w, r, "/", 301) //forcing redirect to home page after file is processed
|
||||||
file, header, err := r.FormFile("fileTest")
|
file, header, err := r.FormFile("fileTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error with fetching file or request issue", file)
|
fmt.Println("Error with fetching file or request issue", file)
|
||||||
}
|
}
|
||||||
|
//torrentFileBytes, err := ioutil.ReadAll(file) TODO dump a byte slice directly into the filename
|
||||||
|
|
||||||
defer file.Close() //defer closing the file until we are done manipulating it
|
defer file.Close() //defer closing the file until we are done manipulating it
|
||||||
var filePath = filepath.Join(Config.TFileUploadFolder, header.Filename) //creating a full filepath to store the .torrent files
|
var filePath = filepath.Join(Config.TFileUploadFolder, header.Filename) //creating a full filepath to store the .torrent files
|
||||||
fileName, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666) //generating the fileName
|
fileName, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666) //generating the fileName
|
||||||
@@ -242,15 +98,16 @@ func main() {
|
|||||||
fmt.Println("Error adding Torrent from file: ", fileName.Name())
|
fmt.Println("Error adding Torrent from file: ", fileName.Name())
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Adding Torrent via file", fileName)
|
fmt.Println("Adding Torrent via file", fileName)
|
||||||
startTorrent(clientTorrent, torrentLocalStorage, db, Config.DataDir, "file", fileName.Name())
|
Engine.StartTorrent(clientTorrent, torrentLocalStorage, db, Config.DataDir, "file", fileName.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) { //exposing the data to the
|
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) { //exposing the data to the
|
||||||
TorrentLocalArray = Storage.ReadInTorrents(db)
|
TorrentLocalArray = Storage.ReadInTorrents(db)
|
||||||
RunningTorrentArray = createRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
||||||
var torrentlistArray = new(torrentList) //the full JSON that includes the number of torrents as the root
|
var torrentlistArray = new(Engine.TorrentList)
|
||||||
torrentlistArray.ClientDBstruct = RunningTorrentArray
|
torrentlistArray.MessageType = "torrentList" //setting the type of message
|
||||||
|
torrentlistArray.ClientDBstruct = RunningTorrentArray //the full JSON that includes the number of torrents as the root
|
||||||
torrentlistArray.Totaltorrents = len(RunningTorrentArray)
|
torrentlistArray.Totaltorrents = len(RunningTorrentArray)
|
||||||
torrentlistArrayJSON, _ := json.Marshal(torrentlistArray)
|
torrentlistArrayJSON, _ := json.Marshal(torrentlistArray)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@@ -261,60 +118,113 @@ func main() {
|
|||||||
conn, err := upgrader.Upgrade(w, r, nil)
|
conn, err := upgrader.Upgrade(w, r, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println("Generic websocket error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
msgType, msg, err := conn.ReadMessage()
|
runningTorrents := tclient.Torrents() //getting running torrents here since multiple cases ask for the running torrents
|
||||||
if err != nil {
|
msg := Engine.Message{}
|
||||||
fmt.Println("Read Message Error", err)
|
readJSONError := conn.ReadJSON(&msg)
|
||||||
return
|
if readJSONError != nil {
|
||||||
|
fmt.Println("Unable to read JSON client message", err)
|
||||||
}
|
}
|
||||||
if string(msg) == "clientUpdateRequest" { //6 second update ping
|
|
||||||
fmt.Println("client Requested Update")
|
|
||||||
//time.Sleep(6 * time.Second)
|
|
||||||
err = conn.WriteMessage(msgType, []byte("clientUpdate"))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Websocket Write err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fmt.Println("MessageType", msg.MessageType)
|
||||||
|
switch msg.MessageType { //first handling data requests
|
||||||
|
|
||||||
|
case "torrentListRequest":
|
||||||
|
fmt.Println("client Requested TorrentList Update")
|
||||||
TorrentLocalArray = Storage.ReadInTorrents(db)
|
TorrentLocalArray = Storage.ReadInTorrents(db)
|
||||||
RunningTorrentArray = createRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
||||||
PreviousTorrentArray = RunningTorrentArray
|
PreviousTorrentArray = RunningTorrentArray
|
||||||
var torrentlistArray = new(torrentList)
|
var torrentlistArray = new(Engine.TorrentList)
|
||||||
|
torrentlistArray.MessageType = "torrentList"
|
||||||
torrentlistArray.ClientDBstruct = RunningTorrentArray
|
torrentlistArray.ClientDBstruct = RunningTorrentArray
|
||||||
torrentlistArray.Totaltorrents = len(RunningTorrentArray)
|
torrentlistArray.Totaltorrents = len(RunningTorrentArray)
|
||||||
//fmt.Printf("%+v\n", torrentlistArray)
|
//fmt.Printf("%+v\n", torrentlistArray)
|
||||||
conn.WriteJSON(torrentlistArray)
|
conn.WriteJSON(torrentlistArray)
|
||||||
|
break
|
||||||
//updateClient(RunningTorrentArray, conn) // sending the client update information over the websocket
|
//updateClient(RunningTorrentArray, conn) // sending the client update information over the websocket
|
||||||
|
|
||||||
} else if strings.HasPrefix(string(msg), "magnet:") {
|
case "torrentFileListRequest": //client requested a filelist update
|
||||||
fmt.Println(string(msg))
|
fmt.Println("client Requested Filelist update")
|
||||||
clientTorrent, err := tclient.AddMagnet(string(msg))
|
fileListRequest := Engine.GenericPayload{}
|
||||||
|
json.Unmarshal(msg.Payload, &fileListRequest) //unmarshal into the generic payload
|
||||||
|
FileListArray := Engine.CreateFileListArray(tclient, fileListRequest.TorrentHashString)
|
||||||
|
conn.WriteJSON(FileListArray) //writing the JSON to the client
|
||||||
|
break
|
||||||
|
|
||||||
|
case "torrentDetailedInfo": //TODO Figure out how to get single torrent info correctly
|
||||||
|
fmt.Println("client requested detailed Torrent Info")
|
||||||
|
torrentDetailRequest := Engine.GenericPayload{}
|
||||||
|
json.Unmarshal(msg.Payload, &torrentDetailRequest)
|
||||||
|
torrentDetailArray := Engine.CreateTorrentDetailJSON(tclient, torrentDetailRequest.TorrentHashString, db)
|
||||||
|
conn.WriteJSON(torrentDetailArray)
|
||||||
|
break
|
||||||
|
|
||||||
|
case "magnetLinkSubmit": //if we detect a magnet link we will be adding a magnet torrent
|
||||||
|
magnetMessage := Engine.MagnetMessage{} //grabbing a magnetMessage struct from engine->clientstructs
|
||||||
|
json.Unmarshal(msg.Payload, &magnetMessage) //unmarshalling the "Payload" from Message into our magnetmessage struct
|
||||||
|
clientTorrent, err := tclient.AddMagnet(magnetMessage.MagnetLink) //reading the payload into the torrent client
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Magnet Error", err)
|
fmt.Println("Magnet Error", err)
|
||||||
}
|
}
|
||||||
fmt.Println(clientTorrent)
|
fmt.Println(clientTorrent)
|
||||||
fmt.Printf("Adding Magnet Link")
|
fmt.Printf("Adding Magnet Link")
|
||||||
|
|
||||||
startTorrent(clientTorrent, torrentLocalStorage, db, Config.DataDir, "magnet", "") //starting the torrent and creating local DB entry
|
Engine.StartTorrent(clientTorrent, torrentLocalStorage, db, Config.DataDir, "magnet", "") //starting the torrent and creating local DB entry
|
||||||
|
break
|
||||||
|
|
||||||
} else if string(msg) == "torrentFileListRequest" { //client requested a filelist update
|
case "stopTorrents":
|
||||||
fmt.Println("client Requested Filelist update")
|
TorrentListCommands := Engine.TorrentCommandMessage{}
|
||||||
err = conn.WriteMessage(msgType, []byte("fileListUpdate"))
|
json.Unmarshal(msg.Payload, &TorrentListCommands)
|
||||||
if err != nil {
|
for _, singleTorrent := range runningTorrents {
|
||||||
fmt.Println("Websocket Write err", err)
|
|
||||||
return
|
for _, singleSelection := range TorrentListCommands.TorrentHashStrings {
|
||||||
|
if singleTorrent.InfoHash().AsString() == singleSelection {
|
||||||
|
fmt.Println("Matched for stopping torrents")
|
||||||
|
//singleTorrent.Drop()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
|
||||||
} else {
|
case "deleteTorrents":
|
||||||
conn.Close()
|
TorrentListCommands := Engine.TorrentCommandMessage{}
|
||||||
fmt.Println(string(msg))
|
json.Unmarshal(msg.Payload, &TorrentListCommands)
|
||||||
|
for _, singleTorrent := range runningTorrents {
|
||||||
|
|
||||||
|
for _, singleSelection := range TorrentListCommands.TorrentHashStrings {
|
||||||
|
if singleTorrent.InfoHash().AsString() == singleSelection {
|
||||||
|
fmt.Println("Matched for deleting torrents")
|
||||||
|
singleTorrent.Drop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case "startTorrents":
|
||||||
|
fmt.Println("Starting torrents")
|
||||||
|
TorrentListCommands := Engine.TorrentCommandMessage{}
|
||||||
|
json.Unmarshal(msg.Payload, &TorrentListCommands)
|
||||||
|
for _, singleTorrent := range runningTorrents {
|
||||||
|
|
||||||
|
for _, singleSelection := range TorrentListCommands.TorrentHashStrings {
|
||||||
|
if singleTorrent.InfoHash().AsString() == singleSelection {
|
||||||
|
fmt.Println("Matched for starting torrents")
|
||||||
|
singleTorrent.DownloadAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
//conn.Close()
|
||||||
|
fmt.Println("Message not found, message recieved is: ", msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
if err := http.ListenAndServe(*httpAddr, nil); err != nil {
|
if err := http.ListenAndServe(*httpAddr, nil); err != nil {
|
||||||
log.Fatalf("Error listening, %v", err)
|
log.Fatalf("Error listening, %v", err)
|
||||||
|
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 546 B |
Before Width: | Height: | Size: 913 B |
Before Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 794 B |
Before Width: | Height: | Size: 753 B |
Before Width: | Height: | Size: 506 B |
Before Width: | Height: | Size: 787 B |
Before Width: | Height: | Size: 251 B |
Before Width: | Height: | Size: 850 B |
Before Width: | Height: | Size: 565 B |
Before Width: | Height: | Size: 579 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 524 B |
Before Width: | Height: | Size: 219 B |
Before Width: | Height: | Size: 539 B |
Before Width: | Height: | Size: 728 B |
Before Width: | Height: | Size: 470 B |
Before Width: | Height: | Size: 1014 B |
@@ -1,49 +0,0 @@
|
|||||||
// Get the modal
|
|
||||||
var modal = document.getElementById('addTorrentModal');
|
|
||||||
|
|
||||||
// Get the button that opens the modal
|
|
||||||
var btn = document.getElementById("addTorrentLink");
|
|
||||||
|
|
||||||
// Get the <span> element that closes the modal
|
|
||||||
var span = document.getElementsByClassName("addTorrentModalClose")[0];
|
|
||||||
|
|
||||||
|
|
||||||
// When the user clicks the button, open the modal
|
|
||||||
btn.onclick = function() {
|
|
||||||
modal.style.display = "block";
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the user clicks on <span> (x), close the modal
|
|
||||||
span.onclick = function() {
|
|
||||||
modal.style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the user clicks anywhere outside of the modal, close it
|
|
||||||
window.onclick = function(event) {
|
|
||||||
if (event.target == modal) {
|
|
||||||
modal.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var torrentFileModal = document.getElementById('addTorrentFileModal');
|
|
||||||
|
|
||||||
var btnTorrentFile = document.getElementById("addTorrentFile");
|
|
||||||
|
|
||||||
var spanTorrentFile = document.getElementsByClassName("addTorrentFileModalClose")[0];
|
|
||||||
|
|
||||||
|
|
||||||
btnTorrentFile.onclick = function() {
|
|
||||||
torrentFileModal.style.display = "block";
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the user clicks on <span> (x), close the modal
|
|
||||||
spanTorrentFile.onclick = function() {
|
|
||||||
torrentFileModal.style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the user clicks anywhere outside of the modal, close it
|
|
||||||
window.onclick = function(event) {
|
|
||||||
if (event.target == torrentFileModal) {
|
|
||||||
torrentFileModal.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
@@ -73459,7 +73459,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|||||||
|
|
||||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // contains the font for material UI
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // contains the font for material UI
|
||||||
|
|
||||||
//import PhotoCamera from 'material-ui-icons/PhotoCamera';
|
|
||||||
|
|
||||||
//Redux
|
//Redux
|
||||||
|
|
||||||
@@ -73504,6 +73503,16 @@ var IconButtons = function (_React$Component) {
|
|||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, (IconButtons.__proto__ || Object.getPrototypeOf(IconButtons)).call(this, props));
|
var _this = _possibleConstructorReturn(this, (IconButtons.__proto__ || Object.getPrototypeOf(IconButtons)).call(this, props));
|
||||||
|
|
||||||
|
_this.startTorrentState = {
|
||||||
|
messageType: "startTorrents",
|
||||||
|
Payload: _this.props.selection
|
||||||
|
};
|
||||||
|
|
||||||
|
_this.startTorrent = function (selection) {
|
||||||
|
console.log("Starting Torrents", selection);
|
||||||
|
ws.send();
|
||||||
|
};
|
||||||
|
|
||||||
_this.buttonHandler = function (buttonState) {
|
_this.buttonHandler = function (buttonState) {
|
||||||
console.log("BUTTONSTATE", buttonState);
|
console.log("BUTTONSTATE", buttonState);
|
||||||
};
|
};
|
||||||
@@ -73582,15 +73591,14 @@ IconButtons.propTypes = {
|
|||||||
|
|
||||||
var mapStateToProps = function mapStateToProps(state) {
|
var mapStateToProps = function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
buttonState: state.buttonState
|
buttonState: state.buttonState,
|
||||||
|
selection: state.selection
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var mapDispatchToProps = function mapDispatchToProps(dispatch) {
|
var mapDispatchToProps = function mapDispatchToProps(dispatch) {
|
||||||
return {
|
return {
|
||||||
changeSelection: function changeSelection(selection) {
|
//changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection: selection})
|
||||||
return dispatch({ type: actionTypes.CHANGE_SELECTION, selection: selection });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81221,9 +81229,13 @@ var addTorrentPopup = function (_React$Component) {
|
|||||||
_this.setState({ open: false });
|
_this.setState({ open: false });
|
||||||
}, _this.handleSubmit = function () {
|
}, _this.handleSubmit = function () {
|
||||||
_this.setState({ open: false });
|
_this.setState({ open: false });
|
||||||
var magnetLinkSubmit = _this.state.textValue;
|
//let magnetLinkSubmit = this.state.textValue;
|
||||||
console.log("Sending magnet link: ", magnetLinkSubmit);
|
var magnetLinkMessage = {
|
||||||
ws.send(magnetLinkSubmit);
|
messageType: "magnetLinkSubmit",
|
||||||
|
Payload: { MagnetLink: _this.state.textValue }
|
||||||
|
};
|
||||||
|
console.log("Sending magnet link: ", magnetLinkMessage);
|
||||||
|
ws.send(JSON.stringify(magnetLinkMessage));
|
||||||
}, _this.setTextValue = function (event) {
|
}, _this.setTextValue = function (event) {
|
||||||
_this.setState({ textValue: event.target.value });
|
_this.setState({ textValue: event.target.value });
|
||||||
}, _temp), _possibleConstructorReturn(_this, _ret);
|
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||||
@@ -89953,38 +89965,45 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|||||||
var title = document.title; //Set the number of active torrents in the title
|
var title = document.title; //Set the number of active torrents in the title
|
||||||
var torrents = [];
|
var torrents = [];
|
||||||
|
|
||||||
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined
|
var torrentListRequest = {
|
||||||
ws.onmessage = function (evt) {
|
messageType: "torrentListRequest"
|
||||||
//When we recieve a message from the websocket
|
|
||||||
if (evt.data == "clientUpdate") {
|
|
||||||
console.log("Client Update Incoming...");
|
|
||||||
} else {
|
|
||||||
// recieving data
|
|
||||||
console.log("Recieved Client Update...");
|
|
||||||
var clientUpdate = JSON.parse(evt.data);
|
|
||||||
if (clientUpdate.total) {
|
|
||||||
// if it has a total field it is a torrentlist update
|
|
||||||
torrents = []; //clearing out the torrent array to make room for new (so that it does keep adding)
|
|
||||||
for (var i = 0; i < clientUpdate.total; i++) {
|
|
||||||
torrents.push({
|
|
||||||
TorrentHashString: clientUpdate.data[i].TorrentHash,
|
|
||||||
TorrentName: clientUpdate.data[i].TorrentName,
|
|
||||||
DownloadedSize: clientUpdate.data[i].DownloadedSize,
|
|
||||||
Size: clientUpdate.data[i].Size,
|
|
||||||
DownloadSpeed: clientUpdate.data[i].DownloadSpeed,
|
|
||||||
UploadSpeed: clientUpdate.data[i].UploadSpeed,
|
|
||||||
PercentDone: clientUpdate.data[i].PercentDone,
|
|
||||||
StoragePath: clientUpdate.data[i].StoragePath,
|
|
||||||
DateAdded: clientUpdate.data[i].DateAdded,
|
|
||||||
Status: clientUpdate.data[i].Status,
|
|
||||||
BytesCompleted: clientUpdate.data[i].BytesCompleted,
|
|
||||||
ActivePeers: clientUpdate.data[i].ActivePeers,
|
|
||||||
ETA: clientUpdate.data[i].ETA
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var newTitle = '(' + clientUpdate.total + ')' + title; //updating the title
|
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined 22
|
||||||
document.title = newTitle;
|
};ws.onmessage = function (evt) {
|
||||||
|
//When we recieve a message from the websocket
|
||||||
|
var serverMessage = JSON.parse(evt.data);
|
||||||
|
if (serverMessage.MessageType == "torrentList") {
|
||||||
|
console.log("Recieved Client Update...");
|
||||||
|
//var serverMessage = JSON.parse(evt.data);
|
||||||
|
|
||||||
|
torrents = []; //clearing out the torrent array to make room for new (so that it does keep adding)
|
||||||
|
for (var i = 0; i < serverMessage.total; i++) {
|
||||||
|
torrents.push({
|
||||||
|
TorrentHashString: serverMessage.data[i].TorrentHash,
|
||||||
|
TorrentName: serverMessage.data[i].TorrentName,
|
||||||
|
DownloadedSize: serverMessage.data[i].DownloadedSize,
|
||||||
|
Size: serverMessage.data[i].Size,
|
||||||
|
DownloadSpeed: serverMessage.data[i].DownloadSpeed,
|
||||||
|
UploadSpeed: serverMessage.data[i].UploadSpeed,
|
||||||
|
PercentDone: serverMessage.data[i].PercentDone,
|
||||||
|
StoragePath: serverMessage.data[i].StoragePath,
|
||||||
|
DateAdded: serverMessage.data[i].DateAdded,
|
||||||
|
Status: serverMessage.data[i].Status,
|
||||||
|
BytesCompleted: serverMessage.data[i].BytesCompleted,
|
||||||
|
ActivePeers: serverMessage.data[i].ActivePeers,
|
||||||
|
ETA: serverMessage.data[i].ETA
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var newTitle = '(' + serverMessage.total + ')' + title; //updating the title
|
||||||
|
document.title = newTitle;
|
||||||
|
} else if (serverMessage.MessageType == "fileList") {
|
||||||
|
console.log("Recieved FileListUpdate", serverMessage.fileList);
|
||||||
|
fileList = [];
|
||||||
|
for (var i = 0; i < serverMessage.total; i++) {
|
||||||
|
fileList.push({
|
||||||
|
FileList: serverMessage.fileList[i]
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -90029,11 +90048,8 @@ var BackendSocket = function (_React$Component) {
|
|||||||
}, {
|
}, {
|
||||||
key: 'tick',
|
key: 'tick',
|
||||||
value: function tick() {
|
value: function tick() {
|
||||||
ws.send("clientUpdateRequest"); //talking to the server to get the torrent list
|
ws.send(JSON.stringify(torrentListRequest)); //talking to the server to get the torrent list
|
||||||
this.props.newTorrentList(torrents);
|
this.props.newTorrentList(torrents);
|
||||||
|
|
||||||
//console.log("STATE:", this.state.torrentList)
|
|
||||||
//console.log("Torrents", torrents);
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'render',
|
key: 'render',
|
||||||
@@ -92541,13 +92557,10 @@ var TorrentListTable = function (_React$Component) {
|
|||||||
|
|
||||||
if (selection.length === 0) {
|
if (selection.length === 0) {
|
||||||
//if selection is empty buttons will be default
|
//if selection is empty buttons will be default
|
||||||
console.log("No Selection");
|
|
||||||
_this.props.setButtonState(_this.props.buttonStateDefault); //if no selection dispatch that to redux
|
_this.props.setButtonState(_this.props.buttonStateDefault); //if no selection dispatch that to redux
|
||||||
} else {
|
} else {
|
||||||
// if we have selection continue on with logic to determine button state
|
// if we have selection continue on with logic to determine button state
|
||||||
|
|
||||||
var selectedRows = []; //array of all the selected Rows
|
var selectedRows = []; //array of all the selected Rows
|
||||||
|
|
||||||
selection.forEach(function (element) {
|
selection.forEach(function (element) {
|
||||||
selectedRows.push(_this.props.torrentList[element]); //pushing the selected rows out of torrentlist
|
selectedRows.push(_this.props.torrentList[element]); //pushing the selected rows out of torrentlist
|
||||||
});
|
});
|
||||||
|
@@ -1,74 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"honnef.co/go/js/dom"
|
|
||||||
"github.com/gopherjs/websocket/websocketjs"
|
|
||||||
"github.com/gopherjs/gopherjs/js"
|
|
||||||
"github.com/johanbrandhorst/gopherjs-json"
|
|
||||||
"time"
|
|
||||||
//"honnef.co/go/js/dom"
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
//d = dom.GetWindow().Document() //getting the dom to manipulate it
|
|
||||||
document = dom.GetWindow().Document().(dom.HTMLDocument)
|
|
||||||
//conn = func(){websocketjs.New("ws://192.168.1.141:8000/websocket")}//creating a global JS websocket connection
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func main(){
|
|
||||||
document.AddEventListener("DOMContentLoaded", false, func(_ dom.Event){
|
|
||||||
println("DOMLoaded...")
|
|
||||||
go ready()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func ready(){
|
|
||||||
|
|
||||||
//conn := conn()
|
|
||||||
conn, err := websocketjs.New("ws://192.168.1.141:8000/websocket") // Blocks until connection is established.
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
println("Error creating client websocket connection") // handle error
|
|
||||||
}
|
|
||||||
onOpen := func(ev *js.Object){
|
|
||||||
err := conn.Send("ping!") //on startup send the ping message
|
|
||||||
if err != nil {
|
|
||||||
println("Cannot send ping message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMessage := func(ev *js.Object){
|
|
||||||
messageData := ev.Get("data").String()
|
|
||||||
if messageData == "pong"{ //if the server says a pong, send a ping back
|
|
||||||
time.Sleep(6 * time.Second)
|
|
||||||
conn.Send("ping")
|
|
||||||
} else {
|
|
||||||
clientData, err := json.Unmarshal(messageData)
|
|
||||||
if err != nil {
|
|
||||||
println("Error unmarshalling server message")
|
|
||||||
}
|
|
||||||
|
|
||||||
println(clientData.String())
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClose := func(ev *js.Object){
|
|
||||||
println("Closing Connection....")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
onError := func(ev *js.Object){
|
|
||||||
println("Error....")
|
|
||||||
}
|
|
||||||
|
|
||||||
conn.AddEventListener("open", false, onOpen)
|
|
||||||
conn.AddEventListener("message", false, onMessage)
|
|
||||||
conn.AddEventListener("close", false, onClose)
|
|
||||||
conn.AddEventListener("error", false, onError)
|
|
||||||
|
|
||||||
|
|
||||||
err = conn.Close()
|
|
||||||
}
|
|
@@ -1,102 +0,0 @@
|
|||||||
d := dom.GetWindow().Document() //getting the dom to manipulate it
|
|
||||||
|
|
||||||
logTextArea := d.GetElementByID("loggerData")
|
|
||||||
|
|
||||||
torrentLinkSubmit := d.GetElementByID("torrentLinkSubmit")
|
|
||||||
magnetLink := d.GetElementByID("magnetLink")
|
|
||||||
|
|
||||||
addTorrentModal := d.GetElementByID("addTorrentModal")
|
|
||||||
addTorrentLinkBtn := d.GetElementByID("addTorrentLink") // Get the button that opens the modal
|
|
||||||
|
|
||||||
addTorrentFileModal := d.GetElementByID("addTorrentFile")
|
|
||||||
addTorrentFileModalClose := d.GetElementsByClassName("addTorrentFileModalClose")
|
|
||||||
|
|
||||||
addTorrentModalClose := d.GetElementsByClassName("addTorrentModalClose") // Get the <span> element that closes the modal
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//add magnet link modal
|
|
||||||
addTorrentLinkBtn.AddEventListener("click", false, func(event dom.Event){
|
|
||||||
addTorrentModal.SetAttribute("display", "block")
|
|
||||||
|
|
||||||
})
|
|
||||||
//close torrent link modal
|
|
||||||
addTorrentModalClose[0].AddEventListener("click", false, func(event dom.Event){
|
|
||||||
addTorrentModal.SetAttribute("display", "none")
|
|
||||||
})
|
|
||||||
//show torrent file modal
|
|
||||||
addTorrentFileModal.AddEventListener("click", false, func(event dom.Event){
|
|
||||||
addTorrentFileModal.SetAttribute("display", "block")
|
|
||||||
})
|
|
||||||
//hide torrent file modal
|
|
||||||
addTorrentFileModalClose[0].AddEventListener("click", false, func(event dom.Event){
|
|
||||||
addTorrentFileModal.SetAttribute("display", "none")
|
|
||||||
})
|
|
||||||
|
|
||||||
// When the user clicks anywhere outside of the modal, close it
|
|
||||||
d.AddEventListener("click", false, func(event dom.Event){
|
|
||||||
addTorrentModal.SetAttribute("display", "none")
|
|
||||||
addTorrentLinkBtn.SetAttribute("display", "none")
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//websocket logic
|
|
||||||
conn, err := websocketjs.New("ws://192.168.1.141:8000/websocket") // Blocks until connection is established.
|
|
||||||
if err != nil {
|
|
||||||
println("Error creating client websocket connection") // handle error
|
|
||||||
}
|
|
||||||
|
|
||||||
onOpen := func(ev *js.Object){
|
|
||||||
err := conn.Send("ping!") //on startup send the ping message
|
|
||||||
if err != nil {
|
|
||||||
println("Cannot send ping message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMessage := func(ev *js.Object){
|
|
||||||
messageData := ev.Get("data").String()
|
|
||||||
if messageData == "pong"{ //if the server says a pong, send a ping back
|
|
||||||
time.Sleep(6 * time.Second)
|
|
||||||
conn.Send("ping")
|
|
||||||
} else {
|
|
||||||
clientData, err := json.Unmarshal(messageData)
|
|
||||||
if err != nil {
|
|
||||||
println("Error unmarshalling server message")
|
|
||||||
}
|
|
||||||
|
|
||||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Client Update Event....")
|
|
||||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + clientData.String())
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClose := func(ev *js.Object){
|
|
||||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Connection closed")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
onError := func(ev *js.Object){
|
|
||||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Error opening websocket")
|
|
||||||
}
|
|
||||||
|
|
||||||
conn.AddEventListener("open", false, onOpen)
|
|
||||||
conn.AddEventListener("message", false, onMessage)
|
|
||||||
conn.AddEventListener("close", false, onClose)
|
|
||||||
conn.AddEventListener("error", false, onError)
|
|
||||||
|
|
||||||
|
|
||||||
err = conn.Close()
|
|
||||||
|
|
||||||
torrentLinkSubmit.AddEventListener("click", false, func(event dom.Event){ //listening to the submit button for magnet link
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
conn.Send(magnetLink.TextContent())
|
|
||||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Adding Magnet Link: " + magnetLink.TextContent()) //adding the magnet link to the log
|
|
||||||
addTorrentModal.SetAttribute("display", "none")
|
|
||||||
magnetLink.SetTextContent("")
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
@@ -1,7 +1,12 @@
|
|||||||
var ws = new WebSocket("ws://192.168.1.141:8000/websocket"); //creating websocket
|
var ws = new WebSocket("ws://192.168.1.141:8000/websocket"); //creating websocket
|
||||||
|
|
||||||
|
var kickStart = {
|
||||||
|
messageType: "torrentListRequest"
|
||||||
|
}
|
||||||
|
|
||||||
ws.onopen = function()
|
ws.onopen = function()
|
||||||
{
|
{
|
||||||
ws.send("clientUpdateRequest"); //sending out the first ping
|
|
||||||
console.log("Kicking off websocket to server on 192.168.1.141.....")
|
ws.send(JSON.stringify(kickStart)); //sending out the first ping
|
||||||
|
console.log("Kicking off websocket to server on 192.168.1.141.....", JSON.stringify(kickStart))
|
||||||
};
|
};
|
@@ -1,13 +0,0 @@
|
|||||||
function openTab(evt, tabName) {
|
|
||||||
var i, x, tablinks;
|
|
||||||
x = document.getElementsByClassName("tab");
|
|
||||||
for (i = 0; i < x.length; i++) {
|
|
||||||
x[i].style.display = "none";
|
|
||||||
}
|
|
||||||
tablinks = document.getElementsByClassName("tablink");
|
|
||||||
for (i = 0; i < x.length; i++) {
|
|
||||||
tablinks[i].className = tablinks[i].className.replace(" activeButton", "");
|
|
||||||
}
|
|
||||||
document.getElementById(tabName).style.display = "block";
|
|
||||||
evt.currentTarget.className += " activeButton";
|
|
||||||
}
|
|
@@ -1,65 +0,0 @@
|
|||||||
function myWebsocketStart()
|
|
||||||
{
|
|
||||||
|
|
||||||
var torrentLinkSubmit = document.getElementById('torrentLinkSubmit');
|
|
||||||
var magnetLink = document.getElementById('magnetLink');
|
|
||||||
var addTorrentModal = document.getElementById('addTorrentModal');
|
|
||||||
var myTextArea = document.getElementById("loggerData");
|
|
||||||
var torrentHash = document.getElementById("hash");
|
|
||||||
|
|
||||||
|
|
||||||
var ws = new WebSocket("ws://192.168.1.141:8000/websocket"); //creating websocket
|
|
||||||
|
|
||||||
ws.onopen = function()
|
|
||||||
{
|
|
||||||
// Web Socket is connected, send data using send()
|
|
||||||
ws.send("ping");
|
|
||||||
|
|
||||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + "First message sent";
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onmessage = function (evt)
|
|
||||||
{
|
|
||||||
var myTextArea = document.getElementById("loggerData");
|
|
||||||
if(evt.data == "pong") {
|
|
||||||
setTimeout(function(){ws.send("ping");}, 2000);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var clientUpdate = JSON.parse(evt.data);
|
|
||||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + "Client Update Event...";
|
|
||||||
//myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + clientUpdate.LocalTorrentInfo.DateAdded;
|
|
||||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + evt.data;
|
|
||||||
//myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + clientUpdate[0].TorrentHashString;
|
|
||||||
|
|
||||||
//torrentHash.innerHTML = "Hash: " + clientUpdate[0].TorrentHashString;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onclose = function()
|
|
||||||
{
|
|
||||||
var myTextArea = document.getElementById("loggerData");
|
|
||||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + "Connection closed";
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
torrentLinkSubmit.onclick = function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
var magnetLinkjs = magnetLink.value;
|
|
||||||
|
|
||||||
ws.send(magnetLinkjs);
|
|
||||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br> Send:" + magnetLinkjs
|
|
||||||
addTorrentModal.style.display = "none";
|
|
||||||
magnetLink.value = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendEvent(message)
|
|
||||||
{
|
|
||||||
ws.send(message);
|
|
||||||
}
|
|
@@ -1,4 +1,4 @@
|
|||||||
package settings
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anacrolix/dht"
|
"github.com/anacrolix/dht"
|
||||||
|
@@ -16,6 +16,7 @@ type TorrentLocal struct {
|
|||||||
TorrentStatus string
|
TorrentStatus string
|
||||||
TorrentType string //magnet or .torrent file
|
TorrentType string //magnet or .torrent file
|
||||||
TorrentFileName string
|
TorrentFileName string
|
||||||
|
Label string //for labeling torrent files
|
||||||
}
|
}
|
||||||
|
|
||||||
//ReadInTorrents is called to read in ALL local stored torrents in the boltdb database (called on server restart)
|
//ReadInTorrents is called to read in ALL local stored torrents in the boltdb database (called on server restart)
|
||||||
@@ -55,7 +56,7 @@ func ReadInTorrents(torrentStorage *bolt.DB) (torrentLocalArray []*TorrentLocal)
|
|||||||
}
|
}
|
||||||
TorrentStatus = b.Get([]byte("TorrentStatus"))
|
TorrentStatus = b.Get([]byte("TorrentStatus"))
|
||||||
if TorrentStatus == nil {
|
if TorrentStatus == nil {
|
||||||
fmt.Println("Torrent Status not found in local storage")
|
//fmt.Println("Torrent Status not found in local storage")
|
||||||
TorrentStatus = []byte("")
|
TorrentStatus = []byte("")
|
||||||
}
|
}
|
||||||
TorrentType = b.Get([]byte("TorrentType"))
|
TorrentType = b.Get([]byte("TorrentType"))
|
||||||
@@ -77,7 +78,7 @@ func ReadInTorrents(torrentStorage *bolt.DB) (torrentLocalArray []*TorrentLocal)
|
|||||||
torrentLocal.TorrentType = string(TorrentType)
|
torrentLocal.TorrentType = string(TorrentType)
|
||||||
torrentLocal.TorrentFileName = string(TorrentFileName)
|
torrentLocal.TorrentFileName = string(TorrentFileName)
|
||||||
|
|
||||||
fmt.Println("Torrentlocal list: ", torrentLocal)
|
//fmt.Println("Torrentlocal list: ", torrentLocal)
|
||||||
torrentLocalArray = append(torrentLocalArray, torrentLocal) //dumping it into the array
|
torrentLocalArray = append(torrentLocalArray, torrentLocal) //dumping it into the array
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -137,3 +138,63 @@ func DelTorrentLocalStorage(torrentStorage *bolt.DB, local *TorrentLocal) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FetchTorrentFromStorage grabs the localtorrent info from the bolt database for usage found my torrenthash
|
||||||
|
func FetchTorrentFromStorage(torrentStorage *bolt.DB, selectedHash []byte) TorrentLocal {
|
||||||
|
singleTorrentInfo := TorrentLocal{}
|
||||||
|
torrentStorage.View(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket(selectedHash)
|
||||||
|
var Dateadded []byte
|
||||||
|
var StoragePath []byte
|
||||||
|
var Hash []byte
|
||||||
|
var TorrentName []byte
|
||||||
|
var TorrentStatus []byte
|
||||||
|
var TorrentType []byte
|
||||||
|
var TorrentFileName []byte
|
||||||
|
Dateadded = b.Get([]byte("Date"))
|
||||||
|
if Dateadded == nil {
|
||||||
|
fmt.Println("Date added error!")
|
||||||
|
Dateadded = []byte(time.Now().Format("Jan _2 2006"))
|
||||||
|
}
|
||||||
|
StoragePath = b.Get([]byte("StoragePath"))
|
||||||
|
if StoragePath == nil {
|
||||||
|
fmt.Println("StoragePath error!")
|
||||||
|
StoragePath = []byte("downloads")
|
||||||
|
}
|
||||||
|
Hash = b.Get([]byte("InfoHash"))
|
||||||
|
if Hash == nil {
|
||||||
|
fmt.Println("Hash error!")
|
||||||
|
}
|
||||||
|
TorrentName = b.Get([]byte("TorrentName"))
|
||||||
|
if TorrentName == nil {
|
||||||
|
fmt.Println("Torrent Name not found")
|
||||||
|
TorrentName = []byte("Not Found!")
|
||||||
|
}
|
||||||
|
TorrentStatus = b.Get([]byte("TorrentStatus"))
|
||||||
|
if TorrentStatus == nil {
|
||||||
|
//fmt.Println("Torrent Status not found in local storage")
|
||||||
|
TorrentStatus = []byte("")
|
||||||
|
}
|
||||||
|
TorrentType = b.Get([]byte("TorrentType"))
|
||||||
|
if TorrentType == nil {
|
||||||
|
fmt.Println("Torrent Type not found in local storage")
|
||||||
|
TorrentStatus = []byte("")
|
||||||
|
}
|
||||||
|
TorrentFileName = b.Get([]byte("TorrentFileName"))
|
||||||
|
if TorrentFileName == nil {
|
||||||
|
fmt.Println("Torrent File Name not found in local storage")
|
||||||
|
TorrentFileName = []byte("")
|
||||||
|
}
|
||||||
|
|
||||||
|
singleTorrentInfo.DateAdded = string(Dateadded)
|
||||||
|
singleTorrentInfo.StoragePath = string(StoragePath)
|
||||||
|
singleTorrentInfo.Hash = string(Hash) //Converting the byte slice back into the full hash
|
||||||
|
singleTorrentInfo.TorrentName = string(TorrentName)
|
||||||
|
singleTorrentInfo.TorrentStatus = string(TorrentStatus)
|
||||||
|
singleTorrentInfo.TorrentType = string(TorrentType)
|
||||||
|
singleTorrentInfo.TorrentFileName = string(TorrentFileName)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return singleTorrentInfo
|
||||||
|
}
|
||||||
|
@@ -14,45 +14,58 @@ var title = document.title; //Set the number of active torrents in the title
|
|||||||
let torrents= [];
|
let torrents= [];
|
||||||
|
|
||||||
|
|
||||||
|
var torrentListRequest = {
|
||||||
|
messageType: "torrentListRequest"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined 22
|
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined 22
|
||||||
ws.onmessage = function (evt) { //When we recieve a message from the websocket
|
ws.onmessage = function (evt) { //When we recieve a message from the websocket
|
||||||
if(evt.data == "clientUpdate") {
|
var serverMessage = JSON.parse(evt.data)
|
||||||
console.log("Client Update Incoming...")
|
if (serverMessage.MessageType == "torrentList"){
|
||||||
} else { // recieving data
|
|
||||||
console.log("Recieved Client Update...")
|
console.log("Recieved Client Update...")
|
||||||
var clientUpdate = JSON.parse(evt.data);
|
//var serverMessage = JSON.parse(evt.data);
|
||||||
if (clientUpdate.total) { // if it has a total field it is a torrentlist update
|
|
||||||
torrents = []; //clearing out the torrent array to make room for new (so that it does keep adding)
|
|
||||||
for(var i = 0; i < clientUpdate.total; i++){
|
|
||||||
torrents.push({
|
|
||||||
TorrentHashString: clientUpdate.data[i].TorrentHash,
|
|
||||||
TorrentName: clientUpdate.data[i].TorrentName,
|
|
||||||
DownloadedSize: clientUpdate.data[i].DownloadedSize,
|
|
||||||
Size: clientUpdate.data[i].Size,
|
|
||||||
DownloadSpeed: clientUpdate.data[i].DownloadSpeed,
|
|
||||||
UploadSpeed: clientUpdate.data[i].UploadSpeed,
|
|
||||||
PercentDone: clientUpdate.data[i].PercentDone,
|
|
||||||
StoragePath: clientUpdate.data[i].StoragePath,
|
|
||||||
DateAdded: clientUpdate.data[i].DateAdded,
|
|
||||||
Status: clientUpdate.data[i].Status,
|
|
||||||
BytesCompleted: clientUpdate.data[i].BytesCompleted,
|
|
||||||
ActivePeers: clientUpdate.data[i].ActivePeers,
|
|
||||||
ETA: clientUpdate.data[i].ETA,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
var newTitle = '(' + clientUpdate.total + ')' + title; //updating the title
|
|
||||||
document.title = newTitle;
|
|
||||||
} else if (clientUpdate) {
|
|
||||||
|
|
||||||
|
torrents = []; //clearing out the torrent array to make room for new (so that it does keep adding)
|
||||||
|
for(var i = 0; i < serverMessage.total; i++){
|
||||||
|
torrents.push({
|
||||||
|
TorrentHashString: serverMessage.data[i].TorrentHash,
|
||||||
|
TorrentName: serverMessage.data[i].TorrentName,
|
||||||
|
DownloadedSize: serverMessage.data[i].DownloadedSize,
|
||||||
|
Size: serverMessage.data[i].Size,
|
||||||
|
DownloadSpeed: serverMessage.data[i].DownloadSpeed,
|
||||||
|
UploadSpeed: serverMessage.data[i].UploadSpeed,
|
||||||
|
PercentDone: serverMessage.data[i].PercentDone,
|
||||||
|
StoragePath: serverMessage.data[i].StoragePath,
|
||||||
|
DateAdded: serverMessage.data[i].DateAdded,
|
||||||
|
Status: serverMessage.data[i].Status,
|
||||||
|
BytesCompleted: serverMessage.data[i].BytesCompleted,
|
||||||
|
ActivePeers: serverMessage.data[i].ActivePeers,
|
||||||
|
ETA: serverMessage.data[i].ETA,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
var newTitle = '(' + serverMessage.total + ')' + title; //updating the title
|
||||||
|
document.title = newTitle;
|
||||||
|
|
||||||
|
} else if (serverMessage.MessageType == "fileList"){
|
||||||
|
console.log("Recieved FileListUpdate", serverMessage.fileList)
|
||||||
|
fileList = [];
|
||||||
|
for (var i = 0; i < serverMessage.total; i++){
|
||||||
|
fileList.push({
|
||||||
|
FileList: serverMessage.fileList[i]
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ws.onclose = function() {
|
ws.onclose = function() {
|
||||||
console.log('Closing connection')
|
console.log('Closing connection')
|
||||||
};
|
};
|
||||||
@@ -83,12 +96,8 @@ class BackendSocket extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
ws.send("clientUpdateRequest")//talking to the server to get the torrent list
|
ws.send(JSON.stringify(torrentListRequest))//talking to the server to get the torrent list
|
||||||
this.props.newTorrentList(torrents)
|
this.props.newTorrentList(torrents)
|
||||||
|
|
||||||
//console.log("STATE:", this.state.torrentList)
|
|
||||||
//console.log("Torrents", torrents);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@@ -16,6 +16,8 @@ import Icon from 'material-ui/Icon';
|
|||||||
import IconButton from 'material-ui/IconButton';
|
import IconButton from 'material-ui/IconButton';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const button = {
|
const button = {
|
||||||
fontSize: '60px',
|
fontSize: '60px',
|
||||||
paddingRight: '20px',
|
paddingRight: '20px',
|
||||||
@@ -29,6 +31,8 @@ const inlineStyle = {
|
|||||||
|
|
||||||
export default class addTorrentPopup extends React.Component {
|
export default class addTorrentPopup extends React.Component {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
open: false,
|
open: false,
|
||||||
};
|
};
|
||||||
@@ -43,9 +47,13 @@ export default class addTorrentPopup extends React.Component {
|
|||||||
|
|
||||||
handleSubmit = () => {
|
handleSubmit = () => {
|
||||||
this.setState({ open: false });
|
this.setState({ open: false });
|
||||||
let magnetLinkSubmit = this.state.textValue;
|
//let magnetLinkSubmit = this.state.textValue;
|
||||||
console.log("Sending magnet link: ", magnetLinkSubmit);
|
let magnetLinkMessage = {
|
||||||
ws.send(magnetLinkSubmit);
|
messageType: "magnetLinkSubmit",
|
||||||
|
Payload: { MagnetLink: this.state.textValue}
|
||||||
|
}
|
||||||
|
console.log("Sending magnet link: ", magnetLinkMessage);
|
||||||
|
ws.send(JSON.stringify(magnetLinkMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
setTextValue = (event) => {
|
setTextValue = (event) => {
|
||||||
|
@@ -21,7 +21,6 @@ import ReactTooltip from 'react-tooltip'
|
|||||||
|
|
||||||
import DeleteIcon from 'material-ui-icons/Delete';
|
import DeleteIcon from 'material-ui-icons/Delete';
|
||||||
import AddShoppingCartIcon from 'material-ui-icons/AddShoppingCart';
|
import AddShoppingCartIcon from 'material-ui-icons/AddShoppingCart';
|
||||||
//import PhotoCamera from 'material-ui-icons/PhotoCamera';
|
|
||||||
|
|
||||||
import BackendSocket from './BackendComm/backendWebsocket';
|
import BackendSocket from './BackendComm/backendWebsocket';
|
||||||
|
|
||||||
@@ -63,13 +62,23 @@ const styles = theme => ({
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IconButtons extends React.Component {
|
class IconButtons extends React.Component {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startTorrentState = {
|
||||||
|
messageType: "startTorrents",
|
||||||
|
Payload: this.props.selection,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
startTorrent = (selection) => {
|
||||||
|
console.log("Starting Torrents", selection)
|
||||||
|
ws.send()
|
||||||
|
}
|
||||||
|
|
||||||
buttonHandler = (buttonState) => {
|
buttonHandler = (buttonState) => {
|
||||||
console.log("BUTTONSTATE", buttonState)
|
console.log("BUTTONSTATE", buttonState)
|
||||||
}
|
}
|
||||||
@@ -128,12 +137,13 @@ IconButtons.propTypes = {
|
|||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
return {
|
return {
|
||||||
buttonState: state.buttonState,
|
buttonState: state.buttonState,
|
||||||
|
selection: state.selection,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection: selection})
|
//changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection: selection})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -95,12 +95,9 @@ class TorrentListTable extends React.Component {
|
|||||||
this.props.changeSelection(selection) //dispatch selection to redux
|
this.props.changeSelection(selection) //dispatch selection to redux
|
||||||
|
|
||||||
if (selection.length === 0) { //if selection is empty buttons will be default
|
if (selection.length === 0) { //if selection is empty buttons will be default
|
||||||
console.log("No Selection")
|
|
||||||
this.props.setButtonState(this.props.buttonStateDefault) //if no selection dispatch that to redux
|
this.props.setButtonState(this.props.buttonStateDefault) //if no selection dispatch that to redux
|
||||||
} else { // if we have selection continue on with logic to determine button state
|
} else { // if we have selection continue on with logic to determine button state
|
||||||
|
|
||||||
const selectedRows = [] //array of all the selected Rows
|
const selectedRows = [] //array of all the selected Rows
|
||||||
|
|
||||||
selection.forEach(element => {
|
selection.forEach(element => {
|
||||||
selectedRows.push(this.props.torrentList[element]) //pushing the selected rows out of torrentlist
|
selectedRows.push(this.props.torrentList[element]) //pushing the selected rows out of torrentlist
|
||||||
});
|
});
|
||||||
|