Documentation
¶
Index ¶
- Constants
- func CacheDBPath(cacheDir string) string
- func InitCacheDB(ctx context.Context, db *sql.DB) error
- func Login(ctx context.Context, w io.Writer) (string, error)
- func SaveRateLimitState(dir string, state *RateLimitState) error
- type CacheReader
- func (r *CacheReader) Close() error
- func (r *CacheReader) GetNexusFileInfo(gameDomain string, modID int64, fileID int64) (*dbc.GetNexusFileInfoRow, error)
- func (r *CacheReader) GetNexusFileInfoFetchedAt(gameDomain string, modID int64) (string, error)
- func (r *CacheReader) GetNexusFileUpdateChain(gameDomain string, modID int64) ([]dbc.GetNexusFileUpdateChainRow, error)
- func (r *CacheReader) GetNexusModInfo(gameDomain string, modID int64) (*dbc.NexusModInfo, error)
- func (r *CacheReader) GetUpdateChain(gameDomain string, modID int64) (updatechain.Chain, error)
- type Client
- func (c *Client) GetMod(gameDomain string, modID int64) (*ModInfo, error)
- func (c *Client) GetModCached(gameDomain string, modID int64) (*ModInfo, error)
- func (c *Client) GetModFiles(gameDomain string, modID int64) (*ModFilesResponse, error)
- func (c *Client) GetModFilesCached(gameDomain string, modID int64) (*ModFilesResponse, error)
- func (c *Client) RateLimitState() (*RateLimitState, error)
- func (c *Client) ValidateUser() (*UserInfo, error)
- type FileUpdateInfo
- type ModFileInfo
- type ModFilesResponse
- type ModInfo
- type RateLimitState
- type UserInfo
Constants ¶
const ( ModInfoTTL = 7 * 24 * time.Hour ModFilesTTL = 24 * time.Hour )
const ( AppSlug = "modctl-modctl" DefaultSSOTimeout = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func CacheDBPath ¶ added in v0.9.0
CacheDBPath is the file of the cache, in the cache directory cacheDir.
func InitCacheDB ¶ added in v0.7.0
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
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(dir string, state *RateLimitState) error
SaveRateLimitState writes the rate limits to the state directory dir, which is made if it is not there.
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, cacheDir string) (*CacheReader, error)
NewCacheReader opens the cache of what the API said, in the directory cacheDir (which has to be there).
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)
func (*CacheReader) GetUpdateChain ¶ added in v0.8.0
func (r *CacheReader) GetUpdateChain(gameDomain string, modID int64) (updatechain.Chain, error)
GetUpdateChain returns the file update chain that is cached for a mod. A mod that has nothing cached has an empty chain, in which every file is the latest.
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, cacheDir string, stateDir string) (*Client, error)
New makes a client for the API, with the cache of what it said in the directory cacheDir (which has to be there), and the rate limits that it said in the state directory stateDir.
func (*Client) GetModCached ¶
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
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 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(dir string) (*RateLimitState, error)
LoadRateLimitState reads the rate limits from the state directory dir. There are none until a response of the API has said what they are, which is a state with nothing in it and not an error, and nothing is made by looking: not the directory, and not the file. A file that is not what it should be is no state either.
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.