@xuda.io/ai_module 1.1.4316 → 1.1.4318

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 +59 -38
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -5289,7 +5289,8 @@ setTimeout(async () => {
5289
5289
  // Location: 'https://xuda-bucket-dev.nyc3.digitaloceanspaces.com/dev.xuda.io/user/d39126e0e2c51ffbd1aad10709fc8335/cb7353fc-4788-49b7-8e73-f7f1be108b69_drv_d39126e0e2c51ffbd1aad10709fc8335_b92337f79e090a2f287bc3dc35d0033e.png',
5290
5290
  // },
5291
5291
  // });
5292
- ret = await get_business_logo(uid, 'bank of america', account_profile_info);
5292
+
5293
+ // ret = await get_business_logo(uid, 'bank of america', account_profile_info);
5293
5294
 
5294
5295
  console.log(ret);
5295
5296
  }, 1000);
@@ -6724,6 +6725,15 @@ export const is_business_contact = async function (uid, email, name, subject, bo
6724
6725
  };
6725
6726
 
6726
6727
  const get_business_logo = async function (uid, name, account_profile_info) {
6728
+ function normalizeFilename(name) {
6729
+ return name
6730
+ .toLowerCase() // lowercase
6731
+ .replace(/\s+/g, '_') // replace all spaces with single underscore
6732
+ .replace(/[^a-z0-9._-]/g, '') // remove anything that's not letter, number, dot, underscore, or hyphen
6733
+ .replace(/_+/g, '_') // collapse multiple underscores
6734
+ .replace(/^_+|_+$/g, ''); // trim leading/trailing underscores
6735
+ }
6736
+
6727
6737
  const get_url = async function () {
6728
6738
  const ret = await submit_chat_gpt_prompt({
6729
6739
  uid,
@@ -6768,7 +6778,7 @@ const get_business_logo = async function (uid, name, account_profile_info) {
6768
6778
  prompt,
6769
6779
  background: 'transparent',
6770
6780
  });
6771
- debugger;
6781
+
6772
6782
  let imageBase64 = await normalizeBase64To1024(logo_response.data[0].b64_json);
6773
6783
 
6774
6784
  const outputBuffer = Buffer.from(imageBase64, 'base64');
@@ -6778,6 +6788,15 @@ const get_business_logo = async function (uid, name, account_profile_info) {
6778
6788
  console.log('Success! Saved →', outputPath);
6779
6789
 
6780
6790
  console.log(file);
6791
+
6792
+ const file_obj = {
6793
+ originalname: normalizeFilename(name) + '_xu_logo.png',
6794
+ path: outputPath,
6795
+ mimetype: `application/png`,
6796
+ };
6797
+
6798
+ const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
6799
+
6781
6800
  record_chat_usage(uid, logo_response.usage.input_tokens, logo_response.usage.output_tokens, 'business logo', prompt, model, { url }, account_profile_info);
6782
6801
  // prompt: `find "${name}" logo base on the following facts "${facts}", Return only png,jpg img tag , nothing else`,
6783
6802
  // try {
@@ -6786,6 +6805,8 @@ const get_business_logo = async function (uid, name, account_profile_info) {
6786
6805
  // return data.is_business;
6787
6806
  // }
6788
6807
  // } catch (error) {}
6808
+
6809
+ return drive_ret;
6789
6810
  } catch (err) {
6790
6811
  return console.error(err);
6791
6812
  }
@@ -6858,49 +6879,49 @@ const return_image_blob_from_downloaded_image = async function (url) {
6858
6879
 
6859
6880
  return { is_transparent, image_blob: new Blob([buffer], { type: 'image/png' }) };
6860
6881
  }
6861
- try {
6862
- if (!url) {
6863
- throw new Error('No URL provided in request');
6864
- }
6882
+ // try {
6883
+ if (!url) {
6884
+ throw new Error('No URL provided in request');
6885
+ }
6865
6886
 
6866
- // 3. Download the image to a Buffer
6867
- const res = await fetch(url);
6868
- if (!res.ok) {
6869
- throw new Error(`Failed to fetch image URL: ${res.status} ${res.statusText}`);
6870
- }
6887
+ // 3. Download the image to a Buffer
6888
+ const res = await fetch(url);
6889
+ if (!res.ok) {
6890
+ throw new Error(`Failed to fetch image URL: ${res.status} ${res.statusText}`);
6891
+ }
6871
6892
 
6872
- const arrayBuffer = await res.arrayBuffer();
6873
- const imageBuffer = Buffer.from(arrayBuffer);
6893
+ const arrayBuffer = await res.arrayBuffer();
6894
+ const imageBuffer = Buffer.from(arrayBuffer);
6874
6895
 
6875
- const tempDir = os.tmpdir();
6876
- const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
6896
+ const tempDir = os.tmpdir();
6897
+ const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
6877
6898
 
6878
- const inputExt = path.extname(url) || '.jpg';
6879
- const tempInputPath = path.join(tempDir, `input_${uniqueId}${inputExt}`);
6880
- const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
6899
+ const inputExt = path.extname(url) || '.jpg';
6900
+ const tempInputPath = path.join(tempDir, `input_${uniqueId}${inputExt}`);
6901
+ const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
6881
6902
 
6882
- // 5. Write the downloaded image to disk
6883
- fs.writeFileSync(tempInputPath, imageBuffer);
6884
- /////////////////////////////////
6903
+ // 5. Write the downloaded image to disk
6904
+ fs.writeFileSync(tempInputPath, imageBuffer);
6905
+ /////////////////////////////////
6885
6906
 
6886
- const imageFiles = [tempInputPath];
6907
+ const imageFiles = [tempInputPath];
6887
6908
 
6888
- const images = await Promise.all(
6889
- imageFiles.map(async (filePath) => {
6890
- const img_ret = await imageToPngBlob(filePath);
6891
- const blob = img_ret.image_blob;
6909
+ const images = await Promise.all(
6910
+ imageFiles.map(async (filePath) => {
6911
+ const img_ret = await imageToPngBlob(filePath);
6912
+ const blob = img_ret.image_blob;
6892
6913
 
6893
- // OpenAI expects a filename for logging/debugging
6894
- const filename = path.basename(filePath, path.extname(filePath)) + '.png';
6895
- blob.name = filename; // Optional but helpful
6896
- // @ts-ignore – name is allowed in Node 20+
6897
- blob.lastModified = Date.now();
6914
+ // OpenAI expects a filename for logging/debugging
6915
+ const filename = path.basename(filePath, path.extname(filePath)) + '.png';
6916
+ blob.name = filename; // Optional but helpful
6917
+ // @ts-ignore – name is allowed in Node 20+
6918
+ blob.lastModified = Date.now();
6898
6919
 
6899
- return { is_transparent: img_ret.is_transparent, image_blob: blob };
6900
- }),
6901
- );
6902
- return { image_blob: images[0].image_blob, is_transparent: images[0].is_transparent, tempOutputPath };
6903
- } catch (err) {
6904
- console.error(err);
6905
- }
6920
+ return { is_transparent: img_ret.is_transparent, image_blob: blob };
6921
+ }),
6922
+ );
6923
+ return { image_blob: images[0].image_blob, is_transparent: images[0].is_transparent, tempOutputPath };
6924
+ // } catch (err) {
6925
+ // console.error(err);
6926
+ // }
6906
6927
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4316",
3
+ "version": "1.1.4318",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",