mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 08:06:50 +00:00
fix(channels): display video pricing per second
This commit is contained in:
1 parent
20a94fbb56
commit
bdb9a91db0
6 files changed
+78
-1
No files matched your search
@@ -135,6 +135,14 @@
|
||||
:scale="1"
|
||||
/>
|
||||
|
||||
<PricingRow
|
||||
v-if="model.pricing.billing_mode === BILLING_MODE_VIDEO && model.pricing.per_request_price != null"
|
||||
:label="t(prefixKey('videoPrice'))"
|
||||
:value="model.pricing.per_request_price"
|
||||
:unit="t(prefixKey('unitPerSecond'))"
|
||||
:scale="1"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="model.pricing.intervals && model.pricing.intervals.length > 0"
|
||||
class="mt-2 border-t pt-2"
|
||||
@@ -172,7 +180,8 @@ import { formatScaled, resolveIntervalPrices } from '@/utils/pricing'
|
||||
import {
|
||||
BILLING_MODE_TOKEN,
|
||||
BILLING_MODE_PER_REQUEST,
|
||||
BILLING_MODE_IMAGE
|
||||
BILLING_MODE_IMAGE,
|
||||
BILLING_MODE_VIDEO
|
||||
} from '@/constants/channel'
|
||||
// 复用 api/channels.ts 的用户侧最小形态 DTO。
|
||||
// admin 侧 ChannelModelPricing 字段更多,但结构上是用户 DTO 的超集,admin 视图传入可直接通过结构化子类型检查。
|
||||
@@ -235,6 +244,8 @@ const billingModeLabel = computed(() => {
|
||||
return t(prefixKey('billingModePerRequest'))
|
||||
case BILLING_MODE_IMAGE:
|
||||
return t(prefixKey('billingModeImage'))
|
||||
case BILLING_MODE_VIDEO:
|
||||
return t(prefixKey('billingModeVideo'))
|
||||
default:
|
||||
return '-'
|
||||
}
|
||||
@@ -246,6 +257,9 @@ function formatRange(min: number, max: number | null): string {
|
||||
}
|
||||
|
||||
function formatInterval(iv: UserPricingInterval, pricing: UserSupportedModelPricing): string {
|
||||
if (pricing.billing_mode === BILLING_MODE_VIDEO) {
|
||||
return `${formatScaled(iv.per_request_price, 1)} ${t(prefixKey('unitPerSecond'))}`
|
||||
}
|
||||
if (pricing.billing_mode === BILLING_MODE_PER_REQUEST || pricing.billing_mode === BILLING_MODE_IMAGE) {
|
||||
return formatScaled(iv.per_request_price, 1)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,61 @@ vi.mock('vue-i18n', async () => {
|
||||
})
|
||||
|
||||
describe('SupportedModelChip', () => {
|
||||
it.each(['availableChannels.pricing', 'admin.availableChannels.pricing'])(
|
||||
'shows video prices per second using %s translations',
|
||||
async (pricingKeyPrefix) => {
|
||||
const wrapper = mount(SupportedModelChip, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
pricingKeyPrefix,
|
||||
model: {
|
||||
name: 'video-test',
|
||||
platform: '',
|
||||
pricing: {
|
||||
billing_mode: 'video',
|
||||
input_price: null,
|
||||
output_price: null,
|
||||
cache_write_price: null,
|
||||
cache_read_price: null,
|
||||
image_input_price: null,
|
||||
image_output_price: null,
|
||||
per_request_price: 0.05,
|
||||
intervals: [
|
||||
{ tier_label: '480p', min_tokens: 0, max_tokens: null, input_price: null, output_price: null, cache_write_price: null, cache_read_price: null, per_request_price: 0 },
|
||||
{ tier_label: '720p', min_tokens: 0, max_tokens: null, input_price: null, output_price: null, cache_write_price: null, cache_read_price: null, per_request_price: 0.12 }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
try {
|
||||
await wrapper.find('[tabindex="0"]').trigger('mouseenter')
|
||||
await nextTick()
|
||||
const tooltip = document.body.querySelector('[role="tooltip"]')
|
||||
expect(tooltip?.textContent).toContain(`${pricingKeyPrefix}.billingModeVideo`)
|
||||
expect(tooltip?.textContent).toContain(`${pricingKeyPrefix}.videoPrice`)
|
||||
expect(tooltip?.textContent).toContain(`$0.05 ${pricingKeyPrefix}.unitPerSecond`)
|
||||
expect(tooltip?.textContent).toContain('480p')
|
||||
expect(tooltip?.textContent).toContain(`$0 ${pricingKeyPrefix}.unitPerSecond`)
|
||||
expect(tooltip?.textContent).toContain('720p')
|
||||
expect(tooltip?.textContent).toContain(`$0.12 ${pricingKeyPrefix}.unitPerSecond`)
|
||||
const model = wrapper.props('model')
|
||||
await wrapper.setProps({
|
||||
model: { ...model, pricing: { ...model.pricing!, per_request_price: null } }
|
||||
})
|
||||
expect(tooltip?.textContent).not.toContain(`${pricingKeyPrefix}.videoPrice`)
|
||||
expect(tooltip?.textContent).toContain(`$0.12 ${pricingKeyPrefix}.unitPerSecond`)
|
||||
await wrapper.setProps({
|
||||
model: { ...model, pricing: { ...model.pricing!, per_request_price: 0 } }
|
||||
})
|
||||
expect(tooltip?.textContent).toContain(`${pricingKeyPrefix}.videoPrice`)
|
||||
expect(wrapper.findComponent({ name: 'PricingRow' }).text()).toContain(`$0 ${pricingKeyPrefix}.unitPerSecond`)
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
it('仅配置区间倍率时按基础价展示 token 档位', async () => {
|
||||
const wrapper = mount(SupportedModelChip, {
|
||||
attachTo: document.body,
|
||||
|
||||
@@ -27,6 +27,8 @@ export default {
|
||||
billingModePerRequest: 'Per Request',
|
||||
billingModeImage: 'Per Image',
|
||||
billingModeVideo: 'Per Video',
|
||||
videoPrice: 'Video Price',
|
||||
unitPerSecond: '/ second',
|
||||
inputPrice: 'Input',
|
||||
outputPrice: 'Output',
|
||||
cacheWritePrice: 'Cache Write',
|
||||
|
||||
@@ -620,6 +620,8 @@ export default {
|
||||
billingModePerRequest: 'Per Request',
|
||||
billingModeImage: 'Per Image',
|
||||
billingModeVideo: 'Per Video',
|
||||
videoPrice: 'Video Price',
|
||||
unitPerSecond: '/ second',
|
||||
inputPrice: 'Input',
|
||||
outputPrice: 'Output',
|
||||
cacheWritePrice: 'Cache Write',
|
||||
|
||||
@@ -27,6 +27,8 @@ export default {
|
||||
billingModePerRequest: '按次',
|
||||
billingModeImage: '按图片',
|
||||
billingModeVideo: '按视频',
|
||||
videoPrice: '视频单价',
|
||||
unitPerSecond: '/ 秒',
|
||||
inputPrice: '输入',
|
||||
outputPrice: '输出',
|
||||
cacheWritePrice: '缓存写入',
|
||||
|
||||
@@ -625,6 +625,8 @@ export default {
|
||||
billingModePerRequest: '按次',
|
||||
billingModeImage: '按图片',
|
||||
billingModeVideo: '按视频',
|
||||
videoPrice: '视频单价',
|
||||
unitPerSecond: '/ 秒',
|
||||
inputPrice: '输入',
|
||||
outputPrice: '输出',
|
||||
cacheWritePrice: '缓存写入',
|
||||
|
||||
Reference in new issue
Block a user