channel-worker 1.3.2 → 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 +15 -7
- package/package.json +1 -1
package/lib/nst-manager.js
CHANGED
|
@@ -49,13 +49,21 @@ class NstManager {
|
|
|
49
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 profiles via local API
|
|
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(', ')}]`);
|
|
59
67
|
const fallback = allProfiles.find(p => p.name?.toLowerCase() === name.toLowerCase());
|
|
60
68
|
if (fallback) return fallback.profileId || fallback._id;
|
|
61
69
|
|