From c0e2c218f65a4afea18bd46f5fedaae4d7236e52 Mon Sep 17 00:00:00 2001 From: Dooy Date: Sun, 24 Dec 2023 11:38:16 +0800 Subject: [PATCH] 2.13.3 --- changlog.md | 3 +++ package.json | 2 +- src/api/openapi.ts | 33 ++++++++++++++++++++++++- src/components/common/Setting/About.vue | 24 ++++++++++++++---- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/changlog.md b/changlog.md index 681464b80..68f04858f 100644 --- a/changlog.md +++ b/changlog.md @@ -1,5 +1,8 @@ # 功能升级日志 +## 2.13.3 +- 😄 更新: 更新本月使用量、余额的请求方式 + ## 2.13.2 - 🐞 修复: midjourney 刷新错误 - ✅ 新增: tts whisper 界面支持 diff --git a/package.json b/package.json index 8bf5c80f2..0f71357ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-web-midjourney-proxy", - "version": "2.13.2", + "version": "2.13.3", "private": false, "description": "ChatGPT Web Midjourney Proxy", "author": "Dooy ", diff --git a/src/api/openapi.ts b/src/api/openapi.ts index 8565dda15..8039fe813 100644 --- a/src/api/openapi.ts +++ b/src/api/openapi.ts @@ -226,4 +226,35 @@ export const bolbObj= ( blob:Blob )=>{ player.load(); }) -} \ No newline at end of file +} + +function formatDate(): string[] { + const today = new Date() + const year = today.getFullYear() + const month = today.getMonth() + 1 + const lastDay = new Date(year, month, 0) + const formattedFirstDay = `${year}-${month.toString().padStart(2, '0')}-01` + const formattedLastDay = `${year}-${month.toString().padStart(2, '0')}-${lastDay.getDate().toString().padStart(2, '0')}` + return [formattedFirstDay, formattedLastDay] +} + +// + +export const gptUsage=async ()=>{ + + // fetch(getUrl(url), opt ) + // .then(d=>d.json().then(d=> resolve(d)) + // .catch(e=>reject(e))) + // .catch(e=>reject(e)) + const [startDate, endDate] = formatDate(); + const urlUsage = `/v1/dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}` + const usageData = await gptFetch(urlUsage); + const billData = await gptFetch('/v1/dashboard/billing/subscription'); + + const usage = Math.round(usageData.total_usage) / 100 + mlog('gpt', usage , billData ); + //remaining = subscriptionData.system_hard_limit_usd - totalUsage; + return {usage,remaining:Math.round(billData.system_hard_limit_usd- usageData.total_usage ) / 100 } ; + +} + diff --git a/src/components/common/Setting/About.vue b/src/components/common/Setting/About.vue index 3d3a8527b..10c1ad019 100644 --- a/src/components/common/Setting/About.vue +++ b/src/components/common/Setting/About.vue @@ -4,6 +4,7 @@ import { NSpin } from 'naive-ui' import pkg from '../../../../package.json' import { fetchChatConfig ,getLastVersion} from '@/api' import { useAuthStore } from '@/store' +import { gptUsage } from "@/api"; interface ConfigState { timeoutMs?: number @@ -12,6 +13,7 @@ interface ConfigState { socksProxy?: string httpsProxy?: string usage?: string + remaining?: string } const authStore = useAuthStore() @@ -26,8 +28,19 @@ const isChatGPTAPI = computed(() => !!authStore.isChatGPTAPI) async function fetchConfig() { try { loading.value = true - const { data } = await fetchChatConfig() - config.value = data + // const { data } = await fetchChatConfig() + // config.value = data + + + const dd= await gptUsage(); + config.value= {usage:dd.usage?`${dd.usage}`:'-' + ,remaining:dd.remaining?`${dd.remaining}`:'-' + , "apiModel": "ChatGPTAPI", + "reverseProxy": "-", + "timeoutMs": 100000, + "socksProxy": "-", + "httpsProxy": "-", } ; + } finally { loading.value = false @@ -93,9 +106,10 @@ const isShow = computed(()=>{

{{ $t("setting.reverseProxy") }}:{{ config?.reverseProxy ?? '-' }}

-

{{ $t("setting.timeout") }}:{{ config?.timeoutMs ?? '-' }}

-

{{ $t("setting.socks") }}:{{ config?.socksProxy ?? '-' }}

-

{{ $t("setting.httpsProxy") }}:{{ config?.httpsProxy ?? '-' }}

+

余额:{{ config?.remaining ?? '-' }}

+ +