// Package dto 壁纸模块的数据传输对象。 // // 设计要点:**把「开源平台」和「自建图库」两种来源统一成同一个输出形状 // (WallpaperItem)**,前端拿到的东西长得一模一样 —— 分页、渲染、下载、 // 全屏都只需要一套代码。来源差异只在后端消化。 package dto // WallpaperItem 是壁纸模块对外的统一输出条目。 // // 无论图片来自开源平台还是自建图库,都填这个结构: // - FromOpen=true 时 Id 为平台内 id(用于下载上报),Url 指向平台 CDN; // - FromOpen=false 时 Id 为库内主键,Url 指向本站 nginx 直出的原图。 type WallpaperItem struct { // ---- 通用 ---- Id string `json:"id"` Title string `json:"title"` Width int `json:"width"` Height int `json:"height"` Orientation int `json:"orientation"` // 0未知 1横版 2竖版 3方形 // ---- 三档图片地址 ---- // Thumb 用于列表网格、Preview 用于全屏展示、Full 用于下载。 // 自建图库这三者分别是 480px 缩略图 / 长边 1920 预览图 / 原图; // 开源平台则取各平台 CDN 提供的对应尺寸,没有的就退回上一档。 ThumbUrl string `json:"thumbUrl"` PreviewUrl string `json:"previewUrl"` FullUrl string `json:"fullUrl"` // ---- 归属 ---- Source string `json:"source"` // 平台编码,自建图库固定为 "mine" SourceName string `json:"sourceName"` // 平台显示名,用于界面标注 FromOpen bool `json:"fromOpen"` // true=开源平台 false=自建图库 // ---- 版权信息(自建图库留空)---- Author string `json:"author"` AuthorUrl string `json:"authorUrl"` PageUrl string `json:"pageUrl"` // 平台详情页,用于「查看原页面」 License string `json:"license"` // 许可说明,如 "Unsplash License" // ---- 自建图库专有 ---- Tags string `json:"tags"` Category string `json:"category"` Filesize int64 `json:"filesize"` CreatedAt string `json:"createdAt"` } // WallpaperSourceInfo 是开源平台的可用性描述,供前端渲染平台切换器。 // // Enabled 与 Configured 要分开看:前者是用户的开关,后者是凭据是否齐备。 // 两者都为真时 Available 才为真 —— 前端据此把平台置灰并给出 Hint, // 而不是点了没反应。 type WallpaperSourceInfo struct { Code string `json:"code"` Name string `json:"name"` Enabled int `json:"enabled"` Sort int `json:"sort"` Configured bool `json:"configured"` Available bool `json:"available"` Hint string `json:"hint"` // 不可用原因,可用时为空 Remark string `json:"remark"` // Config 是脱敏后的配置(apiKey 只回传是否已设置,不回传明文)。 HasApiKey bool `json:"hasApiKey"` } // WallpaperSourceConfig 对应 wallpaper_source.config 字段的 JSON。 // // 全部字段可选:缺失即用该平台的默认值。解析失败不报错、回退全默认, // 避免一个平台的脏配置拖垮整个来源列表。 type WallpaperSourceConfig struct { // ApiKey / ApiSecret 平台凭据。Bing 与 Picsum 不需要。 ApiKey string `json:"apiKey"` ApiSecret string `json:"apiSecret"` // DefaultQuery 默认搜索词,用户没传关键词时用。 DefaultQuery string `json:"defaultQuery"` // Purity 分级过滤(Wallhaven):sfw / sketchy / nsfw。默认只放 sfw。 Purity string `json:"purity"` // Categories 分类(Wallhaven):general/anime/people 的组合,逗号分隔。 Categories string `json:"categories"` // BaseUrl 可选覆盖平台接口地址(便于自建反代或走镜像)。 BaseUrl string `json:"baseUrl"` } // WallpaperSourceSaveInput 是后台保存开源平台配置的入参。 type WallpaperSourceSaveInput struct { Code string `json:"code"` Name string `json:"name"` Enabled int `json:"enabled"` Sort int `json:"sort"` Remark string `json:"remark"` // Config 是 dto.WallpaperSourceConfig 的 JSON 字符串。 // 其中 apiKey 允许留空 —— 留空表示「不修改已保存的 Key」, // 这样后台就不必把密钥明文回传到前端再原样传回来。 Config string `json:"config"` } // WallpaperQuery 是列表查询条件,开源平台与自建图库共用。 type WallpaperQuery struct { Source string // 平台编码;"mine" 表示自建图库 Query string // 搜索词(自建图库匹配标题/标签/分类) Orientation int // 0不限 1横版 2竖版 3方形 Tag string // 标签(仅自建图库) Page int Size int } // WallpaperSaveInput 是后台编辑壁纸元数据的入参(不含文件本身)。 type WallpaperSaveInput struct { Id uint64 `json:"id"` Title string `json:"title"` Tags string `json:"tags"` Category string `json:"category"` Enabled int `json:"enabled"` Sort int `json:"sort"` Remark string `json:"remark"` } // WallpaperStat 是图库概览统计。 type WallpaperStat struct { Total int `json:"total"` // 总数 Enabled int `json:"enabled"` // 启用数 Disabled int `json:"disabled"` // 停用数 Portrait int `json:"portrait"` // 竖版数 Landscape int `json:"landscape"` // 横版数 TotalBytes int64 `json:"totalBytes"` // 原图占用字节 }