nexusclient

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModInfoTTL  = 7 * 24 * time.Hour
	ModFilesTTL = 24 * time.Hour
)
View Source
const (
	AppSlug           = "modctl-modctl"
	DefaultSSOTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

func InitCacheDB added in v0.7.0

func InitCacheDB(ctx context.Context, db *sql.DB) error

InitCacheDB initializes or resets the nexus cache database schema. It is exported for use by the exporter when constructing scoped cache databases for export bundles.

func Login added in v0.3.0

func Login(ctx context.Context, w io.Writer) (string, error)

Login runs the Nexus Mods SSO flow and returns the API key. Progress messages are written to w. The caller should wrap ctx with a timeout before calling (DefaultSSOTimeout is the recommended value)

func SaveRateLimitState

func SaveRateLimitState(state *RateLimitState) error

Types

type CacheReader

type CacheReader struct {
	// contains filtered or unexported fields
}

CacheReader provides read-only access to the Nexus cache DB. Use this when you need cache data but don't need to make API calls.

func NewCacheReader

func NewCacheReader(ctx context.Context, logger *slog.Logger) (*CacheReader, error)

func (*CacheReader) Close

func (r *CacheReader) Close() error

func (*CacheReader) GetNexusFileInfo

func (r *CacheReader) GetNexusFileInfo(gameDomain string, modID int64, fileID int64) (*dbc.GetNexusFileInfoRow, error)

func (*CacheReader) GetNexusFileInfoFetchedAt

func (r *CacheReader) GetNexusFileInfoFetchedAt(gameDomain string, modID int64) (string, error)

func (*CacheReader) GetNexusFileUpdateChain

func (r *CacheReader) GetNexusFileUpdateChain(gameDomain string, modID int64) ([]dbc.GetNexusFileUpdateChainRow, error)

func (*CacheReader) GetNexusModInfo

func (r *CacheReader) GetNexusModInfo(gameDomain string, modID int64) (*dbc.NexusModInfo, error)

type Client

type Client struct {
	CacheReader
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, apiKey string, logger *slog.Logger, version string) (*Client, error)

func (*Client) GetMod

func (c *Client) GetMod(gameDomain string, modID int64) (*ModInfo, error)

func (*Client) GetModCached

func (c *Client) GetModCached(gameDomain string, modID int64) (*ModInfo, error)

func (*Client) GetModFiles

func (c *Client) GetModFiles(gameDomain string, modID int64) (*ModFilesResponse, error)

func (*Client) GetModFilesCached

func (c *Client) GetModFilesCached(gameDomain string, modID int64) (*ModFilesResponse, error)

func (*Client) RateLimitState

func (c *Client) RateLimitState() (*RateLimitState, error)

func (*Client) ValidateUser added in v0.3.0

func (c *Client) ValidateUser() (*UserInfo, error)

ValidateUser calls /v1/users/validate.json to confirm the configured API key is valid and returns basic user info. Rate limit headers from this response are persisted as a side effect via doRequest. This endpoint does not count against the Nexus rate limit quota.

type FileUpdateInfo

type FileUpdateInfo struct {
	OldFileID         int64  `json:"old_file_id"`
	NewFileID         int64  `json:"new_file_id"`
	OldFileName       string `json:"old_file_name"`
	NewFileName       string `json:"new_file_name"`
	UploadedTimestamp int64  `json:"uploaded_timestamp"`
}

type ModFileInfo

type ModFileInfo struct {
	FileID            int64  `json:"file_id"`
	Name              string `json:"name"`
	Version           string `json:"version"`
	CategoryName      string `json:"category_name"`
	IsPrimary         bool   `json:"is_primary"`
	FileName          string `json:"file_name"`
	SizeInBytes       int64  `json:"size_in_bytes"`
	UploadedTimestamp int64  `json:"uploaded_timestamp"`
}

type ModFilesResponse

type ModFilesResponse struct {
	Files       []ModFileInfo    `json:"files"`
	FileUpdates []FileUpdateInfo `json:"file_updates"`
	RawJSON     []byte           `json:"-"`
}

ModFilesResponse represents the fields we care about from /v1/games/{domain}/mods/{id}/files.json

type ModInfo

type ModInfo struct {
	ModID       int64  `json:"mod_id"`
	Name        string `json:"name"`
	Summary     string `json:"summary"`
	Author      string `json:"author"`
	DomainName  string `json:"domain_name"`
	Version     string `json:"version"`
	IsAvailable bool   `json:"available"`
	RawJSON     []byte `json:"-"`
}

ModInfo represents the fields we care about from /v1/games/{domain}/mods/{id}.json

type RateLimitState

type RateLimitState struct {
	HourlyLimit     int       `json:"hourly_limit"`
	HourlyRemaining int       `json:"hourly_remaining"`
	HourlyReset     time.Time `json:"hourly_reset"`
	DailyLimit      int       `json:"daily_limit"`
	DailyRemaining  int       `json:"daily_remaining"`
	DailyReset      time.Time `json:"daily_reset"`
}

func LoadRateLimitState

func LoadRateLimitState() (*RateLimitState, error)

func (*RateLimitState) EffectiveRemaining

func (r *RateLimitState) EffectiveRemaining() (hourly, daily int)

EffectiveRemaining returns the remaining counts, treating expired windows as fully refreshed

type UserInfo added in v0.3.0

type UserInfo struct {
	UserID int64  `json:"user_id"`
	Name   string `json:"name"`
	// IsPremium and IsSupporter are present in two forms in the API response
	// ("is_premium?" and "is_premium"). We decode both and prefer the
	// non-punctuated form.
	IsPremium   bool `json:"is_premium"`
	IsSupporter bool `json:"is_supporter"`

	// Punctuated variants (decoded but not used directly)
	IsPremiumAlt   bool `json:"is_premium?"`
	IsSupporterAlt bool `json:"is_supporter?"`
}

UserInfo contains the fields from /v1/users/validate.json that we surface. The validate endpoint does not count against the Nexus rate limit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL