@xuda.io/ai_module 1.1.4315 → 1.1.4317
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 +37 -37
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6769,7 +6769,7 @@ const get_business_logo = async function (uid, name, account_profile_info) {
|
|
|
6769
6769
|
background: 'transparent',
|
|
6770
6770
|
});
|
|
6771
6771
|
debugger;
|
|
6772
|
-
imageBase64 = await normalizeBase64To1024(logo_response.data[0].b64_json);
|
|
6772
|
+
let imageBase64 = await normalizeBase64To1024(logo_response.data[0].b64_json);
|
|
6773
6773
|
|
|
6774
6774
|
const outputBuffer = Buffer.from(imageBase64, 'base64');
|
|
6775
6775
|
const outputPath = file.tempOutputPath;
|
|
@@ -6858,49 +6858,49 @@ const return_image_blob_from_downloaded_image = async function (url) {
|
|
|
6858
6858
|
|
|
6859
6859
|
return { is_transparent, image_blob: new Blob([buffer], { type: 'image/png' }) };
|
|
6860
6860
|
}
|
|
6861
|
-
try {
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6861
|
+
// try {
|
|
6862
|
+
if (!url) {
|
|
6863
|
+
throw new Error('No URL provided in request');
|
|
6864
|
+
}
|
|
6865
6865
|
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
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
|
+
}
|
|
6871
6871
|
|
|
6872
|
-
|
|
6873
|
-
|
|
6872
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
6873
|
+
const imageBuffer = Buffer.from(arrayBuffer);
|
|
6874
6874
|
|
|
6875
|
-
|
|
6876
|
-
|
|
6875
|
+
const tempDir = os.tmpdir();
|
|
6876
|
+
const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
|
|
6877
6877
|
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
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)
|
|
6881
6881
|
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6882
|
+
// 5. Write the downloaded image to disk
|
|
6883
|
+
fs.writeFileSync(tempInputPath, imageBuffer);
|
|
6884
|
+
/////////////////////////////////
|
|
6885
6885
|
|
|
6886
|
-
|
|
6886
|
+
const imageFiles = [tempInputPath];
|
|
6887
6887
|
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
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;
|
|
6892
6892
|
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
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();
|
|
6898
6898
|
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
|
|
6903
|
-
} catch (err) {
|
|
6904
|
-
|
|
6905
|
-
}
|
|
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
|
+
// }
|
|
6906
6906
|
};
|