mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-18 02:07:26 +00:00
Replace the legacy boolean “DisplayInCurrencyEnabled” with an injected, type-safe
configuration `general_setting.quota_display_type`, and wire it through the
backend and frontend.
Backend
- Add `QuotaDisplayType` to `operation_setting.GeneralSetting` with injected
registration via `config.GlobalConfig.Register("general_setting", ...)`.
Helpers: `IsCurrencyDisplay()`, `IsCNYDisplay()`, `GetQuotaDisplayType()`.
- Expose `quota_display_type` in `/api/status` and keep legacy
`display_in_currency` for backward compatibility.
- Logger: update `LogQuota` and `FormatQuota` to support USD/CNY/TOKENS. When
CNY is selected, convert using `operation_setting.USDExchangeRate`.
- Controllers:
- `billing`: compute subscription/usage amounts based on the selected type
(USD: divide by `QuotaPerUnit`; CNY: USD→CNY; TOKENS: keep raw tokens).
- `topup` / `topup_stripe`: treat inputs as “amount” for USD/CNY and as
token-count for TOKENS; adjust min topup and pay money accordingly.
- `misc`: include `quota_display_type` in status payload.
- Compatibility: in `model/option.UpdateOption`, map updates to
`DisplayInCurrencyEnabled` → `general_setting.quota_display_type`
(true→USD, false→TOKENS). Keep exporting the legacy key in `OptionMap`.
Frontend
- Settings: replace the “display in currency” switch with a Select
(`general_setting.quota_display_type`) offering USD / CNY / Tokens.
Provide fallback mapping from legacy `DisplayInCurrencyEnabled`.
- Persist `quota_display_type` to localStorage (keep `display_in_currency`
for legacy components).
- Rendering helpers: base all quota/price rendering on `quota_display_type`;
use `usd_exchange_rate` for CNY symbol/values.
- Pricing page: default view currency follows site display type (USD/CNY),
while TOKENS mode still allows per-view currency toggling when needed.
Notes
- No database migrations required.
- Legacy clients remain functional via compatibility fields.
62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
export function setStatusData(data) {
|
|
localStorage.setItem('status', JSON.stringify(data));
|
|
localStorage.setItem('system_name', data.system_name);
|
|
localStorage.setItem('logo', data.logo);
|
|
localStorage.setItem('footer_html', data.footer_html);
|
|
localStorage.setItem('quota_per_unit', data.quota_per_unit);
|
|
// 兼容:保留旧字段,同时写入新的额度展示类型
|
|
localStorage.setItem('display_in_currency', data.display_in_currency);
|
|
localStorage.setItem('quota_display_type', data.quota_display_type || 'USD');
|
|
localStorage.setItem('enable_drawing', data.enable_drawing);
|
|
localStorage.setItem('enable_task', data.enable_task);
|
|
localStorage.setItem('enable_data_export', data.enable_data_export);
|
|
localStorage.setItem('chats', JSON.stringify(data.chats));
|
|
localStorage.setItem(
|
|
'data_export_default_time',
|
|
data.data_export_default_time,
|
|
);
|
|
localStorage.setItem(
|
|
'default_collapse_sidebar',
|
|
data.default_collapse_sidebar,
|
|
);
|
|
localStorage.setItem('mj_notify_enabled', data.mj_notify_enabled);
|
|
if (data.chat_link) {
|
|
// localStorage.setItem('chat_link', data.chat_link);
|
|
} else {
|
|
localStorage.removeItem('chat_link');
|
|
}
|
|
if (data.chat_link2) {
|
|
// localStorage.setItem('chat_link2', data.chat_link2);
|
|
} else {
|
|
localStorage.removeItem('chat_link2');
|
|
}
|
|
if (data.docs_link) {
|
|
localStorage.setItem('docs_link', data.docs_link);
|
|
} else {
|
|
localStorage.removeItem('docs_link');
|
|
}
|
|
}
|
|
|
|
export function setUserData(data) {
|
|
localStorage.setItem('user', JSON.stringify(data));
|
|
}
|