@xuda.io/account_module 1.2.1514 → 1.2.1516
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 +16 -94
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2198,6 +2198,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2198
2198
|
if (!contact_obj.profile_avatar) {
|
|
2199
2199
|
const cache = await get_picture_cache(uid, 'profile_avatar', contact_obj.email, contact_obj.name);
|
|
2200
2200
|
let file_ret = { code: 1, data: cache };
|
|
2201
|
+
|
|
2201
2202
|
if (!cache) {
|
|
2202
2203
|
file_ret = await ai_module.get_profile_avatar(
|
|
2203
2204
|
contact_obj.profile_picture,
|
|
@@ -2214,6 +2215,8 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2214
2215
|
job_id,
|
|
2215
2216
|
headers,
|
|
2216
2217
|
);
|
|
2218
|
+
save_picture_cache(uid, 'profile_avatar', contact_obj.name, file_ret.data, { account_type: contact_obj.account_type, type: 'contact' });
|
|
2219
|
+
save_picture_cache(uid, 'profile_avatar', contact_obj.email, file_ret.data, { account_type: contact_obj.account_type, type: 'contact' });
|
|
2217
2220
|
}
|
|
2218
2221
|
if (file_ret.code < 0) {
|
|
2219
2222
|
throw new Error(file_ret.data);
|
|
@@ -2223,8 +2226,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2223
2226
|
contact_obj = contact_obj3;
|
|
2224
2227
|
contact_obj.profile_avatar_obj = file_ret.data;
|
|
2225
2228
|
contact_obj.profile_avatar = contact_obj.profile_avatar_obj.file_url;
|
|
2226
|
-
|
|
2227
|
-
save_picture_cache(uid, 'profile_avatar', contact_obj.email, contact_obj.profile_avatar_obj, { account_type: contact_obj.account_type, type: 'contact' });
|
|
2229
|
+
|
|
2228
2230
|
const contact_save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, contact_obj);
|
|
2229
2231
|
await update_contact_profile_picture_status(uid, contact_id, 3);
|
|
2230
2232
|
}
|
|
@@ -3060,100 +3062,20 @@ export const save_picture_cache = async function (uid, docType, name, file, meta
|
|
|
3060
3062
|
return save_ret;
|
|
3061
3063
|
};
|
|
3062
3064
|
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
// return ret.docs[0].file;
|
|
3070
|
-
// }
|
|
3071
|
-
|
|
3072
|
-
// function findAnyThreeWords(str) {
|
|
3073
|
-
// // 1. Extract all words (letters + digits + underscore)
|
|
3074
|
-
// const words = str.match(/\b\w+\b/g) || [];
|
|
3075
|
-
|
|
3076
|
-
// // 2. If less than 3 words → no match
|
|
3077
|
-
// if (words.length < 3) return [];
|
|
3078
|
-
|
|
3079
|
-
// // 3. Generate all possible combinations of 3 different words
|
|
3080
|
-
// const result = [];
|
|
3081
|
-
|
|
3082
|
-
// for (let i = 0; i < words.length - 2; i++) {
|
|
3083
|
-
// for (let j = i + 1; j < words.length - 1; j++) {
|
|
3084
|
-
// for (let k = j + 1; k < words.length; k++) {
|
|
3085
|
-
// result.push([words[i], words[j], words[k]]);
|
|
3086
|
-
// }
|
|
3087
|
-
// }
|
|
3088
|
-
// }
|
|
3089
|
-
|
|
3090
|
-
// // Optional: format as strings in any order you like
|
|
3091
|
-
// return result.map((arr) => arr.join(' '));
|
|
3092
|
-
// }
|
|
3093
|
-
// if (name.split(' ').length < 3) return;
|
|
3094
|
-
// let file;
|
|
3095
|
-
// const words_combinations_arr = findAnyThreeWords(name);
|
|
3096
|
-
|
|
3097
|
-
// for await (const phrase of words_combinations_arr) {
|
|
3098
|
-
// const words_arr = phrase.split(' ');
|
|
3099
|
-
// opt.selector = { docType, $and: [{ name: { $regex: `(?i)\\b${words_arr[0]}\\b` } }, { name: { $regex: `(?i)\\b${words_arr[1]}\\b` } }, { name: { $regex: `(?i)\\b${words_arr[2]}\\b` } }] };
|
|
3100
|
-
// const ret = await db_module.find_couch_query('xuda_cache', opt);
|
|
3101
|
-
// if (ret.docs.length) {
|
|
3102
|
-
// file = ret.docs[0].file;
|
|
3103
|
-
// break;
|
|
3104
|
-
// }
|
|
3105
|
-
// }
|
|
3106
|
-
// return file;
|
|
3107
|
-
// };
|
|
3108
|
-
|
|
3109
|
-
export const get_picture_cache = async function (uid, docType, name) {
|
|
3110
|
-
if (!name || typeof name !== 'string') return null;
|
|
3111
|
-
|
|
3112
|
-
const words = name
|
|
3113
|
-
.trim()
|
|
3114
|
-
.toLowerCase()
|
|
3115
|
-
.split(/\s+/)
|
|
3116
|
-
.filter((w) => w.length > 1); // ignore very short words
|
|
3117
|
-
|
|
3118
|
-
if (words.length < 3) {
|
|
3119
|
-
// Direct exact match for short names
|
|
3120
|
-
const ret = await db_module.find_couch_query('xuda_cache', {
|
|
3121
|
-
selector: { docType, name: name.trim() },
|
|
3122
|
-
limit: 1,
|
|
3123
|
-
});
|
|
3124
|
-
|
|
3065
|
+
export const get_picture_cache = async function (uid, docType, name, email) {
|
|
3066
|
+
let ret = await db_module.find_couch_query('xuda_cache', {
|
|
3067
|
+
selector: { docType, name: email.trim() },
|
|
3068
|
+
limit: 1,
|
|
3069
|
+
});
|
|
3070
|
+
if (ret.docs.length) {
|
|
3125
3071
|
return ret.docs[0]?.file ?? null;
|
|
3126
3072
|
}
|
|
3127
3073
|
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
for (let k = j + 1; k < words.length && combinations.length < MAX_ATTEMPTS; k++) {
|
|
3135
|
-
combinations.push([words[i], words[j], words[k]]);
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3138
|
-
}
|
|
3139
|
-
|
|
3140
|
-
for (const threeWords of combinations) {
|
|
3141
|
-
const query = {
|
|
3142
|
-
selector: {
|
|
3143
|
-
docType,
|
|
3144
|
-
$and: threeWords.map((word) => ({
|
|
3145
|
-
name: { $regex: `(?i)\\b${word}\\b` },
|
|
3146
|
-
})),
|
|
3147
|
-
},
|
|
3148
|
-
limit: 1,
|
|
3149
|
-
};
|
|
3150
|
-
|
|
3151
|
-
const ret = await db_module.find_couch_query('xuda_cache', query);
|
|
3152
|
-
|
|
3153
|
-
if (ret.docs.length > 0) {
|
|
3154
|
-
return ret.docs[0].file;
|
|
3155
|
-
}
|
|
3074
|
+
ret = await db_module.find_couch_query('xuda_cache', {
|
|
3075
|
+
selector: { docType, name: name.trim() },
|
|
3076
|
+
limit: 1,
|
|
3077
|
+
});
|
|
3078
|
+
if (ret.docs.length) {
|
|
3079
|
+
return ret.docs[0]?.file ?? null;
|
|
3156
3080
|
}
|
|
3157
|
-
|
|
3158
|
-
return null;
|
|
3159
3081
|
};
|