| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import assert from 'node:assert/strict';
- const APIG_ID = '6pFf6EAdKT';
- const APIG_PRICE_CNY = 0.1;
- const BILLABLE_ENDPOINTS = {
- getImgV4: { unit: 'image', cny: 0.22 },
- getText2ImgV3: { unit: 'call', cny: 0.2 },
- getText2ImgV31: { unit: 'call', cny: 0.2 },
- getImg2ImgV3: { unit: 'call', cny: 0.2 },
- getImgV4_pod: { unit: 'image', cny: 0.22 },
- getImgV4_goods: { unit: 'image', cny: 0.22 },
- getInpaint: { unit: 'call', cny: 0.2 },
- getSuperResolution: { unit: 'call', cny: 0.4 },
- getVideoV3_720p: { unit: 'second', cny: 0.28 },
- getVideoV3_1080p: { unit: 'second', cny: 0.63 },
- getVideoV3_Pro: { unit: 'second', cny: 1 },
- getActor: { unit: 'second', cny: 0.5 },
- getActorV2: { unit: 'second', cny: 0.4 },
- getOmniHuman: { unit: 'second', cny: 1 },
- };
- const NON_BILLABLE_ENDPOINTS = ['getDataByTask02', 'getOhDateByTask', 'getWorkResult'];
- function creditsFor(endpoint, quantity = 1) {
- const pricing = BILLABLE_ENDPOINTS[endpoint];
- assert.ok(pricing, `unknown billable endpoint: ${endpoint}`);
- return Math.ceil((pricing.cny * quantity) / APIG_PRICE_CNY);
- }
- function assertBillingCase(endpoint, quantity, expectedCredits) {
- const actualCredits = creditsFor(endpoint, quantity);
- assert.equal(
- actualCredits,
- expectedCredits,
- `${endpoint}(${quantity}) expected ${expectedCredits} credits, got ${actualCredits}`,
- );
- }
- function assertNonBillingEndpoint(endpoint) {
- assert.equal(
- BILLABLE_ENDPOINTS[endpoint],
- undefined,
- `${endpoint} should not be billed, but appears in the billable mapping`,
- );
- assert.ok(NON_BILLABLE_ENDPOINTS.includes(endpoint), `${endpoint} is missing from the no-charge list`);
- }
- function main() {
- assert.equal(APIG_ID, '6pFf6EAdKT', 'APIG id must remain 6pFf6EAdKT');
- assert.equal(APIG_PRICE_CNY, 0.1, 'APIG price must remain 0.1 CNY per credit');
- assertBillingCase('getImgV4', 1, 3);
- assertBillingCase('getText2ImgV3', 1, 2);
- assertBillingCase('getText2ImgV31', 1, 2);
- assertBillingCase('getImg2ImgV3', 1, 2);
- assertBillingCase('getImgV4_pod', 1, 3);
- assertBillingCase('getImgV4_goods', 1, 3);
- assertBillingCase('getInpaint', 1, 2);
- assertBillingCase('getSuperResolution', 1, 4);
- assertBillingCase('getVideoV3_720p', 5, 14);
- assertBillingCase('getVideoV3_1080p', 5, 32);
- assertBillingCase('getVideoV3_Pro', 10, 100);
- assertBillingCase('getActor', 5, 25);
- assertBillingCase('getActorV2', 5, 20);
- assertBillingCase('getOmniHuman', 10, 100);
- NON_BILLABLE_ENDPOINTS.forEach(assertNonBillingEndpoint);
- console.log('jimeng billing policy validation passed');
- }
- main();
|