mirror of
https://github.com/zoriya/tide.git
synced 2026-06-04 11:16:07 +00:00
Create a dockerfile for aria2
This commit is contained in:
+5
-1
@@ -35,10 +35,14 @@ func main() {
|
||||
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if newItem.Uri == "" {
|
||||
http.Error(w, "Uri is a required field", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
item, err := controller.NewItem(newItem)
|
||||
if err != nil {
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(item)
|
||||
|
||||
@@ -5,6 +5,7 @@ import "time"
|
||||
type State string
|
||||
|
||||
const (
|
||||
Unknown State = "unknown"
|
||||
Stale State = "stale"
|
||||
Downloading State = "downloading"
|
||||
Seeding State = "seeding"
|
||||
@@ -41,6 +42,7 @@ type Item struct {
|
||||
State State `json:"state"`
|
||||
Size uint64 `json:"size"`
|
||||
AvailableSize uint64 `json:"availableSize"`
|
||||
Percent uint `json:"percent"`
|
||||
UploadedSize uint64 `json:"uploadedSize"`
|
||||
// Hexadecimal representation of the download progress.
|
||||
// The highest bit corresponds to the piece at index 0. Any set bits indicate loaded pieces,
|
||||
|
||||
+69
-5
@@ -2,7 +2,10 @@ package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
models "tide/api/models"
|
||||
|
||||
"github.com/siku2/arigo"
|
||||
@@ -15,7 +18,7 @@ type Service interface {
|
||||
|
||||
type Aria2 struct {
|
||||
client *arigo.Client
|
||||
token string
|
||||
token string
|
||||
}
|
||||
|
||||
func NewAria2() (*Aria2, error) {
|
||||
@@ -29,15 +32,76 @@ func NewAria2() (*Aria2, error) {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func toState(status arigo.DownloadStatus, percent uint) models.State {
|
||||
switch status {
|
||||
case arigo.StatusActive:
|
||||
if percent == 100 {
|
||||
return models.Seeding
|
||||
}
|
||||
return models.Downloading
|
||||
case arigo.StatusWaiting:
|
||||
return models.Stale
|
||||
case arigo.StatusPaused:
|
||||
return models.Paused
|
||||
case arigo.StatusError:
|
||||
return models.Errored
|
||||
case arigo.StatusCompleted:
|
||||
return models.Finished
|
||||
case arigo.StatusRemoved:
|
||||
fallthrough
|
||||
default:
|
||||
return models.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Aria2) AddItem(uri string) (*models.Item, error) {
|
||||
id, err := x.client.AddURI([]string{uri}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
item := new(models.Item)
|
||||
item.Id = id.GID
|
||||
// TODO: Download other datas
|
||||
return item, nil
|
||||
status, err := id.TellStatus()
|
||||
if err != nil {
|
||||
log.Println("Tell status error")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
percent := status.CompletedLength / status.TotalLength
|
||||
files := make([]models.File, 0, len(status.Files))
|
||||
for _, file := range status.Files {
|
||||
priority := models.Medium
|
||||
if !file.Selected {
|
||||
priority = models.None
|
||||
}
|
||||
|
||||
files = append(files, models.File{
|
||||
Index: uint(file.Index),
|
||||
Name: "???",
|
||||
Path: "???",
|
||||
Priority: priority,
|
||||
Size: uint64(file.Length),
|
||||
AvailableSize: uint64(file.CompletedLength),
|
||||
})
|
||||
}
|
||||
return &models.Item{
|
||||
Id: id.GID,
|
||||
|
||||
Name: "??",
|
||||
Path: "??",
|
||||
AddedDate: time.Now(),
|
||||
Files: files,
|
||||
|
||||
State: toState(status.Status, percent),
|
||||
Size: uint64(status.TotalLength),
|
||||
AvailableSize: uint64(status.CompletedLength),
|
||||
Percent: percent,
|
||||
UploadedSize: uint64(status.UploadLength),
|
||||
BitField: status.BitField,
|
||||
DownloadSpeed: status.DownloadSpeed,
|
||||
UploadSpeed: status.UploadSpeed,
|
||||
SeedCount: status.NumSeeders,
|
||||
Connections: status.Connections,
|
||||
ErrorMessage: &status.ErrorMessage,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (x *Aria2) List() []models.Item {
|
||||
|
||||
Reference in New Issue
Block a user