@qcy2012/api-wasm-sdk 0.0.0-stage → 1.0.0
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 +9 -3
- 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,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qcy2012/api-wasm-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"keywords": ["wasm", "api", "sdk"],
|
|
9
|
+
"author": "qcy2012",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"description": "An Open Source SDK for interacting with WebAssembly APIs."
|
|
6
12
|
}
|
package/README.md
DELETED