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