@xuda.io/account_module 1.2.306 → 1.2.307

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 +49 -49
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -121,7 +121,7 @@ export const update_account_info = async function (req, job_id, headers) {
121
121
  }
122
122
 
123
123
  if (account_obj.account_info?.profile_picture) {
124
- // await removeBg({ url: account_obj.account_info?.profile_picture, uid }, job_id, headers);
124
+ ai_module.convert_profile_image_to_avatar({ url: account_obj.account_info?.profile_picture, uid }, job_id, headers);
125
125
  } else {
126
126
  const ai_module = await import(`${module_path}/ai_module/index.mjs`);
127
127
  // const profile_avatar_ret = ai_module.update_thumbnail('account', account_obj, account_obj.account_project_id, uid, job_id, headers, 'xuda_accounts');
@@ -1589,62 +1589,62 @@ export const get_user_name = async function (uid) {
1589
1589
  }
1590
1590
  };
1591
1591
 
1592
- // const removeBg = async function (req, job_id, headers) {
1593
- // // const ASSET_PATH = path.join(process.cwd(), 'assets/imgly-bg');
1594
- // // const config = {
1595
- // // publicPath: `file://${ASSET_PATH}/`, // Points to your local folder
1596
- // // debug: true, // Optional: Logs fetch attempts for debugging
1597
- // // };
1592
+ const removeBg = async function (req, job_id, headers) {
1593
+ // const ASSET_PATH = path.join(process.cwd(), 'assets/imgly-bg');
1594
+ // const config = {
1595
+ // publicPath: `file://${ASSET_PATH}/`, // Points to your local folder
1596
+ // debug: true, // Optional: Logs fetch attempts for debugging
1597
+ // };
1598
1598
 
1599
- // const ASSET_PATH = '/var/xuda/assets/imgly-bg'; // <-- your folder
1599
+ const ASSET_PATH = '/var/xuda/assets/imgly-bg'; // <-- your folder
1600
1600
 
1601
- // const config = {
1602
- // publicPath: `file://${ASSET_PATH}/`, // ← this fixes everything
1603
- // debug: false,
1604
- // model: 'medium', // or "small" if you want faster/smaller
1605
- // };
1606
- // debugger;
1607
- // const drive_module = await import(`${module_path}/drive_module/index.mjs`);
1608
- // const { url } = req;
1609
- // try {
1610
- // let imageBuffer;
1611
- // // if (inputPath) {
1612
- // // imageBuffer = fs.readFileSync(inputPath);
1613
- // // }
1614
-
1615
- // if (url) {
1616
- // const res = await fetch(url);
1617
- // if (!res.ok) {
1618
- // throw new Error(`Failed to fetch image URL: ${res.status} ${res.statusText}`);
1619
- // }
1620
- // const arrayBuffer = await res.arrayBuffer();
1621
- // imageBuffer = Buffer.from(arrayBuffer);
1622
- // }
1623
- // const blob = await removeBackground(imageBuffer, config);
1601
+ const config = {
1602
+ publicPath: `file://${ASSET_PATH}/`, // ← this fixes everything
1603
+ debug: false,
1604
+ model: 'medium', // or "small" if you want faster/smaller
1605
+ };
1606
+ debugger;
1607
+ const drive_module = await import(`${module_path}/drive_module/index.mjs`);
1608
+ const { url } = req;
1609
+ try {
1610
+ let imageBuffer;
1611
+ // if (inputPath) {
1612
+ // imageBuffer = fs.readFileSync(inputPath);
1613
+ // }
1614
+
1615
+ if (url) {
1616
+ const res = await fetch(url);
1617
+ if (!res.ok) {
1618
+ throw new Error(`Failed to fetch image URL: ${res.status} ${res.statusText}`);
1619
+ }
1620
+ const arrayBuffer = await res.arrayBuffer();
1621
+ imageBuffer = Buffer.from(arrayBuffer);
1622
+ }
1623
+ const blob = await removeBackground(imageBuffer, config);
1624
1624
 
1625
- // // Convert to buffer and save
1626
- // const outputBuffer = Buffer.from(await blob.arrayBuffer());
1625
+ // Convert to buffer and save
1626
+ const outputBuffer = Buffer.from(await blob.arrayBuffer());
1627
1627
 
1628
- // const originalname = 'avatar_' + path.basename(url);
1629
- // const tempPath = path.join(os.tmpdir(), originalname + Date.now());
1630
- // fs.writeFileSync(tempPath, outputBuffer);
1628
+ const originalname = 'avatar_' + path.basename(url);
1629
+ const tempPath = path.join(os.tmpdir(), originalname + Date.now());
1630
+ fs.writeFileSync(tempPath, outputBuffer);
1631
1631
 
1632
- // const ext = drive_module.getExtensionFromUrl(url);
1632
+ const ext = drive_module.getExtensionFromUrl(url);
1633
1633
 
1634
- // const file_obj = {
1635
- // originalname,
1636
- // path: tempPath,
1637
- // mimetype: `image/${ext}`,
1638
- // };
1634
+ const file_obj = {
1635
+ originalname,
1636
+ path: tempPath,
1637
+ mimetype: `image/${ext}`,
1638
+ };
1639
1639
 
1640
- // const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
1641
- // console.log(`Background removed! `, drive_ret);
1642
- // } catch (error) {
1643
- // console.error('Error:', error);
1644
- // }
1645
- // };
1640
+ const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
1641
+ console.log(`Background removed! `, drive_ret);
1642
+ } catch (error) {
1643
+ console.error('Error:', error);
1644
+ }
1645
+ };
1646
1646
 
1647
- const removeBg = async function (req, job_id, headers) {
1647
+ const removeBg2 = async function (req, job_id, headers) {
1648
1648
  // 1. Load your drive module
1649
1649
  const drive_module = await import(`${module_path}/drive_module/index.mjs`);
1650
1650
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.306",
3
+ "version": "1.2.307",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {