@xuda.io/account_module 1.2.1515 → 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 +12 -92
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3062,100 +3062,20 @@ export const save_picture_cache = async function (uid, docType, name, file, meta
|
|
|
3062
3062
|
return save_ret;
|
|
3063
3063
|
};
|
|
3064
3064
|
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
// return ret.docs[0].file;
|
|
3072
|
-
// }
|
|
3073
|
-
|
|
3074
|
-
// function findAnyThreeWords(str) {
|
|
3075
|
-
// // 1. Extract all words (letters + digits + underscore)
|
|
3076
|
-
// const words = str.match(/\b\w+\b/g) || [];
|
|
3077
|
-
|
|
3078
|
-
// // 2. If less than 3 words → no match
|
|
3079
|
-
// if (words.length < 3) return [];
|
|
3080
|
-
|
|
3081
|
-
// // 3. Generate all possible combinations of 3 different words
|
|
3082
|
-
// const result = [];
|
|
3083
|
-
|
|
3084
|
-
// for (let i = 0; i < words.length - 2; i++) {
|
|
3085
|
-
// for (let j = i + 1; j < words.length - 1; j++) {
|
|
3086
|
-
// for (let k = j + 1; k < words.length; k++) {
|
|
3087
|
-
// result.push([words[i], words[j], words[k]]);
|
|
3088
|
-
// }
|
|
3089
|
-
// }
|
|
3090
|
-
// }
|
|
3091
|
-
|
|
3092
|
-
// // Optional: format as strings in any order you like
|
|
3093
|
-
// return result.map((arr) => arr.join(' '));
|
|
3094
|
-
// }
|
|
3095
|
-
// if (name.split(' ').length < 3) return;
|
|
3096
|
-
// let file;
|
|
3097
|
-
// const words_combinations_arr = findAnyThreeWords(name);
|
|
3098
|
-
|
|
3099
|
-
// for await (const phrase of words_combinations_arr) {
|
|
3100
|
-
// const words_arr = phrase.split(' ');
|
|
3101
|
-
// 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` } }] };
|
|
3102
|
-
// const ret = await db_module.find_couch_query('xuda_cache', opt);
|
|
3103
|
-
// if (ret.docs.length) {
|
|
3104
|
-
// file = ret.docs[0].file;
|
|
3105
|
-
// break;
|
|
3106
|
-
// }
|
|
3107
|
-
// }
|
|
3108
|
-
// return file;
|
|
3109
|
-
// };
|
|
3110
|
-
|
|
3111
|
-
export const get_picture_cache = async function (uid, docType, name) {
|
|
3112
|
-
if (!name || typeof name !== 'string') return null;
|
|
3113
|
-
|
|
3114
|
-
const words = name
|
|
3115
|
-
.trim()
|
|
3116
|
-
.toLowerCase()
|
|
3117
|
-
.split(/\s+/)
|
|
3118
|
-
.filter((w) => w.length > 1); // ignore very short words
|
|
3119
|
-
|
|
3120
|
-
if (words.length < 3) {
|
|
3121
|
-
// Direct exact match for short names
|
|
3122
|
-
const ret = await db_module.find_couch_query('xuda_cache', {
|
|
3123
|
-
selector: { docType, name: name.trim() },
|
|
3124
|
-
limit: 1,
|
|
3125
|
-
});
|
|
3126
|
-
|
|
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) {
|
|
3127
3071
|
return ret.docs[0]?.file ?? null;
|
|
3128
3072
|
}
|
|
3129
3073
|
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
for (let k = j + 1; k < words.length && combinations.length < MAX_ATTEMPTS; k++) {
|
|
3137
|
-
combinations.push([words[i], words[j], words[k]]);
|
|
3138
|
-
}
|
|
3139
|
-
}
|
|
3140
|
-
}
|
|
3141
|
-
|
|
3142
|
-
for (const threeWords of combinations) {
|
|
3143
|
-
const query = {
|
|
3144
|
-
selector: {
|
|
3145
|
-
docType,
|
|
3146
|
-
$and: threeWords.map((word) => ({
|
|
3147
|
-
name: { $regex: `(?i)\\b${word}\\b` },
|
|
3148
|
-
})),
|
|
3149
|
-
},
|
|
3150
|
-
limit: 1,
|
|
3151
|
-
};
|
|
3152
|
-
|
|
3153
|
-
const ret = await db_module.find_couch_query('xuda_cache', query);
|
|
3154
|
-
|
|
3155
|
-
if (ret.docs.length > 0) {
|
|
3156
|
-
return ret.docs[0].file;
|
|
3157
|
-
}
|
|
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;
|
|
3158
3080
|
}
|
|
3159
|
-
|
|
3160
|
-
return null;
|
|
3161
3081
|
};
|