From 36416081c1a266aeebb5f564d2a8d1da07a05160 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 6 May 2026 22:26:40 +0200 Subject: [PATCH] Create torrent proto stub --- cmd/music-agregator/main.go | 8 +++- containers/docker-compose.yml | 30 ++---------- internal/torrent/server.go | 34 +++++++++++++ internal/torrent/service.go | 11 +++++ .../music_agregator/torrent/v1/torrent.proto | 48 +++++++++++++++++++ 5 files changed, 105 insertions(+), 26 deletions(-) create mode 100644 internal/torrent/server.go create mode 100644 internal/torrent/service.go create mode 100644 proto/music_agregator/torrent/v1/torrent.proto diff --git a/cmd/music-agregator/main.go b/cmd/music-agregator/main.go index 0797e57..498b150 100644 --- a/cmd/music-agregator/main.go +++ b/cmd/music-agregator/main.go @@ -25,6 +25,7 @@ import ( "homelab.lan/music-agregator/internal/config" "homelab.lan/music-agregator/internal/hello" "homelab.lan/music-agregator/internal/indexer" + "homelab.lan/music-agregator/internal/torrent" ) func main() { @@ -94,12 +95,17 @@ func serveGrpc(config config.Config) { indexerServer, err := indexer.NewIndexerServer(config) if err != nil { - log.Fatal().Err(err).Msg("Failed to create IndexerServer") + log.Fatal().Err(err).Msg("failed to create IndexerServer") + } + torrentServer, err := torrent.NewTorrentServer(config) + if err != nil { + log.Fatal().Err(err).Msg("failed to create TorrentServer") } services := []internal.Registrable{ hello.NewHelloServer(), indexerServer, + torrentServer, } for _, service := range services { diff --git a/containers/docker-compose.yml b/containers/docker-compose.yml index 8800e87..c53d2c4 100644 --- a/containers/docker-compose.yml +++ b/containers/docker-compose.yml @@ -1,23 +1,4 @@ services: - postgres: - image: postgres:16-alpine - container_name: music-aggregator-db - restart: unless-stopped - environment: - POSTGRES_USER: music - POSTGRES_PASSWORD: music - POSTGRES_DB: music_aggregator - volumes: - - postgres_data:/var/lib/postgresql/data - - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro - ports: - - "5433:5432" - healthcheck: - test: ["CMD-SHELL", "pg_isready -U music -d music_aggregator"] - interval: 10s - timeout: 5s - retries: 5 - jackett: image: lscr.io/linuxserver/jackett:latest container_name: music-aggregator-jackett @@ -52,11 +33,11 @@ services: - "6881:6881" - "6881:6881/udp" healthcheck: - test: ["CMD", "wget", "-q", "--spider", "http://localhost:8080"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 30s + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://localhost:9999"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 15s qbittorrent: image: lscr.io/linuxserver/qbittorrent:latest @@ -76,7 +57,6 @@ services: - downloads:/downloads volumes: - postgres_data: jackett_config: jackett_downloads: qbittorrent_config: diff --git a/internal/torrent/server.go b/internal/torrent/server.go new file mode 100644 index 0000000..8562abf --- /dev/null +++ b/internal/torrent/server.go @@ -0,0 +1,34 @@ +package torrent + +import ( + "context" + + "github.com/rs/zerolog/log" + "google.golang.org/grpc" + + pb "homelab.lan/music-agregator/gen/music_agregator/torrent/v1" + "homelab.lan/music-agregator/internal/config" +) + +type TorrentServer struct { + service *TorrentService + pb.UnimplementedTorrentServiceServer +} + +func NewTorrentServer(cfg config.Config) (*TorrentServer, error) { + service, err := NewIndexerService(cfg) + if err != nil { + log.Err(err).Msg("Failed to initialize IndexerService") + return nil, err + } + + return &TorrentServer{service: service}, nil +} + +func (server *TorrentServer) List(ctx context.Context, req *pb.ListRequest) (*pb.ListResponse, error) { + return nil, nil +} + +func (s *TorrentServer) Register(server *grpc.Server) { + pb.RegisterTorrentServiceServer(server, s) +} diff --git a/internal/torrent/service.go b/internal/torrent/service.go new file mode 100644 index 0000000..24400cf --- /dev/null +++ b/internal/torrent/service.go @@ -0,0 +1,11 @@ +package torrent + +import "homelab.lan/music-agregator/internal/config" + +type TorrentService struct { + config config.Config +} + +func NewIndexerService(cfg config.Config) (*TorrentService, error) { + return &TorrentService{config: cfg}, nil +} diff --git a/proto/music_agregator/torrent/v1/torrent.proto b/proto/music_agregator/torrent/v1/torrent.proto new file mode 100644 index 0000000..e1e7bbb --- /dev/null +++ b/proto/music_agregator/torrent/v1/torrent.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; +package music_agregator.torrent.v1; +option go_package = "homelab.lan/music-agregator/gen/music_agregator/v1/torrent"; + +service TorrentService { + rpc List(ListRequest) returns (ListResponse) {} +} + +message ListRequest { + string client_name = 1; + string filter = 2; + string category = 3; + string tag = 4; + string sort = 5; + bool reverse = 6; + int32 limit = 7; + int32 offset = 8; +} + +message ListResponse { + repeated Torrent torrents = 1; +} + +message Torrent { + string hash = 1; + string name = 2; + int64 size = 3; + double progress = 4; + int64 dlspeed = 5; + int64 upspeed = 6; + int32 num_seeds = 7; + int32 num_leechs = 8; + string state = 9; + int64 eta = 10; + double ratio = 11; + string category = 12; + string tags = 13; + int64 added_on = 14; + int64 completion_on = 15; + string save_path = 16; + string content_path = 17; + int64 downloaded = 18; + int64 uploaded = 19; + string tracker = 20; + int64 seeding_time = 21; + int64 amount_left = 22; + double availability = 23; +}