@xuda.io/account_module 1.2.987 → 1.2.988
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +23 -17
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2401,25 +2401,31 @@ export const ts_contact = async function (contact_id) {
|
|
|
2401
2401
|
|
|
2402
2402
|
export const get_ai_usage = async function (req, job_id, headers) {
|
|
2403
2403
|
const { uid } = req;
|
|
2404
|
-
|
|
2404
|
+
try {
|
|
2405
|
+
const app_id = await get_account_default_project_id(uid);
|
|
2405
2406
|
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2407
|
+
const d = new Date();
|
|
2408
|
+
const month = Number(String(d.getMonth() + 1).padStart(2, '0')); // months are 0-based
|
|
2409
|
+
const year = d.getFullYear();
|
|
2409
2410
|
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2411
|
+
const ai_usage = await db_module.get_app_couch_view(app_id, 'ai_chat_usage', {
|
|
2412
|
+
startkey: [year, month, 0],
|
|
2413
|
+
endkey: [year, month, 99],
|
|
2414
|
+
reduce: true,
|
|
2415
|
+
group_level: 999,
|
|
2416
|
+
});
|
|
2417
|
+
console.log('ai_usage', ai_usage.rows);
|
|
2418
|
+
for (const row of ai_usage.rows) {
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
let membership_plan = 0;
|
|
2422
|
+
let ai_workspace_plan = 0;
|
|
2423
|
+
let contact_connection = 0;
|
|
2419
2424
|
|
|
2420
|
-
|
|
2421
|
-
let ai_workspace_plan = 0;
|
|
2422
|
-
let contact_connection = 0;
|
|
2425
|
+
let data = { credits: [{ membership_plan }, { ai_workspace_plan }, { contact_connection }], usage: { profile: [], projects: [] } };
|
|
2423
2426
|
|
|
2424
|
-
|
|
2427
|
+
return { code: -55, data };
|
|
2428
|
+
} catch (err) {
|
|
2429
|
+
return { code: -55, data: err.message };
|
|
2430
|
+
}
|
|
2425
2431
|
};
|