40 lines
989 B
Go
40 lines
989 B
Go
package torrent
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
"google.golang.org/grpc"
|
|
|
|
pb "homelab.lan/music-agregator/gen/music_agregator/torrent/v1"
|
|
)
|
|
|
|
type TorrentServer struct {
|
|
service *TorrentService
|
|
pb.UnimplementedTorrentServiceServer
|
|
}
|
|
|
|
func NewTorrentServer(client TorrentClient) *TorrentServer {
|
|
return &TorrentServer{service: NewTorrentService(client)}
|
|
}
|
|
|
|
func (server *TorrentServer) List(ctx context.Context, req *pb.ListRequest) (*pb.ListResponse, error) {
|
|
return server.service.List(req)
|
|
}
|
|
|
|
func (server *TorrentServer) Add(ctx context.Context, req *pb.AddRequest) (*pb.AddResponse, error) {
|
|
log.Debug().Str("download_url", req.GetDownloadUrl()).Str("filename", req.GetFilename()).Msg("add torrent requested")
|
|
|
|
resp, err := server.service.Add(req)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("add torrent failed")
|
|
return nil, err
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
func (s *TorrentServer) Register(server *grpc.Server) {
|
|
pb.RegisterTorrentServiceServer(server, s)
|
|
}
|