| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- // ============================================================================
- // config_types.go — 配置结构体(服务模式与 GUI 共用)
- //
- // AppSettings 中引用的功能配置结构体,独立成文件避免 GUI 服务文件被服务模式
- // 排除后结构体无处定义。json tag 与 AppSettings 字段一一对应。
- // ============================================================================
- package main
- import "strings"
- // YTDLPConfig 视频下载(yt-dlp)的配置
- type YTDLPConfig struct {
- Dir string `json:"dir"` // 下载保存目录,空=程序当前工作目录
- Mp3Quality string `json:"mp3Quality"` // mp3 转换质量:0-9(VBR,0 最好)或 128K/192K/320K,默认 0
- }
- // MeituConfig 美图工具配置
- type MeituConfig struct {
- MaxSize int `json:"maxSize"` // 悬停预览大图最大边长(px),默认 400
- }
- // validMp3Quality 校验 mp3 转换质量参数:0-9(VBR,0 最好)或常见码率。
- func validMp3Quality(q string) bool {
- switch strings.ToUpper(q) {
- case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "128K", "192K", "320K":
- return true
- }
- return false
- }
- // LocalTool 本地资源/工具配置项(「本地」页,在设置中维护)
- type LocalTool struct {
- Title string `json:"title"` // 显示标题
- Cmd string `json:"cmd"` // 启动命令(程序/脚本,可带参数与环境变量)
- Desc string `json:"desc"` // 说明文字(可空)
- }
- // 古诗配置默认值(PoemConfig 字段为空时使用)
- const (
- DefaultPoemColor = "#c98a3a" // 默认文字颜色(深琥珀,暗底明显可读)
- DefaultPoemFontSize = 16 // 默认字号(px)
- DefaultPoemInterval = 60 // 默认随机换诗间隔(秒),0 表示不自动换
- DefaultPoemSpeed = 18 // 默认滚动一轮时长(秒)
- )
- // LocalSendConfig 是 LocalSend 的运行时配置。
- type LocalSendConfig struct {
- Enabled bool `json:"enabled"` // 是否已启动服务
- Alias string `json:"alias"` // 本机名称(广播给其他设备)
- ReceiveDir string `json:"receiveDir"` // 接收文件保存目录
- AutoAccept bool `json:"autoAccept"` // true=自动接收;false=手动确认
- Port int `json:"port"` // 监听端口
- Fingerprint string `json:"fingerprint"` // 本机证书指纹
- }
- // CrocConfig 是 Croc 传送的配置(发送/接收共用密码)。
- type CrocConfig struct {
- Password string `json:"password"` // 发送/接收共用密码:作为 croc 传输码(--code),空=使用随机传输码
- Dir string `json:"dir"` // 接收保存目录,空=当前工作目录
- }
- // PoemConfig 古诗显示的配置
- type PoemConfig struct {
- Enabled bool `json:"enabled"` // 是否启用古诗显示
- Color string `json:"color"` // 文字颜色
- FontSize int `json:"fontSize"` // 字号(px)
- TTS bool `json:"tts"` // 允许 TTS 阅读(显示朗读按钮)
- Interval int `json:"interval"` // 自动换诗间隔(秒),0 表示不自动换
- Speed int `json:"speed"` // 滚动速度(秒/轮),即滚动一个文本周期所需秒数,越小越快
- }
- // normalizePoemConfig 校正古诗配置:颜色默认、字号限制、间隔限制
- func normalizePoemConfig(cfg PoemConfig) PoemConfig {
- if strings.TrimSpace(cfg.Color) == "" {
- cfg.Color = DefaultPoemColor
- }
- if cfg.FontSize < 12 || cfg.FontSize > 48 {
- cfg.FontSize = DefaultPoemFontSize
- }
- if cfg.Interval < 0 || cfg.Interval > 3600 {
- cfg.Interval = DefaultPoemInterval
- }
- if cfg.Speed < 5 || cfg.Speed > 120 {
- cfg.Speed = DefaultPoemSpeed
- }
- return cfg
- }
- // ResourcesConfig 「设置-资源」栏配置:允许下载外部工具(ffmpeg/croc 等)
- type ResourcesConfig struct {
- ServerURL string `json:"serverURL"` // 自定义资源清单服务器地址;空=使用内置默认清单
- DownloadDir string `json:"downloadDir"` // 下载/解压目标目录;空=程序目录/resources
- AutoInstallPath bool `json:"autoInstallPath"` // 下载成功后是否加入用户 PATH,默认 true
- }
- // ResourceItem 单个可下载资源条目(内置清单或服务器返回的 resources.json 条目)
- type ResourceItem struct {
- Name string `json:"name"` // 唯一标识,如 ffmpeg
- Version string `json:"version"` // 版本号,如 6.1.1
- URL string `json:"url"` // 主下载地址(优先 GitHub;空=无主源,改用镜像)
- MirrorURL string `json:"mirrorUrl"` // 镜像/资源站下载地址(备选源,可手动选择)
- Size int64 `json:"size"` // 字节,0=未知
- Desc string `json:"desc"` // 说明文字
- Platform string `json:"platform"` // 目标平台,如 windows-amd64
- OS string `json:"os"` // 目标操作系统,如 windows/linux/darwin;空=不限(本机可用)
- Homepage string `json:"homepage"` // 官网地址,点击名称可在浏览器打开;空=不可点击
- }
|