@xuda.io/account_module 1.2.311 → 1.2.312
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 +0 -122
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1588,125 +1588,3 @@ export const get_user_name = async function (uid) {
|
|
|
1588
1588
|
return 'unknown';
|
|
1589
1589
|
}
|
|
1590
1590
|
};
|
|
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
|
-
// // };
|
|
1598
|
-
|
|
1599
|
-
// const ASSET_PATH = '/var/xuda/assets/imgly-bg'; // <-- your folder
|
|
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);
|
|
1624
|
-
|
|
1625
|
-
// // Convert to buffer and save
|
|
1626
|
-
// const outputBuffer = Buffer.from(await blob.arrayBuffer());
|
|
1627
|
-
|
|
1628
|
-
// const originalname = 'avatar_' + path.basename(url);
|
|
1629
|
-
// const tempPath = path.join(os.tmpdir(), originalname + Date.now());
|
|
1630
|
-
// fs.writeFileSync(tempPath, outputBuffer);
|
|
1631
|
-
|
|
1632
|
-
// const ext = drive_module.getExtensionFromUrl(url);
|
|
1633
|
-
|
|
1634
|
-
// const file_obj = {
|
|
1635
|
-
// originalname,
|
|
1636
|
-
// path: tempPath,
|
|
1637
|
-
// mimetype: `image/${ext}`,
|
|
1638
|
-
// };
|
|
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
|
-
// };
|
|
1646
|
-
|
|
1647
|
-
// const removeBg2 = async function (req, job_id, headers) {
|
|
1648
|
-
// // 1. Load your drive module
|
|
1649
|
-
// const drive_module = await import(`${module_path}/drive_module/index.mjs`);
|
|
1650
|
-
|
|
1651
|
-
// const { url, uid } = req;
|
|
1652
|
-
|
|
1653
|
-
// try {
|
|
1654
|
-
// if (!url) {
|
|
1655
|
-
// throw new Error('No URL provided in request');
|
|
1656
|
-
// }
|
|
1657
|
-
|
|
1658
|
-
// // 3. Download the image to a Buffer
|
|
1659
|
-
// const res = await fetch(url);
|
|
1660
|
-
// if (!res.ok) {
|
|
1661
|
-
// throw new Error(`Failed to fetch image URL: ${res.status} ${res.statusText}`);
|
|
1662
|
-
// }
|
|
1663
|
-
// const arrayBuffer = await res.arrayBuffer();
|
|
1664
|
-
// const imageBuffer = Buffer.from(arrayBuffer);
|
|
1665
|
-
|
|
1666
|
-
// // 4. Create Temporary File Paths
|
|
1667
|
-
// // rembg works with files, so we must save the buffer to disk first.
|
|
1668
|
-
// const tempDir = os.tmpdir();
|
|
1669
|
-
// const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
|
|
1670
|
-
|
|
1671
|
-
// const inputExt = path.extname(url) || '.jpg';
|
|
1672
|
-
// const tempInputPath = path.join(tempDir, `input_${uniqueId}${inputExt}`);
|
|
1673
|
-
// const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
|
|
1674
|
-
|
|
1675
|
-
// // 5. Write the downloaded image to disk
|
|
1676
|
-
// fs.writeFileSync(tempInputPath, imageBuffer);
|
|
1677
|
-
|
|
1678
|
-
// // 6. EXECUTE REMBG via CLI
|
|
1679
|
-
// // "rembg i [input] [output]"
|
|
1680
|
-
// console.log(`Processing with rembg: ${tempInputPath} -> ${tempOutputPath}`);
|
|
1681
|
-
// debugger;
|
|
1682
|
-
// await execAsync(`rembg i "${tempInputPath}" "${tempOutputPath}"`);
|
|
1683
|
-
|
|
1684
|
-
// // 7. Prepare File Object for Drive Upload
|
|
1685
|
-
// // Note: The output file now exists at tempOutputPath
|
|
1686
|
-
// const originalname = 'avatar_' + path.basename(url, inputExt) + '.png';
|
|
1687
|
-
|
|
1688
|
-
// const file_obj = {
|
|
1689
|
-
// originalname: originalname,
|
|
1690
|
-
// path: tempOutputPath,
|
|
1691
|
-
// mimetype: 'image/png', // rembg output is always PNG
|
|
1692
|
-
// };
|
|
1693
|
-
|
|
1694
|
-
// // 8. Upload to Drive
|
|
1695
|
-
// const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
|
|
1696
|
-
|
|
1697
|
-
// console.log(`Background removed!`, drive_ret);
|
|
1698
|
-
|
|
1699
|
-
// // 9. Clean up Input File (Output file might be needed by upload, so clean input only)
|
|
1700
|
-
// try {
|
|
1701
|
-
// fs.unlinkSync(tempInputPath);
|
|
1702
|
-
// // Optional: fs.unlinkSync(tempOutputPath); // Only if upload_drive_file_user handles the file reading fully
|
|
1703
|
-
// } catch (cleanupErr) {
|
|
1704
|
-
// console.warn('Warning: Failed to cleanup temp input file', cleanupErr);
|
|
1705
|
-
// }
|
|
1706
|
-
|
|
1707
|
-
// return drive_ret;
|
|
1708
|
-
// } catch (error) {
|
|
1709
|
-
// console.error('Error processing background removal:', error);
|
|
1710
|
-
// throw error;
|
|
1711
|
-
// }
|
|
1712
|
-
// };
|