Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

servarr download #288

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ tasks:
cmds:
- cd webui && npm run graphql:codegen

gen-gql-client:
dir: ./internal/client
cmds:
- rover graph introspect http://localhost:3335/graphql -o schema/schema.graphql
- go run github.com/Khan/genqlient


lint:
cmds:
- task lint-golangci
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
nodePackages.prettier
protobuf
protoc-gen-go
rover

];
};
};
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22
require (
github.com/99designs/gqlgen v0.17.45
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/Khan/genqlient v0.7.0
github.com/abice/go-enum v0.6.0
github.com/adrg/xdg v0.4.0
github.com/agnivade/levenshtein v1.1.1
Expand Down Expand Up @@ -60,6 +61,8 @@ require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alexflint/go-arg v1.4.3 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/anacrolix/chansync v0.4.0 // indirect
github.com/anacrolix/generics v0.0.1 // indirect
github.com/anacrolix/log v0.15.2 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/99designs/gqlgen v0.17.45/go.mod h1:Bas0XQ+Jiu/Xm5E33jC8sES3G+iC2esHB
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/Khan/genqlient v0.7.0 h1:GZ1meyRnzcDTK48EjqB8t3bcfYvHArCUUvgOwpz1D4w=
github.com/Khan/genqlient v0.7.0/go.mod h1:HNyy3wZvuYwmW3Y7mkoQLZsa/R5n5yIRajS1kPBvSFM=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
Expand Down Expand Up @@ -39,6 +41,10 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo=
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/anacrolix/chansync v0.4.0 h1:Md0HM7zYCAO4KwNwgcIRgxNsMxiRuk7D1Ha0Uo+2y60=
github.com/anacrolix/chansync v0.4.0/go.mod h1:DZsatdsdXxD0WiwcGl0nJVwyjCKMDv+knl1q2iBjA2k=
github.com/anacrolix/dht/v2 v2.21.1 h1:s1rKkfLLcmBHKv4v/mtMkIeHIEptzEFiB6xVu54+5/o=
Expand Down
5 changes: 5 additions & 0 deletions graphql/mutations/ClientDownload.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation ClientDownload($infoHashes: [Hash20!]!) {
client {
download(infoHashes: $infoHashes)
}
}
1 change: 1 addition & 0 deletions graphql/queries/SystemQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query SystemQuery {
system {
version
download
}
}
5 changes: 5 additions & 0 deletions graphql/schema/mutation.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Mutation {
torrent: TorrentMutation!
client: ClientMutation!
}

type TorrentMutation {
Expand All @@ -8,3 +9,7 @@ type TorrentMutation {
setTags(infoHashes: [Hash20!]!, tagNames: [String!]!): Void
deleteTags(infoHashes: [Hash20!], tagNames: [String!]): Void
}

type ClientMutation {
download(infoHashes: [Hash20!]): Void
}
6 changes: 6 additions & 0 deletions graphql/schema/query.graphqls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type Query {
torrent: TorrentQuery!
torrentContent: TorrentContentQuery!
torrentContentByID: TorrentContentByID!
system: SystemQuery!
}

Expand Down Expand Up @@ -30,6 +31,11 @@ type TorrentContentQuery {
): TorrentContentSearchResult!
}

type TorrentContentByID {
id(infoHash: Hash20): TorrentContentSearchResult!
}

type SystemQuery {
version: String!
download: Boolean!
}
2 changes: 2 additions & 0 deletions internal/app/appfx/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/bitmagnet-io/bitmagnet/internal/boilerplate/app/boilerplateappfx"
"github.com/bitmagnet-io/bitmagnet/internal/boilerplate/httpserver/httpserverfx"
"github.com/bitmagnet-io/bitmagnet/internal/classifier/classifierfx"
"github.com/bitmagnet-io/bitmagnet/internal/client/clientfx"
"github.com/bitmagnet-io/bitmagnet/internal/database/databasefx"
"github.com/bitmagnet-io/bitmagnet/internal/database/migrations"
"github.com/bitmagnet-io/bitmagnet/internal/dhtcrawler/dhtcrawlerfx"
Expand Down Expand Up @@ -41,6 +42,7 @@ func New() fx.Option {
queuefx.New(),
telemetryfx.New(),
tmdbfx.New(),
clientfx.New(),
torznabfx.New(),
versionfx.New(),
classifierfx.New(),
Expand Down
33 changes: 33 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package client

import (
"context"
"net/http"

"github.com/Khan/genqlient/graphql"
"github.com/bitmagnet-io/bitmagnet/internal/protocol"
)

type AddInfoHashesRequest struct {
ClientID string
InfoHashes []protocol.ID
}

type Client interface {
AddInfoHashes(ctx context.Context, req AddInfoHashesRequest) error
}

type ServicesClient struct {
Config Config
}

func (c *ServicesClient) AddInfoHashes(ctx context.Context, req AddInfoHashesRequest) error {
_, err := ServicesDownload(
ctx,
graphql.NewClient(c.Config.ArrServiceUrl+"/graphql", http.DefaultClient),
req.InfoHashes,
ClientID(req.ClientID),
)

return err
}
14 changes: 14 additions & 0 deletions internal/client/clientfx/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package clientfx

import (
"github.com/bitmagnet-io/bitmagnet/internal/boilerplate/config/configfx"
"github.com/bitmagnet-io/bitmagnet/internal/client"
"go.uber.org/fx"
)

func New() fx.Option {
return fx.Module(
"client",
configfx.NewConfigModule[client.Config]("client", client.NewDefaultConfig()),
)
}
15 changes: 15 additions & 0 deletions internal/client/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package client

type Config struct {
ArrServiceUrl string
DownloadEnabled bool
DownloadClient string
}

func NewDefaultConfig() Config {
return Config{
ArrServiceUrl: "http://localhost:3335",
DownloadEnabled: true,
DownloadClient: "Servarr",
}
}
12 changes: 12 additions & 0 deletions internal/client/genqlient.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Default genqlient config; for full documentation see:
# https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
schema: schema/schema.graphql
operations:
- mutations/*.graphql
generated: gqlclient-gen.go

bindings:
Hash20:
type: github.com/bitmagnet-io/bitmagnet/internal/protocol.ID
Void:
type: string
81 changes: 81 additions & 0 deletions internal/client/gqlclient-gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/client/mutations/servicesdownload.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation ServicesDownload($infoHashes: [Hash20!], $clientID: ClientID) {
client {
download(infoHashes: $infoHashes, clientID: $clientID)
}
}
29 changes: 29 additions & 0 deletions internal/client/schema/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
schema {
query: Query
mutation: Mutation
}
scalar Date
scalar DateTime
scalar Hash20
scalar Void
scalar Year
type ClientMutation {
download(infoHashes: [Hash20!], clientID: ClientID): Void
}
type Mutation {
client: ClientMutation!
}
type Query {
system: SystemQuery!
}
type SystemQuery {
version: String!
download: Boolean!
}
enum ClientID {
Servarr
}
"The @defer directive may be specified on a fragment spread to imply de-prioritization, that causes the fragment to be omitted in the initial response, and delivered as a subsequent response afterward. A query with @defer directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred delivered in a subsequent response. @include and @skip take precedence over @defer."
directive @defer(if: Boolean = true, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT
"The @specifiedBy built-in directive is used within the type system definition language to provide a scalar specification URL for specifying the behavior of custom scalar types."
directive @specifiedBy(url: String!) on SCALAR
Loading