Skip to content

Commit

Permalink
perf: 优化账单结束日期 #187
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed May 9, 2023
1 parent 60ca629 commit 08cfd18
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sha": "311c627", "timestamp": 1682221130}
{"sha": "60ca629", "timestamp": 1683647702}
24 changes: 16 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion dist/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1682221130
1683647702
19 changes: 13 additions & 6 deletions src/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit 08cfd18

Please sign in to comment.