From 32cb194cfc844277c03ba29b6b4fd7948e498ebe Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 20 Sep 2023 16:20:24 +0200 Subject: [PATCH] Remove aria2 and update docker compsoe for qbittorent --- .env.example | 7 +-- api/controllers/rest.go | 8 +-- api/main.go | 4 +- api/services/aria2.go | 109 ------------------------------------- api/services/qbittorent.go | 0 aria2/Dockerfile | 26 --------- aria2/aria2.conf | 3 - docker-compose.dev.yml | 13 +++-- shell.nix | 1 - 9 files changed, 17 insertions(+), 154 deletions(-) delete mode 100644 api/services/aria2.go create mode 100644 api/services/qbittorent.go delete mode 100644 aria2/Dockerfile delete mode 100644 aria2/aria2.conf diff --git a/.env.example b/.env.example index 3ce1ef5..2181e17 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,8 @@ DOWNLOAD_DIR=./downloads -ARIA2_DIR=./.aria2 -# IMPORTANT: Change that to actually secure your aria2 connection -RPC_SECRET=wertyui -ARIA_URI=aria2c:6800 +PUID=0 +PGUID=0 + # Database things POSTGRES_USER=tideUser POSTGRES_PASSWORD=tidePassword diff --git a/api/controllers/rest.go b/api/controllers/rest.go index 33dda54..0634783 100644 --- a/api/controllers/rest.go +++ b/api/controllers/rest.go @@ -7,18 +7,18 @@ import ( type Controller struct { Database *services.Database - Aria2 *services.Aria2 + Qbittorent *services.Qbittorent } -func NewController(db *services.Database, aria2 *services.Aria2) *Controller { +func NewController(db *services.Database, aria2 *services.Qbittorent) *Controller { c := new(Controller) c.Database = db - c.Aria2 = aria2 + c.Qbittorent = aria2 return c } func (c *Controller) NewItem(newItem models.NewItem) (*models.Item, error) { - item, err := c.Aria2.AddItem(newItem.Uri) + item, err := c.Qbittorent.AddItem(newItem.Uri) if err != nil { return nil, err } diff --git a/api/main.go b/api/main.go index 931af72..7f8eced 100644 --- a/api/main.go +++ b/api/main.go @@ -20,11 +20,11 @@ func main() { log.Fatal("Could not migrate database: ", err) } - aria2, err := services.NewAria2() + qbittorent, err := services.NewQbittorent() if err != nil { log.Fatal("Could not connect to aria2", err) } - controller := controllers.NewController(db, aria2) + controller := controllers.NewController(db, qbittorent) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { switch r.Method { diff --git a/api/services/aria2.go b/api/services/aria2.go deleted file mode 100644 index 8ec7fa1..0000000 --- a/api/services/aria2.go +++ /dev/null @@ -1,109 +0,0 @@ -package services - -import ( - "fmt" - "log" - "os" - "time" - - models "tide/api/models" - - "github.com/siku2/arigo" -) - -type Service interface { - AddItem(item string) - List() []models.Item -} - -type Aria2 struct { - client *arigo.Client - token string -} - -func NewAria2() (*Aria2, error) { - p := new(Aria2) - p.token = os.Getenv("RPC_SECRET") - c, err := arigo.Dial(fmt.Sprintf("ws://%v/jsonrpc", os.Getenv("ARIA_URI")), p.token) - if err != nil { - return nil, err - } - p.client = &c - 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 - } - 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 { - return make([]models.Item, 0) -} diff --git a/api/services/qbittorent.go b/api/services/qbittorent.go new file mode 100644 index 0000000..e69de29 diff --git a/aria2/Dockerfile b/aria2/Dockerfile deleted file mode 100644 index 150fef2..0000000 --- a/aria2/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM alpine - -RUN apk add --no-cache --update aria2 -WORKDIR /private - - -ENV LISTEN_PORT=6888 \ - RPC_PORT=6800 \ - RPC_SECRET= \ - DISABLE_IPV6=true \ - ENABLE_DHT6=false - -COPY ./aria2.conf ./aria2.conf -EXPOSE 6888 -EXPOSE 6888/udp -CMD touch /aria2/aria2.session && \ - aria2c --conf-path ./aria2.conf \ - --dht-file-path=/dht/dht.data \ - --dht-file-path6=/dht/dht6.data \ - --save-session=/aria2/aria2.session \ - --input-file=/aria2/aria2.session \ - # --rpc-secret=$RPC_SECRET \ - --rpc-listen-port=$RPC_PORT \ - --listen-port=$LISTEN_PORT \ - --disable-ipv6=$DISABLE_IPV6 \ - --enable-dht6=$ENABLE_DHT6 diff --git a/aria2/aria2.conf b/aria2/aria2.conf deleted file mode 100644 index caa7101..0000000 --- a/aria2/aria2.conf +++ /dev/null @@ -1,3 +0,0 @@ -enable-rpc=true -rpc-listen-all=true -dir=/downloads diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 8b1a383..26ed799 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -13,15 +13,18 @@ services: env_file: - .env - aria2: - build: ./aria2 + qbittorent: + image: qbittorrentofficial/qbittorrent-nox ports: - - "6888:6888" - - "6888:6888/udp" + - "6881:6881/tcp" + - "6881:6881/udp" restart: on-failure volumes: - $DOWNLOAD_DIR:/downloads - - $ARIA2_DIR:/aria2 + environment: + - QBT_EULA=accept + - QBT_WEBUI_PORT=8080 + - QBT_DOWNLOADS_PATH=/downloads env_file: - .env diff --git a/shell.nix b/shell.nix index 81e106a..17b229a 100644 --- a/shell.nix +++ b/shell.nix @@ -3,7 +3,6 @@ pkgs.mkShell { packages = with pkgs; [ go wgo - aria go-migrate pgformatter ];