2023-12-06 04:47:41 +00:00
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-12-16 14:19:53 +00:00
|
|
|
"errors"
|
2023-12-06 04:47:41 +00:00
|
|
|
|
|
|
|
"github.com/Khan/genqlient/graphql"
|
2023-12-16 11:59:58 +00:00
|
|
|
resolver "github.com/satisfactorymodding/ficsit-resolver"
|
2023-12-06 04:47:41 +00:00
|
|
|
|
2024-10-02 08:59:56 +00:00
|
|
|
"github.com/satisfactorymodding/ficsit-cli/cli/localregistry"
|
2023-12-06 04:47:41 +00:00
|
|
|
"github.com/satisfactorymodding/ficsit-cli/ficsit"
|
|
|
|
)
|
|
|
|
|
2023-12-16 11:59:58 +00:00
|
|
|
type FicsitProvider struct {
|
2023-12-06 04:47:41 +00:00
|
|
|
client graphql.Client
|
|
|
|
}
|
|
|
|
|
2023-12-16 11:59:58 +00:00
|
|
|
func NewFicsitProvider(client graphql.Client) FicsitProvider {
|
|
|
|
return FicsitProvider{
|
2023-12-06 04:47:41 +00:00
|
|
|
client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-16 11:59:58 +00:00
|
|
|
func (p FicsitProvider) Mods(context context.Context, filter ficsit.ModFilter) (*ficsit.ModsResponse, error) {
|
2023-12-06 04:47:41 +00:00
|
|
|
return ficsit.Mods(context, p.client, filter)
|
|
|
|
}
|
|
|
|
|
2023-12-16 11:59:58 +00:00
|
|
|
func (p FicsitProvider) GetMod(context context.Context, modReference string) (*ficsit.GetModResponse, error) {
|
2023-12-06 04:47:41 +00:00
|
|
|
return ficsit.GetMod(context, p.client, modReference)
|
|
|
|
}
|
|
|
|
|
2023-12-16 11:59:58 +00:00
|
|
|
func (p FicsitProvider) ModVersionsWithDependencies(_ context.Context, modID string) ([]resolver.ModVersion, error) {
|
|
|
|
response, err := ficsit.GetAllModVersions(modID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if response.Error != nil {
|
|
|
|
return nil, errors.New(response.Error.Message)
|
|
|
|
}
|
|
|
|
|
2024-10-04 17:23:51 +00:00
|
|
|
localregistry.Add(modID, response.Data)
|
2023-12-16 11:59:58 +00:00
|
|
|
|
2024-10-04 17:23:51 +00:00
|
|
|
return convertFicsitVersionsToResolver(response.Data), nil
|
2023-12-06 04:47:41 +00:00
|
|
|
}
|
|
|
|
|
2023-12-16 11:59:58 +00:00
|
|
|
func (p FicsitProvider) GetModName(context context.Context, modReference string) (*resolver.ModName, error) {
|
|
|
|
response, err := ficsit.GetModName(context, p.client, modReference)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &resolver.ModName{
|
|
|
|
ID: response.Mod.Id,
|
|
|
|
ModReference: response.Mod.Mod_reference,
|
|
|
|
Name: response.Mod.Name,
|
|
|
|
}, nil
|
2023-12-06 04:47:41 +00:00
|
|
|
}
|
|
|
|
|
2023-12-16 11:59:58 +00:00
|
|
|
func (p FicsitProvider) IsOffline() bool {
|
|
|
|
return false
|
2023-12-06 04:47:41 +00:00
|
|
|
}
|