@xuda.io/ai_module 1.1.4418 → 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 +57 -3
- 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);
|
|
@@ -5667,7 +5667,7 @@ const create_and_upload_image_to_drive = async function (drive_type, file_path,
|
|
|
5667
5667
|
};
|
|
5668
5668
|
|
|
5669
5669
|
export const create_avatar = async function (req, job_id, headers) {
|
|
5670
|
-
const { docType, uid, url, _id, name, account_type } = req;
|
|
5670
|
+
const { docType, uid, url, _id, name, account_type, metadata } = req;
|
|
5671
5671
|
try {
|
|
5672
5672
|
if (!['account', 'account_profile'].includes(docType)) {
|
|
5673
5673
|
throw new Error('invalid docType value');
|
|
@@ -5685,7 +5685,9 @@ export const create_avatar = async function (req, job_id, headers) {
|
|
|
5685
5685
|
|
|
5686
5686
|
const account_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
|
|
5687
5687
|
const account_info = account_obj.account_info;
|
|
5688
|
-
|
|
5688
|
+
if (!metadata) {
|
|
5689
|
+
metadata = account_info;
|
|
5690
|
+
}
|
|
5689
5691
|
|
|
5690
5692
|
return await get_profile_avatar(url, uid, null, account_profile_info, account_type, docType, _id, metadata, account_info, name, account_info.email, job_id, headers);
|
|
5691
5693
|
} catch (err) {
|
|
@@ -7003,3 +7005,55 @@ export const get_business_info = async function (uid, name, email, account_profi
|
|
|
7003
7005
|
console.error('Error in get_business_info:', error);
|
|
7004
7006
|
}
|
|
7005
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
|
+
};
|