@xuda.io/account_module 1.2.2248 → 1.2.2249
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 +121 -3
- package/index_ms.mjs +4 -0
- package/index_msa.mjs +4 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import _ from 'lodash';
|
|
3
4
|
// import { exec } from 'child_process';
|
|
4
5
|
// import util from 'util';
|
|
@@ -100,7 +101,8 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
100
101
|
account_info_changes_arr.push(key);
|
|
101
102
|
|
|
102
103
|
if (key === 'profile_picture') {
|
|
103
|
-
|
|
104
|
+
const current_profile_picture = account_obj.account_info?.profile_picture || '';
|
|
105
|
+
if (current_profile_picture.includes('googleusercontent')) {
|
|
104
106
|
account_obj.account_info['profile_picture_google'] = val;
|
|
105
107
|
} else {
|
|
106
108
|
//delete old profile picture
|
|
@@ -111,8 +113,14 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
const profile_avatar_obj = account_obj?.account_info?.profile_avatar_obj || '';
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
const profile_avatar_file = profile_avatar_obj?.data || profile_avatar_obj;
|
|
117
|
+
if (profile_avatar_file?.file_path && profile_avatar_file?.filename) {
|
|
118
|
+
drive_msa.delete_drive_files({ uid, drive_type: 'user', files_arr: [{ type: 'file', file_path: path.join(profile_avatar_file.file_path, profile_avatar_file.filename) }] });
|
|
119
|
+
} else if (profile_avatar_obj) {
|
|
120
|
+
console.warn('Skipping profile avatar cleanup, missing file path data', {
|
|
121
|
+
uid,
|
|
122
|
+
profile_avatar_obj,
|
|
123
|
+
});
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
|
|
@@ -559,6 +567,116 @@ export const get_account_info = async function (req) {
|
|
|
559
567
|
});
|
|
560
568
|
};
|
|
561
569
|
|
|
570
|
+
const TIPS_FILE_PATH = path.join(process.env.XUDA_HOME, 'dist', 'tips', 'tips.json');
|
|
571
|
+
let _did_you_know_tips_cache = null;
|
|
572
|
+
let _did_you_know_tips_cache_mtime = 0;
|
|
573
|
+
|
|
574
|
+
const load_did_you_know_tips = function () {
|
|
575
|
+
try {
|
|
576
|
+
const stat = fs.statSync(TIPS_FILE_PATH);
|
|
577
|
+
if (_did_you_know_tips_cache && stat.mtimeMs === _did_you_know_tips_cache_mtime) {
|
|
578
|
+
return _did_you_know_tips_cache;
|
|
579
|
+
}
|
|
580
|
+
const raw = fs.readFileSync(TIPS_FILE_PATH, 'utf8');
|
|
581
|
+
const parsed = JSON.parse(raw);
|
|
582
|
+
_did_you_know_tips_cache = Array.isArray(parsed) ? parsed : parsed.tips || [];
|
|
583
|
+
_did_you_know_tips_cache_mtime = stat.mtimeMs;
|
|
584
|
+
return _did_you_know_tips_cache;
|
|
585
|
+
} catch (err) {
|
|
586
|
+
console.error('load_did_you_know_tips failed:', err.message);
|
|
587
|
+
return [];
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
const tip_requirement_passes = function (tip, account_doc) {
|
|
592
|
+
const r = tip?.requires;
|
|
593
|
+
if (!r) return true;
|
|
594
|
+
const account_info = account_doc?.account_info || {};
|
|
595
|
+
switch (r) {
|
|
596
|
+
case 'profile_incomplete': {
|
|
597
|
+
const required = ['first_name', 'last_name', 'bio', 'country', 'profile_picture'];
|
|
598
|
+
return required.some((k) => !account_info[k]);
|
|
599
|
+
}
|
|
600
|
+
case 'free_plan':
|
|
601
|
+
return account_doc?.membership_plan === 'free';
|
|
602
|
+
case 'no_support_plan':
|
|
603
|
+
return !account_doc?.support_plan || account_doc.support_plan === 'none' || account_doc.support_plan === 'free';
|
|
604
|
+
case 'email_not_connected':
|
|
605
|
+
return !account_doc?.connected_emails?.length && !account_doc?.email_oauth?.connected;
|
|
606
|
+
default:
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
export const did_you_know_tips = async function (req, job_id, headers) {
|
|
612
|
+
const { uid, action = 'next', tip_id } = req || {};
|
|
613
|
+
try {
|
|
614
|
+
if (!uid) throw new Error('uid required');
|
|
615
|
+
|
|
616
|
+
const account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
|
|
617
|
+
if (!account_doc) throw new Error('account not found');
|
|
618
|
+
|
|
619
|
+
account_doc.did_you_know_tips = account_doc.did_you_know_tips || { offered: [], accepted: [], dismissed: [], current_offer: null };
|
|
620
|
+
const tips_state = account_doc.did_you_know_tips;
|
|
621
|
+
|
|
622
|
+
if (action === 'accept' || action === 'dismiss') {
|
|
623
|
+
const target_id = tip_id || tips_state.current_offer?.id;
|
|
624
|
+
if (!target_id) throw new Error('tip_id required');
|
|
625
|
+
|
|
626
|
+
const bucket = action === 'accept' ? tips_state.accepted : tips_state.dismissed;
|
|
627
|
+
if (!bucket.includes(target_id)) bucket.push(target_id);
|
|
628
|
+
|
|
629
|
+
if (tips_state.current_offer?.id === target_id) {
|
|
630
|
+
tips_state.current_offer = null;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
account_doc.ts = Date.now();
|
|
634
|
+
const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
|
|
635
|
+
if (save_ret.code < 0) throw new Error(save_ret.data);
|
|
636
|
+
return { code: 1, data: { action, tip_id: target_id, tips_state } };
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const all_tips = load_did_you_know_tips();
|
|
640
|
+
if (!all_tips.length) {
|
|
641
|
+
return { code: 1, data: { offer: null, message: 'no tips available' } };
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
const seen = new Set([...(tips_state.accepted || []), ...(tips_state.dismissed || [])]);
|
|
645
|
+
let candidates = all_tips.filter((t) => !seen.has(t.id) && tip_requirement_passes(t, account_doc));
|
|
646
|
+
|
|
647
|
+
if (!candidates.length) {
|
|
648
|
+
candidates = all_tips.filter((t) => !tips_state.accepted?.includes(t.id) && tip_requirement_passes(t, account_doc));
|
|
649
|
+
}
|
|
650
|
+
if (!candidates.length) {
|
|
651
|
+
return { code: 1, data: { offer: null, message: 'no more tips available' } };
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const not_yet_offered = candidates.filter((t) => !tips_state.offered?.includes(t.id));
|
|
655
|
+
const pool = not_yet_offered.length ? not_yet_offered : candidates;
|
|
656
|
+
const picked = pool[Math.floor(Math.random() * pool.length)];
|
|
657
|
+
|
|
658
|
+
const offer = {
|
|
659
|
+
id: picked.id,
|
|
660
|
+
title: picked.title,
|
|
661
|
+
text: picked.text,
|
|
662
|
+
image: picked.image,
|
|
663
|
+
url: picked.url,
|
|
664
|
+
ts: Date.now(),
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
if (!tips_state.offered.includes(picked.id)) tips_state.offered.push(picked.id);
|
|
668
|
+
tips_state.current_offer = offer;
|
|
669
|
+
|
|
670
|
+
account_doc.ts = Date.now();
|
|
671
|
+
const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
|
|
672
|
+
if (save_ret.code < 0) throw new Error(save_ret.data);
|
|
673
|
+
|
|
674
|
+
return { code: 1, data: { offer } };
|
|
675
|
+
} catch (err) {
|
|
676
|
+
return { code: -45, data: err.message };
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
|
|
562
680
|
export const get_active_account_profile_info = async function (uid, profile_id) {
|
|
563
681
|
try {
|
|
564
682
|
const acc_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
|
package/index_ms.mjs
CHANGED
|
@@ -25,6 +25,10 @@ export const update_account_preferences = async function (...args) {
|
|
|
25
25
|
return await broker.send_to_queue("update_account_preferences", ...args);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
export const did_you_know_tips = async function (...args) {
|
|
29
|
+
return await broker.send_to_queue("did_you_know_tips", ...args);
|
|
30
|
+
};
|
|
31
|
+
|
|
28
32
|
export const save_admin_presets = async function (...args) {
|
|
29
33
|
return await broker.send_to_queue("save_admin_presets", ...args);
|
|
30
34
|
};
|
package/index_msa.mjs
CHANGED
|
@@ -25,6 +25,10 @@ export const update_account_preferences = function (...args) {
|
|
|
25
25
|
broker.send_to_queue_async("update_account_preferences", ...args);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
export const did_you_know_tips = function (...args) {
|
|
29
|
+
broker.send_to_queue_async("did_you_know_tips", ...args);
|
|
30
|
+
};
|
|
31
|
+
|
|
28
32
|
export const save_admin_presets = function (...args) {
|
|
29
33
|
broker.send_to_queue_async("save_admin_presets", ...args);
|
|
30
34
|
};
|