config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDownloadPath     = "./downloads"
	DefaultFilenameTemplate = "{author} - {title}_{id}"
)
View Source
const DefaultConfigFileMode = constants.PrivateFileMode

Variables

This section is empty.

Functions

func ConfigFilePath

func ConfigFilePath() (string, error)

func EnsureDefaultConfigFile added in v0.7.1

func EnsureDefaultConfigFile() error

EnsureDefaultConfigFile 在配置首次缺失时生成只含常用选项的基线文件。高级设置 (代理、日志、登录超时与 Premium 缓存等)必须由用户显式写入,已有文件绝不覆盖。

func EnvValue

func EnvValue(spec SettingSpec) (string, bool)

func IsSensitiveSetting added in v0.8.0

func IsSensitiveSetting(alias string) bool

IsSensitiveSetting 标记禁止通过公开配置查询回显的凭据型值。

func NewLogger added in v0.2.0

func NewLogger(writer io.Writer, cfg RuntimeConfig) (*slog.Logger, error)

NewLogger 按已解析的运行时配置创建本进程根 logger。调用方决定输出流,CLI/MCP 一律传 stderr;本函数绝不设置或读取 slog 默认全局 logger。

func PublicSettingText added in v0.8.0

func PublicSettingText(alias, text string) string

PublicSettingText 返回可安全进入 CLI、SDK JSON 与日志边界的配置值。

func RefreshTokenFromEnv

func RefreshTokenFromEnv() (string, error)

RefreshTokenFromEnv 读取 App API refresh token。Cookie 形态在此处即被拒绝, 不能继续流入默认 SDK 的 OAuth 请求。

func SetConfigValue

func SetConfigValue(path, alias string, value parser.Value) error

func SetFilePathForTest

func SetFilePathForTest(configPath string) func()

func UnsetConfigValue

func UnsetConfigValue(path, alias string) (bool, error)

func ValidSettingAliases

func ValidSettingAliases() []string

func WritePrivateFile

func WritePrivateFile(path string, body []byte) error

Types

type AccountPoolConfig added in v0.8.0

type AccountPoolConfig struct {
	Enabled  bool
	Accounts []int64
	Strategy AccountPoolStrategy
}

AccountPoolConfig 描述内容读取和作品下载可使用的本地受管账号白名单。 账号 token 仍只存在 auth.json,配置与状态文件均不保存凭据。

type AccountPoolStrategy added in v0.8.0

type AccountPoolStrategy string
const (
	AccountPoolStrategyRoundRobin AccountPoolStrategy = "round_robin"
	AccountPoolStrategyRandom     AccountPoolStrategy = "random"
)

type RuntimeConfig

type RuntimeConfig struct {
	DownloadPath       string
	FilenameTemplate   string
	HTTPSProxy         string
	WebFallbackEnabled bool
	UpdateCheckEnabled bool
	OutputJSON         bool
	LoginOpenBrowser   bool
	LoginUseAfterLogin bool
	// LoginRelay* 描述跨机器浏览器回调中继。secret 只用于 handler 与 server
	// 间的 bearer 认证,不能作为普通配置输出的一部分。
	LoginRelayPublicURL   string
	LoginRelayListenAddr  string
	LoginRelaySecret      string
	LoginRelayTargetURL   string
	LoginRelayTLSCertFile string
	LoginRelayTLSKeyFile  string
	// LogLevel 只描述应用根 logger,不会改变 slog 默认全局 logger。
	LogLevel string
	// AccountPool 只能在 config.toml 的 [account_pool] 表中手工维护,避免普通
	// config set 的扁平字符串接口误写账号白名单。
	AccountPool AccountPoolConfig
}

type SettingSpec

type SettingSpec struct {
	Alias    string
	KoanfKey string
	Table    []string
	Key      string
	Kind     settingKind
	// Sensitive 表示该值可用于认证或中继授权。它可以被写入私有 config.toml,
	// 但绝不能通过 config get、日志或错误消息回显。
	Sensitive  bool
	HasDefault bool
	Default    any
}

func SettingSpecByAlias

func SettingSpecByAlias(alias string) (SettingSpec, bool)

type SettingValue

type SettingValue struct {
	Value    any
	Text     string
	Source   string
	HasValue bool
}

func ParseSettingInput

func ParseSettingInput(alias, raw string) (SettingValue, parser.Value, error)

type SettingsState

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

func LoadSettingsState

func LoadSettingsState() (SettingsState, error)

func LoadSettingsStateAt added in v0.2.0

func LoadSettingsStateAt(path string) (SettingsState, error)

LoadSettingsStateAt 从明确给定的路径加载配置。SDK 需要它避免改动 包级测试路径或依赖调用进程的隐式当前配置位置。

func (SettingsState) Effective

func (s SettingsState) Effective(alias string) (SettingValue, error)

func (SettingsState) Runtime

func (s SettingsState) Runtime() (RuntimeConfig, error)

Jump to

Keyboard shortcuts

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