@xuda.io/account_module 1.2.2259 → 1.2.2261

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.
@@ -0,0 +1,56 @@
1
+ // download-models.js
2
+ const https = require('https');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const models = ['u2net.onnx', 'u2net.onnx.bin', 'u2net.onnx.wasm'];
7
+
8
+ const baseUrl = 'https://static.imgly.com/background-removal/models/medium/';
9
+ const outputDir = '/var/xuda/assets/imgly-bg';
10
+
11
+ // Create directory if it doesn't exist
12
+ if (!fs.existsSync(outputDir)) {
13
+ fs.mkdirSync(outputDir, { recursive: true });
14
+ }
15
+
16
+ async function downloadFile(url, filepath) {
17
+ return new Promise((resolve, reject) => {
18
+ const file = fs.createWriteStream(filepath);
19
+ https
20
+ .get(url, (response) => {
21
+ if (response.statusCode === 200) {
22
+ response.pipe(file);
23
+ file.on('finish', () => {
24
+ file.close();
25
+ console.log(`Downloaded: ${path.basename(filepath)}`);
26
+ resolve();
27
+ });
28
+ } else {
29
+ reject(new Error(`HTTP ${response.statusCode}: ${url}`));
30
+ }
31
+ })
32
+ .on('error', (err) => {
33
+ fs.unlink(filepath, () => {}); // Delete partial file
34
+ reject(err);
35
+ });
36
+ });
37
+ }
38
+
39
+ async function downloadAll() {
40
+ console.log('Downloading models to:', outputDir);
41
+
42
+ for (const model of models) {
43
+ const url = baseUrl + model;
44
+ const filepath = path.join(outputDir, model);
45
+
46
+ try {
47
+ await downloadFile(url, filepath);
48
+ } catch (error) {
49
+ console.error(`Failed to download ${model}:`, error.message);
50
+ }
51
+ }
52
+
53
+ console.log('Download complete!');
54
+ }
55
+
56
+ downloadAll();
@@ -0,0 +1,56 @@
1
+ // download-models.js
2
+ const https = require('https');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const models = ['u2net.onnx', 'u2net.onnx.bin', 'u2net.onnx.wasm'];
7
+
8
+ const baseUrl = 'https://static.imgly.com/background-removal/models/medium/';
9
+ const outputDir = '/var/xuda/assets/imgly-bg';
10
+
11
+ // Create directory if it doesn't exist
12
+ if (!fs.existsSync(outputDir)) {
13
+ fs.mkdirSync(outputDir, { recursive: true });
14
+ }
15
+
16
+ async function downloadFile(url, filepath) {
17
+ return new Promise((resolve, reject) => {
18
+ const file = fs.createWriteStream(filepath);
19
+ https
20
+ .get(url, (response) => {
21
+ if (response.statusCode === 200) {
22
+ response.pipe(file);
23
+ file.on('finish', () => {
24
+ file.close();
25
+ console.log(`Downloaded: ${path.basename(filepath)}`);
26
+ resolve();
27
+ });
28
+ } else {
29
+ reject(new Error(`HTTP ${response.statusCode}: ${url}`));
30
+ }
31
+ })
32
+ .on('error', (err) => {
33
+ fs.unlink(filepath, () => {}); // Delete partial file
34
+ reject(err);
35
+ });
36
+ });
37
+ }
38
+
39
+ async function downloadAll() {
40
+ console.log('Downloading models to:', outputDir);
41
+
42
+ for (const model of models) {
43
+ const url = baseUrl + model;
44
+ const filepath = path.join(outputDir, model);
45
+
46
+ try {
47
+ await downloadFile(url, filepath);
48
+ } catch (error) {
49
+ console.error(`Failed to download ${model}:`, error.message);
50
+ }
51
+ }
52
+
53
+ console.log('Download complete!');
54
+ }
55
+
56
+ downloadAll();
@@ -0,0 +1,21 @@
1
+ const db_module = await import(`${module_path}/db_module/index.mjs`);
2
+
3
+ export const get_active_account_profile_info = async function (uid, profile_id) {
4
+ try {
5
+ const acc_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
6
+
7
+ let active_account_profile_id = profile_id || acc_obj.account_info.active_account_profile_id;
8
+
9
+ const account_profile_obj = await db_module.get_app_couch_doc_native(acc_obj.account_project_id, active_account_profile_id);
10
+ if (account_profile_obj.share_item_id) {
11
+ // set the original profile id if shared
12
+ active_account_profile_id = account_profile_obj.share_item_id;
13
+ }
14
+ const app_id = await get_account_default_project_id(account_profile_obj.shared_from_uid || account_profile_obj.uid);
15
+
16
+ return { uid: account_profile_obj.shared_from_uid || uid, account_profile_id: active_account_profile_id, app_id, is_main: active_account_profile_id === acc_obj.account_profile_id, account_profile_obj };
17
+ } catch (err) {
18
+ console.error('**** get_active_account_profile_info', err);
19
+ debugger;
20
+ }
21
+ };
@@ -0,0 +1,126 @@
1
+ export const get_contact_info = async function (uid, contact_doc, _id) {
2
+ let doc = contact_doc;
3
+ if (_id) {
4
+ doc = await get_contact(uid, _id);
5
+ }
6
+
7
+ delete doc.metadata;
8
+ delete doc.profile_avatar_obj;
9
+ delete doc.profile_picture_obj;
10
+ delete doc.bio;
11
+
12
+ const chat_conversation_count = async function () {
13
+ const account_profile_info = await get_active_account_profile_info(uid);
14
+
15
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
16
+ reduce: true,
17
+ group_level: 1,
18
+
19
+ startkey: [doc._id, ''],
20
+ endkey: [doc._id, 'zzzzzz'],
21
+ });
22
+
23
+ return counts_ret?.rows?.[0]?.value || 0;
24
+ };
25
+ const chat_conversation_read = async function () {
26
+ const account_profile_info = await get_active_account_profile_info(uid);
27
+
28
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
29
+ reduce: true,
30
+ group_level: 2,
31
+
32
+ startkey: [uid, doc._id, ''],
33
+ endkey: [uid, doc._id, 'zzzzzz'],
34
+ });
35
+
36
+ return counts_ret?.rows?.[0]?.value || 0;
37
+ };
38
+
39
+ doc.notifications = 0;
40
+ if (doc.contact_uid) {
41
+ const account_info_ret = await get_account_name({ uid_query: doc.contact_uid });
42
+ if (account_info_ret.code < 0) {
43
+ return; // throw new Error(`account ${contact_uid} not found`);
44
+ }
45
+
46
+ doc.profile_avatar = account_info_ret.data.profile_avatar;
47
+
48
+ //membership_plan
49
+ // doc.name = `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
50
+ doc.name = account_info_ret.data?.account_type === 'business' ? account_info_ret.data.business_name : `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
51
+
52
+ if (account_info_ret.data.phone_number) {
53
+ try {
54
+ doc.phone_number = formatPhoneWithFlag(account_info_ret.data.phone_number, account_info_ret.data.country);
55
+ } catch (err) {
56
+ // console.error(err);
57
+ doc.phone_number = account_info_ret.data.phone_number;
58
+ }
59
+ }
60
+
61
+ if (doc.team_req_id) {
62
+ try {
63
+ const req_doc = await db_module.get_couch_doc_native('xuda_team', doc.team_req_id);
64
+ doc.connection_stat = req_doc.team_req_stat;
65
+ doc.connection_type = req_doc.access_type;
66
+ doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
67
+ doc.connection_contact_id = req_doc.team_req_from_contact_id === doc._id ? req_doc.team_req_to_contact_id : req_doc.team_req_from_contact_id;
68
+ if (doc.connection_type === 'contact_connection') {
69
+ doc.friend_since = req_doc.team_req_date;
70
+ }
71
+ if (doc.connection_type === 'account_profile') {
72
+ try {
73
+ const app_id = await get_account_default_project_id(uid);
74
+ const account_profile_doc = await db_module.get_app_couch_doc_native(app_id, req_doc.share_item_id);
75
+ doc.account_profile = account_profile_doc;
76
+ } catch (error) {}
77
+ }
78
+ } catch (err) {
79
+ if (err.message === 'deleted') {
80
+ try {
81
+ let contact_doc = await get_contact(uid, doc._id);
82
+ contact_doc.team_req_id = '';
83
+ await save_contact(uid, contact_doc);
84
+ } catch (error) {}
85
+ }
86
+ doc.connection_stat = 0;
87
+ }
88
+ }
89
+
90
+ doc.avatar_source = account_info_ret.data.avatar_source;
91
+ // doc.icon_pattern = await get_contact_pattern(doc);
92
+ doc.username = account_info_ret.data.username;
93
+ doc.business_name = account_info_ret.data.business_name;
94
+ doc.address = account_info_ret.data.address;
95
+ doc.city = account_info_ret.data.city;
96
+ doc.state = account_info_ret.data.state;
97
+ doc.zip = account_info_ret.data.zip;
98
+ doc.account_type = account_info_ret.data.account_type;
99
+ doc.email = doc.email;
100
+ if (doc.connection_stat === 3) {
101
+ doc.online = account_info_ret.data.online;
102
+ }
103
+ } else {
104
+ doc.email = doc.email;
105
+ }
106
+
107
+ doc.business_has_person = doc?.business_has_person && doc?.person_info?.person_full_name !== 'Not available';
108
+ doc.icon_pattern = await get_contact_pattern(doc);
109
+
110
+ delete doc.account_type_info;
111
+ delete doc.person_info;
112
+ delete doc.business_info;
113
+
114
+ const contact_chat_conversation_count_ret = await chat_conversation_count();
115
+ const contact_chat_conversation_read_ret = await chat_conversation_read();
116
+
117
+ doc.interactions = contact_chat_conversation_count_ret;
118
+ doc.notifications = contact_chat_conversation_count_ret - contact_chat_conversation_read_ret;
119
+ doc.chats = doc.interactions;
120
+
121
+ doc.card_background = get_contact_background(doc);
122
+
123
+ doc.border = get_contact_border(doc);
124
+
125
+ return doc;
126
+ };