Skip to content

Commit

Permalink
Merge pull request #188 from TBXark/dev
Browse files Browse the repository at this point in the history
fix: bill date range
  • Loading branch information
TBXark authored May 10, 2023
2 parents 81072a9 + 08cfd18 commit ca467a5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@
如果使用openai期间需要绑卡可以使用我的onekey的邀请码: https://card.onekey.so/?i=QO19EC 如果有其他问题可以加群交流。



## 特别鸣谢

![https://www.jetbrains.com/?from=tbxark](https://user-images.githubusercontent.com/9513891/236592683-1ea579cf-08ff-4703-b313-db038f62bab0.svg)

感谢 [JetBrains](https://www.jetbrains.com/?from=tbxark) 提供的开源开发许可证。



## 贡献者

这个项目存在是因为所有贡献者的帮助。[贡献](https://github.com/tbxark/ChatGPT-Telegram-Workers/graphs/contributors).
Expand Down
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 ca467a5

Please sign in to comment.