@xuda.io/ai_module 1.1.4419 → 1.1.4420
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 +53 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3359,7 +3359,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
|
|
|
3359
3359
|
case 'conversation': {
|
|
3360
3360
|
prompt = `create image: ${doc.title}`;
|
|
3361
3361
|
let images_arr;
|
|
3362
|
-
const cache = await
|
|
3362
|
+
const cache = await get_chat_picture_cache(uid, 'chat_thumbnail', doc.title);
|
|
3363
3363
|
images_arr = [cache];
|
|
3364
3364
|
if (!cache) {
|
|
3365
3365
|
images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
|
|
@@ -7005,3 +7005,55 @@ export const get_business_info = async function (uid, name, email, account_profi
|
|
|
7005
7005
|
console.error('Error in get_business_info:', error);
|
|
7006
7006
|
}
|
|
7007
7007
|
};
|
|
7008
|
+
|
|
7009
|
+
const get_chat_picture_cache = async function (uid, docType, name) {
|
|
7010
|
+
if (!name || typeof name !== 'string') return null;
|
|
7011
|
+
|
|
7012
|
+
const words = name
|
|
7013
|
+
.trim()
|
|
7014
|
+
.toLowerCase()
|
|
7015
|
+
.split(/\s+/)
|
|
7016
|
+
.filter((w) => w.length > 1); // ignore very short words
|
|
7017
|
+
|
|
7018
|
+
if (words.length < 3) {
|
|
7019
|
+
// Direct exact match for short names
|
|
7020
|
+
const ret = await db_module.find_couch_query('xuda_cache', {
|
|
7021
|
+
selector: { docType, name: name.trim() },
|
|
7022
|
+
limit: 1,
|
|
7023
|
+
});
|
|
7024
|
+
|
|
7025
|
+
return ret.docs[0]?.file ?? null;
|
|
7026
|
+
}
|
|
7027
|
+
|
|
7028
|
+
// Try combinations of 3 words — but **limit** the number of attempts
|
|
7029
|
+
const MAX_ATTEMPTS = 15; // prevent explosion on long names
|
|
7030
|
+
const combinations = [];
|
|
7031
|
+
|
|
7032
|
+
for (let i = 0; i < words.length - 2 && combinations.length < MAX_ATTEMPTS; i++) {
|
|
7033
|
+
for (let j = i + 1; j < words.length - 1 && combinations.length < MAX_ATTEMPTS; j++) {
|
|
7034
|
+
for (let k = j + 1; k < words.length && combinations.length < MAX_ATTEMPTS; k++) {
|
|
7035
|
+
combinations.push([words[i], words[j], words[k]]);
|
|
7036
|
+
}
|
|
7037
|
+
}
|
|
7038
|
+
}
|
|
7039
|
+
|
|
7040
|
+
for (const threeWords of combinations) {
|
|
7041
|
+
const query = {
|
|
7042
|
+
selector: {
|
|
7043
|
+
docType,
|
|
7044
|
+
$and: threeWords.map((word) => ({
|
|
7045
|
+
name: { $regex: `(?i)\\b${word}\\b` },
|
|
7046
|
+
})),
|
|
7047
|
+
},
|
|
7048
|
+
limit: 1,
|
|
7049
|
+
};
|
|
7050
|
+
|
|
7051
|
+
const ret = await db_module.find_couch_query('xuda_cache', query);
|
|
7052
|
+
|
|
7053
|
+
if (ret.docs.length > 0) {
|
|
7054
|
+
return ret.docs[0].file;
|
|
7055
|
+
}
|
|
7056
|
+
}
|
|
7057
|
+
|
|
7058
|
+
return null;
|
|
7059
|
+
};
|