@qcy2012/api-wasm-sdk 0.0.0-stage → 1.0.1
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.js +48 -0
- package/package.json +17 -4
- package/test/test1.js +18 -0
- package/README.md +0 -3
package/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class QcyAPI {
|
|
2
|
+
constructor(apiKey) {
|
|
3
|
+
this.apiKey = apiKey;
|
|
4
|
+
this.baseUrl = 'https://api.qcyblog.dpdns.org/api';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async _request(endpoint, method = 'GET', body = null) {
|
|
8
|
+
const options = {
|
|
9
|
+
method,
|
|
10
|
+
headers: {
|
|
11
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
12
|
+
...(body && { 'Content-Type': 'application/json' })
|
|
13
|
+
},
|
|
14
|
+
...(body && { body: JSON.stringify(body) })
|
|
15
|
+
};
|
|
16
|
+
const res = await fetch(`${this.baseUrl}/${endpoint}`, options);
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
if (!res.ok) throw new Error(data.error || 'API request failed');
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async compute(n) {
|
|
23
|
+
return this._request(`compute?n=${n}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async cipher(text, shift) {
|
|
27
|
+
return this._request(`cipher?text=${encodeURIComponent(text)}&shift=${shift}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async hash(text) {
|
|
31
|
+
return this._request(`hash?text=${encodeURIComponent(text)}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async markdown(md) {
|
|
35
|
+
return this._request('markdown', 'POST', { markdown: md });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async qrcode(text) {
|
|
39
|
+
return this._request(`qrcode?text=${encodeURIComponent(text)}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async evalLua(code) {
|
|
43
|
+
return this._request('eval', 'POST', { code });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = QcyAPI;
|
|
48
|
+
// 如果是 ES Module,用 export default QcyAPI;
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qcy2012/api-wasm-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"wasm",
|
|
10
|
+
"api",
|
|
11
|
+
"sdk"
|
|
12
|
+
],
|
|
13
|
+
"author": "qcy2012",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"description": "An Open Source SDK for interacting with WebAssembly APIs.",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@qcy2012/api-wasm-sdk": "^1.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/test/test1.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const QcyAPI = require('@qcy2012/api-wasm-sdk');
|
|
2
|
+
|
|
3
|
+
// 替换成你控制台里生成的真实 Key
|
|
4
|
+
const api = new QcyAPI('sk_live_YourKeyHere');
|
|
5
|
+
|
|
6
|
+
async function test() {
|
|
7
|
+
try {
|
|
8
|
+
const hashResult = await api.hash('Hello SDK');
|
|
9
|
+
console.log('Hash 结果:', hashResult);
|
|
10
|
+
|
|
11
|
+
const qrResult = await api.qrcode('https://api.qcyblog.dpdns.org');
|
|
12
|
+
console.log('二维码 SVG 长度:', qrResult.svg.length);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error('调用失败:', err.message);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test();
|
package/README.md
DELETED