config_types.go 4.6 KB

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