@xuda.io/account_module 1.2.271 → 1.2.273
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/download_model.mjs +56 -0
- package/index.mjs +6 -6
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// download-models.js
|
|
2
|
+
const https = require('https');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const models = ['u2net.onnx', 'u2net.onnx.bin', 'u2net.onnx.wasm'];
|
|
7
|
+
|
|
8
|
+
const baseUrl = 'https://static.imgly.com/background-removal/models/medium/';
|
|
9
|
+
const outputDir = '/var/xuda/assets/imgly-bg';
|
|
10
|
+
|
|
11
|
+
// Create directory if it doesn't exist
|
|
12
|
+
if (!fs.existsSync(outputDir)) {
|
|
13
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function downloadFile(url, filepath) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const file = fs.createWriteStream(filepath);
|
|
19
|
+
https
|
|
20
|
+
.get(url, (response) => {
|
|
21
|
+
if (response.statusCode === 200) {
|
|
22
|
+
response.pipe(file);
|
|
23
|
+
file.on('finish', () => {
|
|
24
|
+
file.close();
|
|
25
|
+
console.log(`Downloaded: ${path.basename(filepath)}`);
|
|
26
|
+
resolve();
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
reject(new Error(`HTTP ${response.statusCode}: ${url}`));
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
.on('error', (err) => {
|
|
33
|
+
fs.unlink(filepath, () => {}); // Delete partial file
|
|
34
|
+
reject(err);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function downloadAll() {
|
|
40
|
+
console.log('Downloading models to:', outputDir);
|
|
41
|
+
|
|
42
|
+
for (const model of models) {
|
|
43
|
+
const url = baseUrl + model;
|
|
44
|
+
const filepath = path.join(outputDir, model);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
await downloadFile(url, filepath);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`Failed to download ${model}:`, error.message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log('Download complete!');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
downloadAll();
|
package/index.mjs
CHANGED
|
@@ -1561,13 +1561,13 @@ const removeBg = async function (req, job_id, headers) {
|
|
|
1561
1561
|
// debug: true, // Optional: Logs fetch attempts for debugging
|
|
1562
1562
|
// };
|
|
1563
1563
|
|
|
1564
|
-
const ASSET_PATH = '/var/xuda/assets/imgly-bg';
|
|
1564
|
+
const ASSET_PATH = '/var/xuda/assets/imgly-bg'; // <-- your folder
|
|
1565
1565
|
|
|
1566
|
-
const config = {
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
};
|
|
1566
|
+
const config = {
|
|
1567
|
+
publicPath: `file://${ASSET_PATH}/`, // ← this fixes everything
|
|
1568
|
+
debug: false,
|
|
1569
|
+
model: 'medium', // or "small" if you want faster/smaller
|
|
1570
|
+
};
|
|
1571
1571
|
debugger;
|
|
1572
1572
|
const drive_module = await import(`${module_path}/drive_module/index.mjs`);
|
|
1573
1573
|
const { url } = req;
|