diff --git a/client.go b/client.go new file mode 100644 index 00000000..fb0f5c7a --- /dev/null +++ b/client.go @@ -0,0 +1,89 @@ +package main + +import ( + "fmt" + "github.com/anacrolix/torrent" + "log" + "os" + "path/filepath" + "time" +) + +// ClientError formats errors coming from the client. +type ClientError struct { + Type string + Origin error +} + +func (clientError ClientError) Error() string { + return fmt.Sprintf("Error %s: %s\n", clientError.Type, clientError.Origin) +} + +type ClientConfig struct { + TorrentPath string + Port int + TorrentPort int + Seed bool + TCP bool + MaxConnections int + DownloadDir string +} + +// NewClientConfig creates a new default configuration. +func NewClientConfig() ClientConfig { + return ClientConfig{ + Port: 8080, + TorrentPort: 50007, + Seed: false, + TCP: true, + MaxConnections: 200, + DownloadDir: "Download", + } +} + +type Client struct { + Client *torrent.Client + Torrent *torrent.Torrent + Name string + Progress int64 + Status string + Seeds int + Peers int + DownloadSpeed int64 + UploadSpeed int64 + ETA time.Duration + Ratio int + Avail int + Config ClientConfig +} + +func NewClient(cfg ClientConfig) (client Client, err error) { + + var t *torrent.Torrent + var c *torrent.Client + + client.Config = cfg + + //create the download directory + _, err := os.Create(cfg.DownloadDir) + if err != nil { + log.Println(err) + return + } + + c, err = torrent.NewClient(&torrent.Config{ + DataDir: cfg.DownloadDir, + NoUpload: !cfg.Seed, + Seed: cfg.Seed, + DisableTCP: !cfg.TCP, + ListenAddr: fmt.Sprintf("%d", cfg.TorrentPort), + }) + if err != nil { + return client, ClientError{Type: "creating torrent client", Origin: err} + } + + client.Client = c + + //adding torrents + +} diff --git a/main.go b/main.go index 5cec422c..6bbfda57 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "net/http" "os" + "strings" "time" ) @@ -57,6 +58,8 @@ func main() { fmt.Println(err) return } + } else if strings.HasPrefix(string(msg), "magnet:") { + fmt.Println(string(msg)) } else { conn.Close() fmt.Println(string(msg)) diff --git a/public/static/css/gridbase.css b/public/static/css/gridbase.css index a53b771c..5cef01dd 100644 --- a/public/static/css/gridbase.css +++ b/public/static/css/gridbase.css @@ -117,4 +117,58 @@ tr:nth-child(even) { .defaultTab { display: initial; +} + + +.addTorrentModal { + display: none; /* Hidden by default */ + position: fixed; /* Stay in place */ + z-index: 1; /* Sit on top */ + padding-top: 100px; /* Location of the box */ + left: 0; + top: 0; + width: 100%; /* Full width */ + height: 100%; /* Full height */ + overflow: auto; /* Enable scroll if needed */ + background-color: rgb(0,0,0); /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ +} + +/* Modal Content */ +.addTorrentModalContent { + background-color: #fefefe; + margin: auto; + padding: 20px; + border: 1px solid #888; + width: 80%; +} + +/* The Close Button */ +.addTorrentModalClose { + color: #aaaaaa; + float: right; + font-size: 28px; + font-weight: bold; +} + +.addTorrentModalClose:hover, +.addTorrentModalClose:focus { + color: #000; + text-decoration: none; + cursor: pointer; +} + +.addTorrentFileModalClose { + color: #aaaaaa; + float: right; + font-size: 28px; + font-weight: bold; +} + + +.addTorrentFileModalClose:hover, +.addTorrentFileModalClose:focus { + color: #000; + text-decoration: none; + cursor: pointer; } \ No newline at end of file diff --git a/templates/home.tmpl b/templates/home.tmpl index 6d12bb44..64286b90 100644 --- a/templates/home.tmpl +++ b/templates/home.tmpl @@ -18,11 +18,19 @@ document.getElementById(tabName).style.display = "block"; evt.currentTarget.className += " activeButton"; } + + + +
+ + +
+ × +
+ Input Magnet Link: + +
+
+ +
+ +
+ + +
+ × + Input Torrent File: + +
+ +
-
+ +