config

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HomeDirectory    = "HomeDirectory"
	WorkingDirectory = "WorkingDirectory"
	ProgramDirectory = "ProgramDirectory"
)

Variables

View Source
var (
	Server *http.Server
	Mutex  sync.Mutex
)
View Source
var CfgStatus = Status{}
View Source
var GlobalLibraryScanner *scheduler.LibraryScanner

GlobalLibraryScanner 全局的定时扫描调度器实例

Functions

func AutoSetCacheDir added in v1.1.0

func AutoSetCacheDir()

func DefaultConfigLocation added in v1.0.0

func DefaultConfigLocation() string

DefaultConfigLocation 判断当前配置文件应该保存到哪里。 逻辑:

  1. 是否在HomeDirectory已有 config.toml
  2. 否则是否在WorkingDirectory已有 config.toml
  3. 否则是否在ProgramDirectory已有 config.toml 若都没有,则返回 "HomeDirectory"。

返回:location字符串

func DeleteConfigIn

func DeleteConfigIn(in string) error

func GetConfigDir added in v1.1.0

func GetConfigDir() (dir string, err error)

GetConfigDir 获取配置文件所在目录

func GetHomeDirectoryConfig added in v1.0.0

func GetHomeDirectoryConfig() string

func GetJwtSigningKey added in v1.0.0

func GetJwtSigningKey() string

GetJwtSigningKey JWT令牌签名key,目前是用户名+密码(如果两者都设置了的话)

func GetProgramDirectoryConfig added in v1.0.0

func GetProgramDirectoryConfig() string

func GetQrcodeURL

func GetQrcodeURL() string

func GetVersion added in v1.0.0

func GetVersion() string

func GetWorkingDirectoryConfig added in v1.0.0

func GetWorkingDirectoryConfig() string

func InitLibraryScanner added in v1.1.8

func InitLibraryScanner()

InitLibraryScanner 初始化全局调度器

func OpenBrowserIfNeeded added in v1.1.6

func OpenBrowserIfNeeded()

func SaveConfig

func SaveConfig(to string) error

func ScanUserPlugins added in v1.2.4

func ScanUserPlugins() error

ScanUserPlugins 扫描并加载用户自定义插件

func SetPort added in v1.0.0

func SetPort(port int)

func SetScanTaskFunc added in v1.1.8

func SetScanTaskFunc(fn func() error)

SetScanTaskFunc 设置扫描任务函数(由外部包调用,避免循环导入)

func StartOrStopAutoRescan added in v1.1.8

func StartOrStopAutoRescan()

StartOrStopAutoRescan 根据配置启动或停止自动扫描

func UpdateConfigByJson added in v1.0.0

func UpdateConfigByJson(jsonString string) error

UpdateConfigByJson 使用 JSON 字符串反序列化将更新的配置解析为映射,遍历映射并更新配置,减少重复的代码。

func UpdateConfigFile added in v1.1.0

func UpdateConfigFile() error

UpdateConfigFile 如果存在本地配置,更新本地配置

Types

type Config

type Config struct {
	AutoRescanIntervalMinutes int            `` /* 135-byte string literal not displayed */
	CacheDir                  string         `json:"CacheDir" comment:"本地图片缓存位置,默认系统临时文件夹"`
	ClearCacheExit            bool           `json:"ClearCacheExit" comment:"退出程序的时候,清理web图片缓存"`
	ClearDatabaseWhenExit     bool           `json:"ClearDatabaseWhenExit" comment:"启用本地数据库时,扫描完成后,清除不存在的书籍。"`
	ConfigFile                string         `json:"-" toml:"-" comment:"用户指定的的yaml设置文件路径"`
	ReadOnlyMode              bool           `json:"ReadOnlyMode" comment:"只读模式。禁止网页端更改配置或上传文件。"`
	Debug                     bool           `json:"Debug" comment:"开启Debug模式"`
	EnablePlugin              bool           `json:"EnablePlugin" comment:"启用插件系统"`
	PluginDirectory           string         `json:"-" toml:"-"  comment:"插件存放目录"`
	BuildInPluginList         []string       `json:"-" toml:"-"  comment:"内置插件列表"`
	UserPluginList            []string       `json:"-" toml:"-"  comment:"用户自定义插件列表"`
	EnabledPluginList         []string       `json:"-" toml:"-"  comment:"已启用插件列表"`
	CustomPlugins             []CustomPlugin `json:"-" toml:"-"  comment:"用户自定义插件内容列表"`
	DisableLAN                bool           `json:"DisableLAN" comment:"只在本机提供阅读服务,不对外共享"`
	EnableDatabase            bool           `json:"EnableDatabase" comment:"启用本地数据库,保存扫描到的书籍数据。"`
	EnableTLS                 bool           `json:"EnableTLS" comment:"是否启用HTTPS协议。需要设置证书于key文件。"`
	AutoTLSCertificate        bool           `json:"AutoTLSCertificate" comment:"自动申请、签发 HTTPS 证书(Let's Encrypt)"`
	Host                      string         `` /* 191-byte string literal not displayed */
	KeyFile                   string         `json:"KeyFile" comment:"TLS/SSL key文件路径 (default: ~/.config/.comigo/key.key)"`
	CertFile                  string         `json:"CertFile" comment:"TLS/SSL 证书文件路径 (default: ~/.config/.comigo/cert.crt)"`
	EnableUpload              bool           `json:"EnableUpload" comment:"启用上传功能"`
	ExcludePath               []string       `json:"ExcludePath" comment:"扫描书籍的时候,需要排除的文件或文件夹的名字"`
	GenerateMetaData          bool           `json:"GenerateMetaData" toml:"GenerateMetaData" comment:"生成书籍元数据"`
	StoreUrls                 []string       `json:"StoreUrls" comment:"本地书库路径列表,支持多个路径。可以是本地文件夹或网络书库地址。"` // 书库地址列表
	LogFileName               string         `json:"LogFileName" comment:"Log文件名"`
	LogFilePath               string         `json:"LogFilePath" comment:"Log文件的保存位置"`
	LogToFile                 bool           `json:"LogToFile" comment:"是否保存程序Log到本地文件。默认不保存。"`
	MaxScanDepth              int            `json:"MaxScanDepth" comment:"最大扫描深度"`
	MinImageNum               int            `json:"MinImageNum" comment:"压缩包或文件夹内,至少有几张图片,才算作书籍"`
	OpenBrowser               bool           `json:"OpenBrowser" comment:"是否同时打开浏览器,windows默认true,其他默认false"`
	Password                  string         `json:"Password" comment:"登录界面需要的密码。"`
	Port                      int            `` /* 320-byte string literal not displayed */
	PrintAllPossibleQRCode    bool           `json:"PrintAllPossibleQRCode" comment:"扫描完成后,打印所有可能的阅读链接二维码"`
	SupportFileType           []string       `json:"SupportFileType" comment:"支持的书籍压缩包后缀"`
	SupportMediaType          []string       `json:"SupportMediaType" comment:"扫描压缩包时,用于统计图片数量的图片文件后缀"`
	SupportTemplateFile       []string       `json:"SupportTemplateFile" comment:"支持的模板文件类型,默认为html"`
	Timeout                   int            `json:"Timeout" comment:"cookie过期的时间。单位为分钟。默认60*24*30分钟后过期。"`
	TimeoutLimitForScan       int            `` /* 130-byte string literal not displayed */
	UseCache                  bool           `json:"UseCache" comment:"开启本地图片缓存,可以加快二次读取,但会占用硬盘空间"`
	Username                  string         `json:"Username" comment:"登录界用的用户名。"`
	EnableTailscale           bool           `json:"EnableTailscale" comment:"启用Tailscale网络支持"`
	TailscaleHostname         string         `json:"TailscaleHostname" comment:"Tailscale网络的主机名,默认为comigo"`
	FunnelTunnel              bool           `json:"FunnelTunnel" comment:"启用Tailscale的Funnel模式,允许通过Tailscale公开comigo服务到公网。"`
	FunnelLoginCheck          bool           `json:"funnel_enforce_password" comment:"启用Funnel模式时,强制要求使用密码登录comigo服务。"`
	TailscalePort             int            `json:"TailscalePort" comment:"Tailscale网络的端口,默认为443"`
	TailscaleAuthKey          string         `` /* 142-byte string literal not displayed */
	ZipFileTextEncoding       string         `json:"ZipFileTextEncoding" comment:"非utf-8编码的ZIP文件,尝试用什么编码解析,默认GBK"`
	EnableSingleInstance      bool           `json:"EnableSingleInstance" comment:"启用单实例模式,确保同一时间只有一个程序实例运行"`
	Language                  string         `` /* 148-byte string literal not displayed */
	RegisterContextMenu       bool           `json:"RegisterContextMenu" comment:"在 Windows 上注册资源管理器文件夹右键菜单:使用Comigo打开"`
	UnregisterContextMenu     bool           `json:"UnregisterContextMenu" comment:"在 Windows 上卸载资源管理器文件夹右键菜单:使用Comigo打开"`
}

Config Comigo全局配置

func CopyCfg added in v1.0.0

func CopyCfg() Config

func GetCfg added in v1.0.0

func GetCfg() *Config

func (*Config) AddPlugin added in v1.2.3

func (c *Config) AddPlugin(pluginName string) error

AddPlugin 启用指定插件(添加到 EnabledPluginList)

func (*Config) AddStoreUrl added in v1.1.0

func (c *Config) AddStoreUrl(storeURL string) error

AddStoreUrl 添加本地书库(单个路径) 会将相对路径转换为绝对路径,并检查路径冲突

func (*Config) AddStringArrayConfig added in v1.0.0

func (c *Config) AddStringArrayConfig(fieldName, addValue string) ([]string, error)

AddStringArrayConfig 往指定的 []string 字段中添加一个新字符串 对于 StoreUrls 字段,会进行路径验证和标准化

func (*Config) DeleteStringArrayConfig added in v1.0.0

func (c *Config) DeleteStringArrayConfig(fieldName, deleteValue string) ([]string, error)

DeleteStringArrayConfig 从指定的 []string 字段中删除某个字符串 对于 StoreUrls 字段,删除时也需要使用绝对路径进行匹配

func (*Config) DisablePlugin added in v1.2.3

func (c *Config) DisablePlugin(pluginName string) error

DisablePlugin 禁用指定插件(从 EnabledPluginList 移除)

func (*Config) GetClearDatabaseWhenExit added in v1.0.0

func (c *Config) GetClearDatabaseWhenExit() bool

func (*Config) GetDebug added in v1.0.0

func (c *Config) GetDebug() bool

func (*Config) GetEnableDatabase added in v1.0.0

func (c *Config) GetEnableDatabase() bool

func (*Config) GetEnableUpload added in v1.1.0

func (c *Config) GetEnableUpload() bool

func (*Config) GetExcludePath added in v1.0.0

func (c *Config) GetExcludePath() []string

func (*Config) GetHost added in v1.1.0

func (c *Config) GetHost() string

func (*Config) GetMaxScanDepth added in v1.0.0

func (c *Config) GetMaxScanDepth() int

func (*Config) GetMinImageNum added in v1.0.0

func (c *Config) GetMinImageNum() int

func (*Config) GetPort added in v1.1.0

func (c *Config) GetPort() int

func (*Config) GetStoreUrls added in v1.1.0

func (c *Config) GetStoreUrls() []string

func (*Config) GetSupportFileType added in v1.0.0

func (c *Config) GetSupportFileType() []string

func (*Config) GetSupportMediaType added in v1.0.0

func (c *Config) GetSupportMediaType() []string

func (*Config) GetSupportTemplateFile added in v1.0.0

func (c *Config) GetSupportTemplateFile() []string

func (*Config) GetTimeoutLimitForScan added in v1.0.0

func (c *Config) GetTimeoutLimitForScan() int

func (*Config) GetTopStoreName added in v1.0.0

func (c *Config) GetTopStoreName() string

func (*Config) GetZipFileTextEncoding added in v1.0.0

func (c *Config) GetZipFileTextEncoding() string

func (*Config) InitConfigStoreUrls added in v1.1.5

func (c *Config) InitConfigStoreUrls()

InitConfigStoreUrls 初始化配置文件中的书库,将相对路径转换为绝对路径 TODO: 后续支持网络书库的时候需要修改

func (*Config) IsPathOverlapping added in v1.2.4

func (c *Config) IsPathOverlapping(newPath string) (overlapping bool, conflictPath string, message string)

IsPathOverlapping 检查新路径是否与已有路径重合(完全相同、父子关系) 返回值: - overlapping: true 表示有重合 - conflictPath: 冲突的已有路径 - message: 错误消息

func (*Config) IsPluginEnabled added in v1.2.3

func (c *Config) IsPluginEnabled(pluginName string) bool

IsPluginEnabled 检查指定插件是否已启用

func (*Config) RequiresAuth added in v1.1.0

func (c *Config) RequiresAuth() bool

RequiresAuth 是否需要登录

func (*Config) SetConfigValue added in v1.0.0

func (c *Config) SetConfigValue(fieldName, fieldValue string) error

SetConfigValue 更新 Config 的相应字段,如果【fieldName】不存在、或【fieldValue】类型有问题,都返回错误。

func (*Config) StoreUrlIsExits added in v1.1.0

func (c *Config) StoreUrlIsExits(url string) bool

StoreUrlIsExits 检查书库URL是否可添加(已弃用,使用 IsPathOverlapping 代替)

type CustomPlugin added in v1.2.4

type CustomPlugin struct {
	Name     string // 文件名
	Content  string // 文件内容
	FileType string // html/css/js
	Scope    string // global/shelf/flip/scroll
}

CustomPlugin 用户自定义插件结构

func GetCustomPluginsByScope added in v1.2.4

func GetCustomPluginsByScope(scope string) []CustomPlugin

GetCustomPluginsByScope 根据范围获取自定义插件

func LoadBookPlugins added in v1.2.4

func LoadBookPlugins(bookID, scope string) ([]CustomPlugin, error)

LoadBookPlugins 加载特定书籍的插件(按需加载) bookID: 书籍ID,如 "aBcE4Fz" scope: 范围,如 "flip" 或 "scroll" 返回该书籍在指定范围下的插件列表

type FrpClientConfig added in v1.0.0

type FrpClientConfig struct {
	FrpcCommand      string `comment:"手动设定frpc可执行程序的路径,默认为frpc"`
	ServerAddr       string
	ServerPort       int
	Token            string
	FrpType          string // 本地转发端口设置
	RemotePort       int
	RandomRemotePort bool
}

FrpClientConfig frp客户端配置

type Status

type Status struct {
	// 当前生效的配置文件路径 None、HomeDirectory、WorkingDirectory、ProgramDirectory
	// 设置读取顺序:None(默认值) -> HomeDirectory -> ProgramDirectory -> WorkingDirectory
	In   string
	Path struct {
		// 对应配置文件的绝对路径
		WorkingDirectory string
		HomeDirectory    string
		ProgramDirectory string
	}
}

func (*Status) SetConfigStatus added in v1.0.0

func (c *Status) SetConfigStatus() error

type UploadDirOption added in v1.0.0

type UploadDirOption int

type WebPServerConfig added in v1.0.0

type WebPServerConfig struct {
	WebpCommand  string
	HOST         string
	PORT         string
	ImgPath      string
	QUALITY      int
	AllowedTypes []string
	ExhaustPath  string
}

WebPServerConfig WebPServer服务端配置

Jump to

Keyboard shortcuts

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