opencode-pollinations-plugin 5.6.0-beta.4 → 5.6.0-beta.6
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/dist/debug_check.js +35 -0
- package/dist/server/commands.js +27 -5
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as https from 'https';
|
|
2
|
+
|
|
3
|
+
function checkEndpoint(ep, key) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
console.log(`Checking ${ep}...`);
|
|
6
|
+
const req = https.request({
|
|
7
|
+
hostname: 'gen.pollinations.ai',
|
|
8
|
+
path: ep,
|
|
9
|
+
method: 'GET',
|
|
10
|
+
headers: { 'Authorization': `Bearer ${key}` }
|
|
11
|
+
}, (res) => {
|
|
12
|
+
console.log(`Status Code: ${res.statusCode}`);
|
|
13
|
+
let data = '';
|
|
14
|
+
res.on('data', chunk => data += chunk);
|
|
15
|
+
res.on('end', () => {
|
|
16
|
+
console.log(`Body Sample: ${data.substring(0, 100)}...`);
|
|
17
|
+
if (res.statusCode === 200) resolve({ ok: true });
|
|
18
|
+
else resolve({ ok: false, status: res.statusCode });
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
req.on('error', (e) => {
|
|
22
|
+
console.log(`Error: ${e.message}`);
|
|
23
|
+
resolve({ ok: false, status: e.message || 'Error' });
|
|
24
|
+
});
|
|
25
|
+
req.setTimeout(10000, () => req.destroy());
|
|
26
|
+
req.end();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const KEY = "plln_sk_F7a4RcBG4AVCeBSo6lnS36EKwm0nPn1O";
|
|
31
|
+
|
|
32
|
+
(async () => {
|
|
33
|
+
const res = await checkEndpoint('/account/profile', KEY);
|
|
34
|
+
console.log('Result:', res);
|
|
35
|
+
})();
|
package/dist/server/commands.js
CHANGED
|
@@ -10,12 +10,34 @@ function checkEndpoint(ep, key) {
|
|
|
10
10
|
hostname: 'gen.pollinations.ai',
|
|
11
11
|
path: ep,
|
|
12
12
|
method: 'GET',
|
|
13
|
-
headers: {
|
|
13
|
+
headers: {
|
|
14
|
+
'Authorization': `Bearer ${key}`,
|
|
15
|
+
'User-Agent': 'Pollinations-Plugin/5.6.0' // Identify cleanly
|
|
16
|
+
}
|
|
14
17
|
}, (res) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const isJson = res.headers['content-type']?.includes('application/json');
|
|
19
|
+
let data = '';
|
|
20
|
+
res.on('data', chunk => data += chunk);
|
|
21
|
+
res.on('end', () => {
|
|
22
|
+
if (res.statusCode === 200 && isJson) {
|
|
23
|
+
// Double Check Check Body for Logical Errors masked as 200
|
|
24
|
+
try {
|
|
25
|
+
const json = JSON.parse(data);
|
|
26
|
+
if (json.error || json.success === false) {
|
|
27
|
+
resolve({ ok: false, reason: "API Logical Error", status: 200 });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
resolve({ ok: true });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
resolve({ ok: false, reason: "Invalid JSON", status: 200 });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
resolve({ ok: false, status: res.statusCode, reason: isJson ? "API Error" : "Not JSON (Cloudflare?)" });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
19
41
|
});
|
|
20
42
|
req.on('error', (e) => resolve({ ok: false, status: e.message || 'Error' }));
|
|
21
43
|
req.setTimeout(10000, () => req.destroy()); // 10s Timeout
|
package/package.json
CHANGED