channel-worker 1.3.1 → 1.3.3
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/lib/nst-manager.js +23 -11
- package/package.json +1 -1
package/lib/nst-manager.js
CHANGED
|
@@ -46,16 +46,25 @@ class NstManager {
|
|
|
46
46
|
profiles = res.data;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const match = profiles.find(p => p.name === name);
|
|
49
|
+
const match = profiles.find(p => p.name?.toLowerCase() === name.toLowerCase());
|
|
50
50
|
if (match) return match.profileId || match._id;
|
|
51
51
|
|
|
52
|
-
// Fallback: fetch
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
// Fallback: fetch ALL profiles via local API (paginate if needed)
|
|
53
|
+
let allProfiles = [];
|
|
54
|
+
let page = 1;
|
|
55
|
+
while (true) {
|
|
56
|
+
const rawRes = await fetch(`http://localhost:8848/api/v2/profiles/?keyword=${encodeURIComponent(name)}&page=${page}&limit=100`, {
|
|
57
|
+
headers: { 'x-api-key': this.apiKey },
|
|
58
|
+
});
|
|
59
|
+
const rawData = await rawRes.json();
|
|
60
|
+
const docs = rawData?.data?.docs || rawData?.data || [];
|
|
61
|
+
allProfiles = allProfiles.concat(docs);
|
|
62
|
+
const totalPages = rawData?.data?.totalPage || rawData?.data?.totalPages || 1;
|
|
63
|
+
if (page >= totalPages || docs.length === 0) break;
|
|
64
|
+
page++;
|
|
65
|
+
}
|
|
66
|
+
console.log(`[nst] Fallback search for "${name}": found ${allProfiles.length} profiles, names: [${allProfiles.map(p => p.name).join(', ')}]`);
|
|
67
|
+
const fallback = allProfiles.find(p => p.name?.toLowerCase() === name.toLowerCase());
|
|
59
68
|
if (fallback) return fallback.profileId || fallback._id;
|
|
60
69
|
|
|
61
70
|
return null;
|
|
@@ -73,7 +82,7 @@ class NstManager {
|
|
|
73
82
|
return existing;
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
console.log(`[nst]
|
|
85
|
+
console.log(`[nst] WARNING: Profile "${name}" NOT FOUND — creating new profile...`);
|
|
77
86
|
const res = await this.client.profiles().createProfile({
|
|
78
87
|
name,
|
|
79
88
|
platform: 'Windows',
|
|
@@ -122,9 +131,12 @@ class NstManager {
|
|
|
122
131
|
|
|
123
132
|
// Ensure profile language is en-US to prevent auto-translate
|
|
124
133
|
try {
|
|
125
|
-
await
|
|
126
|
-
|
|
134
|
+
const res = await fetch(`http://localhost:8848/api/v2/profiles/${profileId}`, {
|
|
135
|
+
method: 'PATCH',
|
|
136
|
+
headers: { 'Content-Type': 'application/json', 'x-api-key': this.apiKey },
|
|
137
|
+
body: JSON.stringify({ fingerprint: { language: 'en-US' } }),
|
|
127
138
|
});
|
|
139
|
+
if (!res.ok) console.warn(`[nst] Could not update profile language: ${res.status}`);
|
|
128
140
|
} catch (err) {
|
|
129
141
|
console.warn(`[nst] Could not update profile language:`, err.message);
|
|
130
142
|
}
|