Skip to content

Feature/dynamic pricing - #4117

Closed
only-wjt wants to merge 3 commits into
QuantumNous:mainfrom
only-wjt:feature/dynamic-pricing
Closed

Feature/dynamic pricing#4117
only-wjt wants to merge 3 commits into
QuantumNous:mainfrom
only-wjt:feature/dynamic-pricing

Conversation

@only-wjt

@only-wjt only-wjt commented Apr 7, 2026

Copy link
Copy Markdown

根据时间动态调整倍率

Summary by CodeRabbit

Release Notes

  • New Features

    • Maintenance Mode: Schedule planned maintenance windows with advance user notification, admin bypass option, and whitelist capabilities.
    • Time-Based Dynamic Pricing: Configure rules to apply pricing multipliers during specific days/hours.
    • Token Configuration Export: One-click export of token configs for integration with Codex, Claude Code, Cursor, and other tools.
  • Documentation

    • Comprehensive implementation roadmap for monitoring, scheduling, cleanup, and other platform enhancements.

onlyWjt added 3 commits April 6, 2026 21:30
- 后端: 配置结构 + 中间件 + 控制器 + 路由挂载
- 后端: 登录接口维护期间拦截普通用户
- 后端: GetStatus 接口联动 maintenance 字段
- 前端: 维护设置管理页面 (SettingsMaintenance)
- 前端: 用户端 MaintenanceBanner (全屏遮挡/预告 Banner)
- 前端: 中英文国际化翻译
- 权限: root 始终放行, admin 可配置, 普通用户拦截
# Conflicts:
#	controller/misc.go
#	controller/user.go
#	electron/build.sh
#	router/api-router.go
#	router/relay-router.go
#	router/video-router.go
#	web/src/components/layout/PageLayout.jsx
#	web/src/components/settings/OperationSetting.jsx
#	web/src/i18n/locales/en.json
#	web/src/i18n/locales/zh-CN.json
- 新增 setting/operation_setting/time_dynamic_ratio.go(规则引擎:支持时间段/星期/分组/模型维度匹配)
- 新增 controller/time_dynamic_ratio.go(管理 API:CRUD + ConfigManager 前缀格式持久化)
- 新增 web/src/pages/Setting/Operation/SettingsTimeDynamicRatio.jsx(运营管理界面)
- 修改 relay/helper/price.go(注入 TimeDynamicMultiplier 到计费流程)
- 修改 service/text_quota.go + task_billing.go(计费公式乘以时间倍率)
- 修改 service/log_info_generate.go(日志 other 字段记录 time_dynamic_multiplier)
- 修改 controller/relay.go(响应头 X-New-Api-Time-Dynamic-Multiplier + 异步任务快照)
- 修改前端日志渲染(日志详情/计费过程/列表摘要三处显示时间倍率)
- 修改 types/price_data.go + model/task.go(数据结构扩展)
- 修改 router/api-router.go(注册管理路由)
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This PR introduces multiple interconnected features for New-API: maintenance mode with time windows and whitelist controls, time-based dynamic pricing multipliers for temporal pricing adjustments, token configuration export functionality, and comprehensive implementation documentation. Changes span documentation files, Go backend logic (controllers, middleware, settings), TypeScript/React frontend components, and i18n localization.

Changes

Cohort / File(s) Summary
Implementation Documentation
aidoc/implementation_plan.md, aidoc/implementation_plan_revised.md, aidoc/implementation_playbook.md, aidoc/newapiplus自定义开发实施方案.md
Detailed technical specifications and phased delivery roadmaps for the New-API secondary development initiative, including architecture diagrams, module breakdown, Sprint planning, and engineering constraints.
Feature Module Documentation
aidoc/module_1_monitor.md, aidoc/module_2_scheduler.md, aidoc/module_3_maintenance.md, aidoc/module_4_concurrency.md, aidoc/module_5_fallback.md, aidoc/module_6_import.md, aidoc/module_7_cleanup.md, aidoc/module_8_extras.md
Feature-level design documents covering slow request monitoring, scheduling engine, maintenance mode, user concurrency limits, channel fallback strategies, token export, inactive account cleanup, and additional optional features.
Maintenance Mode Backend
controller/maintenance.go, middleware/maintenance.go, setting/system_setting/maintenance.go
Maintenance mode control with time-window validation, whitelist enforcement, admin bypass logic, Redis/database persistence, and gating of login operations during active maintenance.
Time Dynamic Ratio Backend
setting/operation_setting/time_dynamic_ratio.go, controller/time_dynamic_ratio.go, relay/helper/price.go, service/task_billing.go, service/text_quota.go
Time-based multiplier resolution with weekday/time window/group/model matching, quota and billing recalculation integration points, and configuration management.
Token Export Backend
controller/token_export.go
HTTP endpoint and helper functions to generate and export token configurations for external tools (Codex, Claude Code, Cursor, generic OpenAI) with environment scripts, config files, and test commands.
Relay & Pricing Integration
controller/relay.go, types/price_data.go, model/task.go, relay/helper/price.go, service/log_info_generate.go
Extension of billing context and price data structures to propagate time dynamic multiplier through relay processing, quota calculation, and logging pipelines.
Login & Status Gating
controller/user.go, controller/misc.go
Addition of maintenance-mode login gate and status endpoint enrichment with maintenance configuration for public consumption.
Router Middleware Wiring
router/relay-router.go, router/video-router.go, router/api-router.go
Middleware chain updates to include maintenance checks on relay endpoints and new authenticated routes for maintenance/time-dynamic-ratio management.
Frontend Maintenance UI
web/src/components/layout/MaintenanceBanner.jsx, web/src/pages/Setting/Operation/SettingsMaintenance.jsx, web/src/components/layout/PageLayout.jsx
Maintenance banner component (overlay and sticky notices based on time window and user role) and admin configuration page with time picker, whitelist user input, and status controls.
Frontend Time Dynamic Ratio UI
web/src/pages/Setting/Operation/SettingsTimeDynamicRatio.jsx
Admin page for managing time-based multiplier rules: rule creation/editing with time/weekday/group/model selectors, priority reordering, enable/disable toggles, and API integration.
Frontend Token Export UI
web/src/components/table/tokens/modals/TokenExportConfigModal.jsx
Modal component displaying tool-specific token export configurations with environment variables, config file paths/content, test commands, and one-click copy actions.
Frontend Integration
web/src/components/settings/OperationSetting.jsx, web/src/components/table/usage-logs/UsageLogsColumnDefs.jsx, web/src/hooks/usage-logs/useUsageLogsData.jsx
Integration of new maintenance and time-dynamic-ratio settings panels; augmentation of usage log UI to display time multiplier when applied.
Internationalization
web/src/i18n/locales/en.json, web/src/i18n/locales/zh-CN.json
Locale keys for maintenance mode configuration, time dynamic ratio rules, and related user-facing messages in English and Simplified Chinese.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024
  • Calcium-Ion

Poem

🐰 Maintenance calls, time bends with grace,
Tokens exported to every place,
Multipliers bloom in twilight hours,
New-API shines with scheduling powers!
Planning complete, the roadmap's clear—
Let the development begin here! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.89% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Feature/dynamic pricing' partially describes the changeset but is not fully specific. While dynamic pricing is indeed a core feature added, the PR also includes maintenance mode V1—a significant, independent feature. The title only highlights one of two major feature areas.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feature/dynamic-pricing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@only-wjt only-wjt closed this Apr 7, 2026
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.

1 participant