From 08cfd188e74fc7832ba2e0829f36a8b4d5c4bf6f Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 9 May 2023 23:56:37 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=B4=A6=E5=8D=95?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E6=97=A5=E6=9C=9F=20#187?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 24 ++++++++++++++++-------- dist/timestamp | 2 +- src/openai.js | 19 +++++++++++++------ 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 5fe4bedf..21203ff6 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "311c627", "timestamp": 1682221130} +{"sha": "60ca629", "timestamp": 1683647702} diff --git a/dist/index.js b/dist/index.js index fb7f9e1c..e543a977 100644 --- a/dist/index.js +++ b/dist/index.js @@ -43,9 +43,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1682221130, + BUILD_TIMESTAMP: 1683647702, // 当前版本 commit id - BUILD_VERSION: "311c627", + BUILD_VERSION: "60ca629", /** * @type {I18n} */ @@ -890,12 +890,20 @@ async function requestImageFromOpenAI(prompt, context) { async function requestBill(context) { const apiUrl = ENV.OPENAI_API_DOMAIN; const key = context.openAIKeyFromContext(); - const date = /* @__PURE__ */ new Date(); - const year = date.getFullYear(); - const month = (date.getMonth() + 1).toString().padStart(2, "0"); - const day = date.getDate().toString().padStart(2, "0"); - const endDate = `${year}-${month}-${day}`; - const startDate = `${year}-${month}-01`; + const date2Cmp = (date) => { + const year = date.getFullYear(); + const month = (date.getMonth() + 1).toString().padStart(2, "0"); + const day = date.getDate().toString().padStart(2, "0"); + return { + year, + month, + day + }; + }; + const start = date2Cmp(/* @__PURE__ */ new Date()); + const startDate = `${start.year}-${start.month}-01`; + const end = date2Cmp(new Date(Date.now() + 24 * 60 * 60 * 1e3)); + const endDate = `${end.year}-${end.month}-${end.day}`; const urlSub = `${apiUrl}/v1/dashboard/billing/subscription`; const urlUsage = `${apiUrl}/v1/dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`; const headers = { diff --git a/dist/timestamp b/dist/timestamp index 41b007c1..d1389c32 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1682221130 +1683647702 diff --git a/src/openai.js b/src/openai.js index 5bf3920a..a96d58c6 100644 --- a/src/openai.js +++ b/src/openai.js @@ -131,12 +131,19 @@ export async function requestBill(context) { const apiUrl = ENV.OPENAI_API_DOMAIN; const key = context.openAIKeyFromContext(); - const date = new Date(); - const year = date.getFullYear(); - const month = (date.getMonth() + 1).toString().padStart(2, '0'); - const day = date.getDate().toString().padStart(2, '0'); - const endDate = `${year}-${month}-${day}`; - const startDate = `${year}-${month}-01`; + const date2Cmp = (date) => { + const year = date.getFullYear(); + const month = (date.getMonth() + 1).toString().padStart(2, '0'); + const day = date.getDate().toString().padStart(2, '0'); + return { + year, month, day, + }; + }; + + const start = date2Cmp(new Date()); + const startDate = `${start.year}-${start.month}-01`; + const end = date2Cmp(new Date(Date.now() + 24 * 60 * 60 * 1000)); + const endDate = `${end.year}-${end.month}-${end.day}`; const urlSub = `${apiUrl}/v1/dashboard/billing/subscription`; const urlUsage = `${apiUrl}/v1/dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`;