config_types.go 4.9 KB

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