@xuda.io/ai_module 1.1.4301 → 1.1.4302
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 +49 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6737,6 +6737,8 @@ const get_business_logo = async function (uid, name, account_profile_info) {
|
|
|
6737
6737
|
});
|
|
6738
6738
|
console.log('=============', ret);
|
|
6739
6739
|
|
|
6740
|
+
const url = ret.data;
|
|
6741
|
+
|
|
6740
6742
|
// prompt: `find "${name}" logo base on the following facts "${facts}", Return only png,jpg img tag , nothing else`,
|
|
6741
6743
|
// try {
|
|
6742
6744
|
// if (ret.code > -1) {
|
|
@@ -6745,3 +6747,50 @@ const get_business_logo = async function (uid, name, account_profile_info) {
|
|
|
6745
6747
|
// }
|
|
6746
6748
|
// } catch (error) {}
|
|
6747
6749
|
};
|
|
6750
|
+
|
|
6751
|
+
const return_image_blob_from_downloaded_image = async function (url) {
|
|
6752
|
+
try {
|
|
6753
|
+
if (!url) {
|
|
6754
|
+
throw new Error('No URL provided in request');
|
|
6755
|
+
}
|
|
6756
|
+
|
|
6757
|
+
// 3. Download the image to a Buffer
|
|
6758
|
+
const res = await fetch(url);
|
|
6759
|
+
if (!res.ok) {
|
|
6760
|
+
throw new Error(`Failed to fetch image URL: ${res.status} ${res.statusText}`);
|
|
6761
|
+
}
|
|
6762
|
+
|
|
6763
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
6764
|
+
const imageBuffer = Buffer.from(arrayBuffer);
|
|
6765
|
+
|
|
6766
|
+
const tempDir = os.tmpdir();
|
|
6767
|
+
const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
|
|
6768
|
+
|
|
6769
|
+
const inputExt = path.extname(url) || '.jpg';
|
|
6770
|
+
const tempInputPath = path.join(tempDir, `input_${uniqueId}${inputExt}`);
|
|
6771
|
+
const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
|
|
6772
|
+
|
|
6773
|
+
// 5. Write the downloaded image to disk
|
|
6774
|
+
fs.writeFileSync(tempInputPath, imageBuffer);
|
|
6775
|
+
/////////////////////////////////
|
|
6776
|
+
|
|
6777
|
+
const imageFiles = [tempInputPath];
|
|
6778
|
+
|
|
6779
|
+
const images = await Promise.all(
|
|
6780
|
+
imageFiles.map(async (filePath) => {
|
|
6781
|
+
const img_ret = await imageToPngBlob(filePath);
|
|
6782
|
+
const blob = img_ret.image_blob;
|
|
6783
|
+
|
|
6784
|
+
// OpenAI expects a filename for logging/debugging
|
|
6785
|
+
const filename = path.basename(filePath, path.extname(filePath)) + '.png';
|
|
6786
|
+
blob.name = filename; // Optional but helpful
|
|
6787
|
+
// @ts-ignore – name is allowed in Node 20+
|
|
6788
|
+
blob.lastModified = Date.now();
|
|
6789
|
+
|
|
6790
|
+
return { is_transparent: img_ret.is_transparent, image_blob: blob };
|
|
6791
|
+
}),
|
|
6792
|
+
);
|
|
6793
|
+
} catch (err) {
|
|
6794
|
+
console.error(err);
|
|
6795
|
+
}
|
|
6796
|
+
};
|