在 SQL 查询中使用 CASE WHEN > 0 回退策略,让渠道定价的扩展比率
(cache_ratio, cache_creation_ratio, image_ratio, audio_ratio,
audio_completion_ratio) 在未设置时自动回退到全局默认值,
而不是像 COALESCE 那样被零值拦截。同时更新 GROUP BY 子句包含所有
新选择的列,确保 MySQL 兼容。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1. Extract parseTokenKey helper function to eliminate code duplication
2. Add channelId validation to prevent invalid formats like sk-abc:def:ghi
3. Add database migration to drop deprecated bound_channel_id column
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add support for sk-{key}:{channelId} format to specify channel dynamically
- Remove BoundChannelId field and related code
- All users can now specify channels, not just admins
- Add model validation when channel is specified
- Remove bound channel UI from token management
Breaking change: tokens can no longer be bound to channels at creation time.
Use sk-{key}:{channelId} format instead.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add "by price" sub-mode for per-token pricing (auto-calculate ratios)
- Add color picker with preset colors in tag manager
- Display tags with colors in channel pricing view and selector
- Remove unused function, extract hardcoded color constants
- Fix pricing model filter (status==0 instead of status!=1)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This PR fixes three issues:
1. Token bound_channel_id not updating: Add bound field to Update() method
2. Channel pricing quota_type detection: Use QuotaTypeByCall constant instead of magic number 1
3. Log display for ratio-based pricing: Set ModelPrice=-1 for ratio-based pricing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a new /api/user/channels endpoint that returns only enabled channels
with non-sensitive fields (id, name, type, remark) for token channel binding.
Update EditTokenModal to use this endpoint and display remark instead of ID
in the channel dropdown.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add BoundChannelId field to support binding a token to a specific channel.
When set, the token will always use the bound channel for requests.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add the new pricing models to both migrateDB() and migrateDBFast()
functions to enable automatic table creation on database initialization.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous implementation only did INSERT without handling conflicts.
Now uses GORM's OnConflict clause to properly update existing records
when (model_name, channel_id) unique constraint is violated.
On conflict updates: quota_type, model_ratio, completion_ratio,
model_price, tag_ids, updated_time
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add new model to support per-channel pricing for models,
allowing the same model to have different prices across
different channels.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a channel is created or updated, automatically sync its models to the
models table if they don't exist. Models created this way are marked with
SyncOfficial=0 to prevent official sync from overwriting them.