mirror of
https://github.com/zoriya/tide.git
synced 2025-12-05 22:56:12 +00:00
Remove aria2 and update docker compsoe for qbittorent
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
0
api/services/qbittorent.go
Normal file
0
api/services/qbittorent.go
Normal file
@@ -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
|
||||
@@ -1,3 +0,0 @@
|
||||
enable-rpc=true
|
||||
rpc-listen-all=true
|
||||
dir=/downloads
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user