@xuda.io/ai_module 1.1.4527 → 1.1.4529

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 +5 -68
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -7000,55 +7000,6 @@ const get_chat_picture_cache = async function (uid, docType, name) {
7000
7000
  };
7001
7001
 
7002
7002
  const save_drive_file_to_disk = async function (drive_file) {
7003
- async function hasTransparentBackground(filePath) {
7004
- const image = sharp(filePath);
7005
- const metadata = await image.metadata();
7006
-
7007
- // If the image doesn't have an alpha channel at all → no transparency possible
7008
- if (!metadata.hasAlpha) {
7009
- return false;
7010
- }
7011
-
7012
- // For images with alpha channel, check if any pixel actually has alpha < 255
7013
- const { data, info } = await image.raw().toBuffer({ resolveWithObject: true });
7014
-
7015
- // Determine position of alpha channel based on number of channels
7016
- const channels = info.channels; // 2 (grayscale+alpha), 4 (RGBA), etc.
7017
- const alphaOffset = channels === 2 ? 1 : channels === 4 ? 3 : -1;
7018
-
7019
- if (alphaOffset === -1) {
7020
- // Unusual channel count – be conservative and assume it might have transparency
7021
- return true;
7022
- }
7023
-
7024
- for (let i = alphaOffset; i < data.length; i += channels) {
7025
- if (data[i] < 255) {
7026
- return true; // Found at least one transparent/semi-transparent pixel
7027
- }
7028
- }
7029
-
7030
- return false; // Has alpha channel but all pixels are fully opaque
7031
- }
7032
-
7033
- async function imageToPngBlob(filePath) {
7034
- const ext = path.extname(filePath).toLowerCase();
7035
-
7036
- let buffer;
7037
-
7038
- let is_transparent = false;
7039
- if (ext === '.png') {
7040
- buffer = await fs.promises.readFile(filePath);
7041
- is_transparent = await hasTransparentBackground(filePath);
7042
- } else {
7043
- console.log(`Converting ${path.basename(filePath)} to PNG...`);
7044
- buffer = await sharp(filePath).png({ quality: 100, compressionLevel: 9, force: true }).toBuffer();
7045
- }
7046
-
7047
- // Create a Blob with correct MIME type
7048
-
7049
- return { is_transparent, image_blob: new Blob([buffer], { type: 'image/png' }) };
7050
- }
7051
- // try {
7052
7003
  if (!drive_file.file_url) {
7053
7004
  throw new Error('No URL provided in request');
7054
7005
  }
@@ -7065,28 +7016,14 @@ const save_drive_file_to_disk = async function (drive_file) {
7065
7016
  const tempDir = os.tmpdir();
7066
7017
 
7067
7018
  const tempInputPath = path.join(tempDir, drive_file.filename);
7068
- // const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
7069
7019
 
7070
7020
  // 5. Write the downloaded image to disk
7071
7021
  fs.writeFileSync(tempInputPath, imageBuffer);
7072
7022
  /////////////////////////////////
7073
7023
 
7074
- const imageFiles = [tempInputPath];
7075
-
7076
- const images = await Promise.all(
7077
- imageFiles.map(async (filePath) => {
7078
- const img_ret = await imageToPngBlob(filePath);
7079
- const blob = img_ret.image_blob;
7080
-
7081
- // OpenAI expects a filename for logging/debugging
7082
- const filename = path.basename(filePath, path.extname(filePath)) + '.png';
7083
- blob.name = filename; // Optional but helpful
7084
- // @ts-ignore – name is allowed in Node 20+
7085
- blob.lastModified = Date.now();
7086
-
7087
- return { is_transparent: img_ret.is_transparent, image_blob: blob };
7088
- }),
7089
- );
7090
-
7091
- return images[0];
7024
+ return {
7025
+ filename: 'invoice.pdf',
7026
+ path: '/tmp/attachments/invoice.pdf',
7027
+ contentType: 'application/pdf',
7028
+ };
7092
7029
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4527",
3
+ "version": "1.1.4529",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",