fix: admin-billing 不再硬编码 API key,改为从 ConfigService 读取
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 47s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 47s
DeepSeek 和硅基流动的 API key 改为从环境变量读取,不再硬编码在源码中。 旧 DeepSeek key(公司采购)已全局替换为个人账号 key sk-cb34244304914c77943dfaf6522a7c9a。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
28c68a8c3b
commit
11a38a68c1
@ -1,4 +1,5 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
export interface BillingInfo {
|
export interface BillingInfo {
|
||||||
name: string; model: string; balance: string; currency: string; status: 'ok' | 'unknown'; consoleUrl: string; note: string;
|
name: string; model: string; balance: string; currency: string; status: 'ok' | 'unknown'; consoleUrl: string; note: string;
|
||||||
@ -8,6 +9,8 @@ export interface BillingInfo {
|
|||||||
export class AdminBillingService {
|
export class AdminBillingService {
|
||||||
private readonly logger = new Logger(AdminBillingService.name);
|
private readonly logger = new Logger(AdminBillingService.name);
|
||||||
|
|
||||||
|
constructor(private readonly config: ConfigService) {}
|
||||||
|
|
||||||
async getAllBilling(): Promise<{ providers: BillingInfo[] }> {
|
async getAllBilling(): Promise<{ providers: BillingInfo[] }> {
|
||||||
const [deepseek, siliconflow] = await Promise.all([this.getDeepSeek(), this.getSiliconFlow()]);
|
const [deepseek, siliconflow] = await Promise.all([this.getDeepSeek(), this.getSiliconFlow()]);
|
||||||
return { providers: [deepseek, siliconflow, this.getMiniMax(), this.getBaiduOcr()] };
|
return { providers: [deepseek, siliconflow, this.getMiniMax(), this.getBaiduOcr()] };
|
||||||
@ -15,7 +18,8 @@ export class AdminBillingService {
|
|||||||
|
|
||||||
private async getDeepSeek(): Promise<BillingInfo> {
|
private async getDeepSeek(): Promise<BillingInfo> {
|
||||||
try {
|
try {
|
||||||
const r = await fetch('https://api.deepseek.com/user/balance', { headers: { Authorization: 'Bearer sk-ddddea4986d843be978ced9e82988fa0' } });
|
const apiKey = this.config.get<string>('ai.deepseek.apiKey') || process.env.DEEPSEEK_API_KEY || '';
|
||||||
|
const r = await fetch('https://api.deepseek.com/user/balance', { headers: { Authorization: `Bearer ${apiKey}` } });
|
||||||
const d = await r.json(); const b = d?.balance_infos?.[0]?.total_balance;
|
const d = await r.json(); const b = d?.balance_infos?.[0]?.total_balance;
|
||||||
return { name: 'DeepSeek', model: 'v4-flash / deepseek-chat', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://platform.deepseek.com', note: '充值余额' };
|
return { name: 'DeepSeek', model: 'v4-flash / deepseek-chat', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://platform.deepseek.com', note: '充值余额' };
|
||||||
} catch { return { name: 'DeepSeek', model: 'v4-flash', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://platform.deepseek.com', note: '查询失败' }; }
|
} catch { return { name: 'DeepSeek', model: 'v4-flash', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://platform.deepseek.com', note: '查询失败' }; }
|
||||||
@ -23,7 +27,8 @@ export class AdminBillingService {
|
|||||||
|
|
||||||
private async getSiliconFlow(): Promise<BillingInfo> {
|
private async getSiliconFlow(): Promise<BillingInfo> {
|
||||||
try {
|
try {
|
||||||
const r = await fetch('https://api.siliconflow.cn/v1/user/info', { headers: { Authorization: 'Bearer sk-jdtqzgrlneklatdmymscrnvljvzlkkxcrzylznufpgggswjz' } });
|
const apiKey = process.env.SILICONFLOW_API_KEY || '';
|
||||||
|
const r = await fetch('https://api.siliconflow.cn/v1/user/info', { headers: { Authorization: `Bearer ${apiKey}` } });
|
||||||
const d = await r.json(); const b = d?.data?.totalBalance;
|
const d = await r.json(); const b = d?.data?.totalBalance;
|
||||||
return { name: '硅基流动', model: 'BGE-M3 / BGE-Reranker', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://cloud.siliconflow.cn', note: '充值 + 赠送' };
|
return { name: '硅基流动', model: 'BGE-M3 / BGE-Reranker', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://cloud.siliconflow.cn', note: '充值 + 赠送' };
|
||||||
} catch { return { name: '硅基流动', model: 'Embedding/Rerank', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://cloud.siliconflow.cn', note: '查询失败' }; }
|
} catch { return { name: '硅基流动', model: 'Embedding/Rerank', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://cloud.siliconflow.cn', note: '查询失败' }; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user