@xuda.io/ai_module 1.1.4351 → 1.1.4353

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.
Files changed (2) hide show
  1. package/index.mjs +15 -8
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -6735,6 +6735,10 @@ export const is_business_contact = async function (uid, email, name, subject, bo
6735
6735
  };
6736
6736
 
6737
6737
  const get_profile_image = async function (uid, account_type = 'business', name, facts = {}, account_profile_info) {
6738
+ const tempDir = os.tmpdir();
6739
+ const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
6740
+ const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`);
6741
+
6738
6742
  function normalizeFilename(name) {
6739
6743
  return name
6740
6744
  .toLowerCase() // lowercase
@@ -6744,7 +6748,7 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6744
6748
  .replace(/^_+|_+$/g, ''); // trim leading/trailing underscores
6745
6749
  }
6746
6750
 
6747
- let prompt, factual_prompt, originalname, factual_image_mode, imageBase64;
6751
+ let prompt, factual_prompt, originalname, factual_image_mode, imageBase64, image_blob, file;
6748
6752
 
6749
6753
  switch (account_type) {
6750
6754
  case 'personal': {
@@ -6786,17 +6790,17 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6786
6790
  try {
6787
6791
  // first attempt
6788
6792
  let url = await get_url();
6789
- if (!url.substr(0, 7, 'https://')) {
6793
+ if (url.substr(0, 8) !== 'https://') {
6790
6794
  // second attempt
6791
6795
  url = await get_url();
6792
- if (!url.substr(0, 7, 'https://')) {
6796
+ if (url.substr(0, 8) !== 'https://') {
6793
6797
  factual_image_mode = true;
6794
6798
  }
6795
6799
  } else {
6796
6800
  // success
6797
- let file;
6801
+
6798
6802
  try {
6799
- file = await get_image_blob_from_downloaded_image(url);
6803
+ image_blob = await get_image_blob_from_downloaded_image(url);
6800
6804
  } catch (err) {
6801
6805
  if (!err.message.includes('Failed to fetch image URL')) {
6802
6806
  console.error(err);
@@ -6815,7 +6819,7 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6815
6819
  `;
6816
6820
  const image_response = await client.images.edit({
6817
6821
  model,
6818
- image: file.image_blob, //logo
6822
+ image: image_blob,
6819
6823
  prompt,
6820
6824
  background: 'transparent',
6821
6825
  });
@@ -6823,7 +6827,7 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6823
6827
  imageBase64 = await normalizeBase64To1024(image_response.data[0].b64_json);
6824
6828
  }
6825
6829
  const outputBuffer = Buffer.from(imageBase64, 'base64');
6826
- const outputPath = file.tempOutputPath;
6830
+ const outputPath = tempOutputPath;
6827
6831
  await fs.promises.writeFile(outputPath, outputBuffer);
6828
6832
 
6829
6833
  console.log('Success! Saved →', outputPath);
@@ -6955,7 +6959,10 @@ const get_image_blob_from_downloaded_image = async function (url) {
6955
6959
  return { is_transparent: img_ret.is_transparent, image_blob: blob };
6956
6960
  }),
6957
6961
  );
6958
- return { image_blob: images[0].image_blob, is_transparent: images[0].is_transparent, tempOutputPath };
6962
+
6963
+ return images[0].image_blob;
6964
+ // return { image_blob: images[0].image_blob, is_transparent: images[0].is_transparent, tempOutputPath };
6965
+
6959
6966
  // } catch (err) {
6960
6967
  // console.error(err);
6961
6968
  // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4351",
3
+ "version": "1.1.4353",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",