@xuda.io/account_module 1.2.1563 → 1.2.1565

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.
Files changed (2) hide show
  1. package/index.mjs +22 -0
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -3104,7 +3104,29 @@ export const record_ai_credit = async function (uid, credits = 0, source, detail
3104
3104
  };
3105
3105
  const save_ret = await db_module.save_couch_doc('xuda_billing', credit_doc);
3106
3106
  // console.log(save_ret);
3107
+ return save_ret;
3107
3108
  } catch (err) {
3108
3109
  console.error(err);
3110
+ return { code: -78, data: err.message };
3111
+ }
3112
+ };
3113
+
3114
+ export const add_ai_credits_to_active_accounts = async function () {
3115
+ let date = new Date();
3116
+
3117
+ let date_str = date.toLocaleDateString('en-US', {
3118
+ month: 'long',
3119
+ day: 'numeric',
3120
+ year: 'numeric',
3121
+ });
3122
+
3123
+ const active_accounts = await db_module.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account', last_free_daily_ai_credit_ts: { $lt: Date.now() - 1000 * 60 * 60 * 24 } }, limit: 99999 });
3124
+ for await (account_doc of active_accounts.docs) {
3125
+ const ret = await record_ai_credit('system', 1, 'daily credit', 'free daily credit ' + date_str, account_doc._id);
3126
+ if (ret.code > -1) {
3127
+ account_doc.last_free_daily_ai_credit_ts = Date.now();
3128
+ account_doc.last_free_daily_ai_credit_id = ret.data.id;
3129
+ const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
3130
+ }
3109
3131
  }
3110
3132
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.1563",
3
+ "version": "1.2.1565",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {