refactor(assets): Phase 1 - extract types, constants and utils #892

Merged
auto-approve-bot merged 3 commits from refactor/asset-library-phase1 into develop 2026-07-25 17:18:27 +08:00
Owner

AssetLibrary 重构 Phase 1

背景

AssetLibrary.tsx (1279行) 三阶段渐进式重构的第一步,抽离类型、常量和工具函数。

变更内容

**新增文件 (5个):

  • apps/web/src/pages/assets/types.ts — 类型定义与数据映射
    • AssetKind, StatusType, LibraryItem, AssetItem
    • inferKind, inferStatus, mapLibrary, mapAsset
  • apps/web/src/pages/assets/constants.ts — 常量配置
    • 文件大小限制、筛选选项、分类配置、状态配置
  • apps/web/src/pages/assets/utils/format.ts — 格式化工具
    • formatDuration, formatFileSize, formatDate
  • apps/web/src/pages/assets/utils/asset.ts — 素材工具函数
    • kindLabel, thumbGradient
  • apps/web/src/test/pages/assets/smoke.test.tsx — smoke test

修改文件:

  • apps/web/src/pages/assets/AssetLibrary.tsx — 移除已抽离的代码,改为 import 新模块

数据

  • 主文件行数: 1279 → 1124 行(-155行,-12.1%)

验收

  • pnpm lint 通过
  • pnpm tsc --noEmit 通过
  • pnpm test run related 通过
  • 功能等价,无行为变化
  • 0 any、0 ts-ignore、0 eslint-disable
  • import 路径统一使用 @/pages/assets/xxx

参考

对齐 VoiceLibrary 和 VoiceMaterialLibrary 的 Phase 1 重构模式。

## AssetLibrary 重构 Phase 1 ### 背景 AssetLibrary.tsx (1279行) 三阶段渐进式重构的第一步,抽离类型、常量和工具函数。 ### 变更内容 **新增文件 (5个): - `apps/web/src/pages/assets/types.ts` — 类型定义与数据映射 - `AssetKind`, `StatusType`, `LibraryItem`, `AssetItem` - `inferKind`, `inferStatus`, `mapLibrary`, `mapAsset` - `apps/web/src/pages/assets/constants.ts` — 常量配置 - 文件大小限制、筛选选项、分类配置、状态配置 - `apps/web/src/pages/assets/utils/format.ts` — 格式化工具 - `formatDuration`, `formatFileSize`, `formatDate` - `apps/web/src/pages/assets/utils/asset.ts` — 素材工具函数 - `kindLabel`, `thumbGradient` - `apps/web/src/test/pages/assets/smoke.test.tsx` — smoke test **修改文件:** - `apps/web/src/pages/assets/AssetLibrary.tsx` — 移除已抽离的代码,改为 import 新模块 ### 数据 - 主文件行数: 1279 → 1124 行(-155行,-12.1%) ### 验收 - [ ] `pnpm lint` 通过 - [ ] `pnpm tsc --noEmit` 通过 - [ ] `pnpm test run related` 通过 - [x] 功能等价,无行为变化 - [x] 0 any、0 ts-ignore、0 eslint-disable - [x] import 路径统一使用 `@/pages/assets/xxx` ### 参考 对齐 VoiceLibrary 和 VoiceMaterialLibrary 的 Phase 1 重构模式。
xiaoxia added 1 commit 2026-07-25 16:22:54 +08:00
refactor(assets): Phase 1 - extract types, constants and utils
AI Code Review / AI Code Review (pull_request) Failing after 0s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 18s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 43s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 47s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 16s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 44s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m59s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 1m56s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 42s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 15s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 40s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m27s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 16s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
17c125f8a5
Extract types, constants, and utility functions from AssetLibrary.tsx
into separate modules, following the VoiceLibrary / VoiceMaterialLibrary
refactoring pattern:

- types.ts: AssetKind, StatusType, LibraryItem, AssetItem interfaces
  and mapping functions (mapLibrary, mapAsset, inferKind, inferStatus)
- constants.ts: file size limits, filter options, category configs
- utils/format.ts: formatDuration, formatFileSize, formatDate
- utils/asset.ts: kindLabel, thumbGradient

Also adds smoke test for vitest related mode coverage.

Main file: 1279 → 1124 lines (-155)
xiaoxia added 1 commit 2026-07-25 17:03:52 +08:00
fix(assets): remove unused LibraryItem import
AI Code Review / AI Code Review (pull_request) Failing after 0s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 4s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 47s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 30s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 46s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Web Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Successful in 41s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 41s
c91e37eaa3
xiaoxia added 1 commit 2026-07-25 17:12:27 +08:00
fix(assets): lint errors for Phase 1
AI Code Review / AI Code Review (pull_request) Failing after 0s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 5s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 50s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 49s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 42s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m7s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 15s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m5s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 45s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 12s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m50s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 15s
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m36s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Failing after 14s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 20s
9dad7c333e
auto-approve-bot approved these changes 2026-07-25 17:17:06 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-07-25 17:17:06 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot merged commit 32868e54ad into develop 2026-07-25 17:18:27 +08:00
auto-approve-bot deleted branch refactor/asset-library-phase1 2026-07-25 17:18:28 +08:00

🗑️ 预览环境已清理

PR #892 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #892 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.