Skip to content

feat(settings): 工作区背景新增「壁纸市场」(Wallhaven SFW 图库浏览/下载/应用) - #626

Open
user-A100 wants to merge 9 commits into
xintaofei:mainfrom
user-A100:feat/workspace-wallpaper-market
Open

feat(settings): 工作区背景新增「壁纸市场」(Wallhaven SFW 图库浏览/下载/应用)#626
user-A100 wants to merge 9 commits into
xintaofei:mainfrom
user-A100:feat/workspace-wallpaper-market

Conversation

@user-A100

Copy link
Copy Markdown

Closes #624

功能概述 / What

在 设置 → 外观 → 工作区背景 中新增「壁纸市场」:浏览 Wallhaven 公开图库(purity=100 SFW 强制),点击缩略图即由后端下载、校验并立即应用为当前背景。

改动
Rust 核心 backgrounds/marketplace.rs(新):搜索(purity=100 硬编码、分类映射 all/general/anime/people→111/100/010/001)、缩略图代理、下载。全部 URL 经 https + wallhaven.cc/子域 白名单校验(拒绝 userinfo),Content-Type 限 jpeg/png/webp,响应体双重上限(搜索 4 MiB / 缩略图 4 MiB / 原图 16 MiB),下载复用既有 validate_background + write_background_atomic —— 与本地选图同一条安全路径
命令面 background_market_search / _asset / _download 三组:commands/background.rs_core + tauri command、web/handlers/background.rs Axum handler、router/lib.rs 注册,Tauri 与 standalone-server 双模式同构
前端 lib/workspace-background-market.ts transport 绑定(camelCase 镜像);useProxiedBackgroundThumb(模块级 asset 缓存 + per-consumer blob URL,镜像宠物市场同款 hook)
Provider downloadMarketWorkspaceBackground(后端落盘 → bump 版本戳 → 跨窗口重读盘,与本地选图共用失效广播);workspaceBgSourceUrl「使用中」标记(localStorage,本地图/移除时清除)
UI workspace-background-market-dialog.tsx:搜索(300ms 防抖)+ 分类 + 缩略图网格 + 分页 + 加载/空/错误可重试三态 + 「使用中」徽标;入口为工作区背景区「壁纸市场」按钮
i18n AppearanceSettings.workspaceBackground.market.* 10 locale 同步(messages.test.ts 键集校验通过)

设计取舍 / Why

  • 复刻宠物市场三层模式pets/marketplace.rs → commands → transport):与仓库既有市场类功能同构,无新依赖(reqwest/base64 均已在 Cargo.toml)。
  • 16 MiB 下载上限(而非 issue 初稿提的 40MB):对齐 backgrounds::MAX_BG_BYTES,市场图与本地选图共享同一张安全网,避免出现第二套上限。
  • 缩略图经后端代理:部分网络下 webview 无法直连 th.wallhaven.cc(与宠物市场代理 codex-pets.net 同因)。
  • 单图模型不需要 library 去重:ccgui 式的 sourcePath 库在 codeg「单背景文件」模型下退化为 localStorage 来源标记。

验证 / How verified

自动化(本机全部实际执行):

  • cargo test --no-default-features --bin codeg-server --lib ✅(含 marketplace 8 个新单测:URL 白名单/分类映射/payload 解析/去窄化)
  • cargo clippy --all-targets --features test-utils -- -D warnings ✅、cargo clippy --no-default-features --bin codeg-server --lib -- -D warnings
  • cargo check(tauri)与 cargo check --no-default-features --bin codeg-server
  • pnpm vitest run --maxWorkers=1397 文件 / 5620 测试全部通过(Task 4/5 两次全量)✅
  • npx tsc --noEmit ✅、eslint 对全部改动文件 ✅

手动 smoke(桌面 dev 构建)✅:市场打开/搜索/分类/下载应用/「使用中」徽标/分页/本地图覆盖清除标记。

环境备注:--features test-utils 的 lib 测试 exe 在本机 Windows 因 comctl32 manifest 无法直接启动,故单测经 server-mode 目标运行;pnpm test 多 worker 在本机 tinypool 崩溃,均与本 PR 改动无关(stash 基线复现)。

English summary: Adds a "Wallpaper Market" to Settings → Appearance → Workspace Background, backed by the key-free Wallhaven public search API. SFW is hard-coded (purity=100), all URLs pass an https + wallhaven.cc allowlist, search/asset/download are proxied host-side, and downloads go through the exact same validation + atomic write as a manual background pick. Dual-mode (Tauri + standalone server), 10-locale i18n, full test suite green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【功能建议】为「工作区背景」增加在线壁纸市场(Wallhaven 公开图库,无需 API key)

1 participant