@xstbot/cloudku 1.0.1 → 1.0.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/README.md +66 -93
- package/dist/esm/index.js +38 -0
- package/dist/index.js +39 -0
- package/package.json +49 -10
- package/index.d.ts +0 -7
- package/index.js +0 -39
- package/src/index.ts +0 -29
package/README.md
CHANGED
|
@@ -1,163 +1,136 @@
|
|
|
1
1
|
# @xstbot/cloudku
|
|
2
2
|
|
|
3
|
-
> **CloudKu Official SDK**
|
|
3
|
+
> **CloudKu Official SDK** Solusi integrasi CDN yang cepat, aman, dan dirancang khusus untuk pengembang modern.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@xstbot/cloudku)
|
|
6
6
|
[](https://www.npmjs.com/package/@xstbot/cloudku)
|
|
7
7
|
[]()
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
¦ NPM Package : https://www.npmjs.com/package/@xstbot/cloudku
|
|
10
|
+
– Dokumentasi : https://cloudku.sbs/docs
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## ‹ Daftar Isi
|
|
15
15
|
|
|
16
16
|
- [Tentang](#tentang)
|
|
17
17
|
- [Instalasi](#instalasi)
|
|
18
18
|
- [Penggunaan](#penggunaan)
|
|
19
19
|
- [JavaScript (CommonJS)](#javascript-commonjs)
|
|
20
|
-
- [
|
|
20
|
+
- [JavaScript (ES Module)](#javascript-es-module)
|
|
21
|
+
- [API Reference](#api-reference)
|
|
21
22
|
- [Response Schema](#response-schema)
|
|
22
|
-
- [Contoh Lengkap](#contoh-lengkap)
|
|
23
23
|
- [Error Handling](#error-handling)
|
|
24
24
|
- [Lisensi](#lisensi)
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
|
-
##
|
|
28
|
+
## Tentang
|
|
29
29
|
|
|
30
|
-
`@xstbot/cloudku` adalah SDK resmi dari **CloudKu CDN** yang memungkinkan pengembang mengunggah file ke jaringan CDN secara mudah dan cepat. Library ini mendukung JavaScript (
|
|
30
|
+
`@xstbot/cloudku` adalah SDK resmi dari **CloudKu CDN** yang memungkinkan pengembang mengunggah file ke jaringan CDN secara mudah dan cepat. Library ini mendukung **JavaScript** dalam format **CommonJS (CJS)** maupun **ES Module (ESM)**, sehingga kompatibel dengan berbagai environment Node.js modern.
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
Pasang library melalui NPM dengan perintah berikut:
|
|
34
|
+
## Instalasi
|
|
37
35
|
|
|
38
36
|
```bash
|
|
39
37
|
npm install @xstbot/cloudku
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Atau menggunakan Yarn:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
38
|
+
# atau
|
|
45
39
|
yarn add @xstbot/cloudku
|
|
46
40
|
```
|
|
47
41
|
|
|
48
42
|
---
|
|
49
43
|
|
|
50
|
-
##
|
|
44
|
+
## – Penggunaan
|
|
51
45
|
|
|
52
46
|
### JavaScript (CommonJS)
|
|
53
47
|
|
|
54
|
-
Gunakan `require` untuk integrasi cepat pada proyek Node.js atau Express.
|
|
55
|
-
|
|
56
48
|
```js
|
|
57
49
|
const { CloudKu } = require('@xstbot/cloudku');
|
|
50
|
+
const fs = require('fs');
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
* Fungsi untuk menangani upload file
|
|
61
|
-
* @param {Buffer} fileBuffer - Data buffer dari file
|
|
62
|
-
* @param {String} fileName - Nama file yang diinginkan
|
|
63
|
-
*/
|
|
64
|
-
async function handleFileUpload(fileBuffer, fileName) {
|
|
65
|
-
try {
|
|
66
|
-
const result = await CloudKu(fileBuffer, fileName);
|
|
52
|
+
const buffer = fs.readFileSync('./photo.jpg');
|
|
67
53
|
|
|
54
|
+
async function handleUpload() {
|
|
55
|
+
try {
|
|
56
|
+
const result = await CloudKu(buffer, 'photo.jpg');
|
|
68
57
|
if (result.status === 'success') {
|
|
69
|
-
console.log('
|
|
58
|
+
console.log('File berhasil diunggah:', result.url);
|
|
70
59
|
} else {
|
|
71
|
-
console.error('
|
|
60
|
+
console.error('API Error:', result.message);
|
|
72
61
|
}
|
|
73
62
|
} catch (err) {
|
|
74
|
-
console.error('
|
|
63
|
+
console.error('System Error:', err.message);
|
|
75
64
|
}
|
|
76
65
|
}
|
|
66
|
+
|
|
67
|
+
handleUpload();
|
|
77
68
|
```
|
|
78
69
|
|
|
79
70
|
---
|
|
80
71
|
|
|
81
|
-
###
|
|
82
|
-
|
|
83
|
-
Dukungan penuh tipe data untuk pengalaman pengembangan yang lebih aman dan terstruktur.
|
|
72
|
+
### JavaScript (ES Module)
|
|
84
73
|
|
|
85
|
-
```
|
|
86
|
-
import { CloudKu
|
|
74
|
+
```js
|
|
75
|
+
import { CloudKu } from '@xstbot/cloudku';
|
|
76
|
+
import { readFileSync } from 'fs';
|
|
87
77
|
|
|
88
|
-
const
|
|
89
|
-
const response: CloudKuResponse = await CloudKu(buffer, name);
|
|
78
|
+
const buffer = readFileSync('./photo.jpg');
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
const handleUpload = async () => {
|
|
81
|
+
const result = await CloudKu(buffer, 'photo.jpg');
|
|
82
|
+
if (result.status === 'success') {
|
|
83
|
+
console.log(`File live at: ${result.url}`);
|
|
84
|
+
} else {
|
|
85
|
+
console.error('Upload gagal:', result.message);
|
|
94
86
|
}
|
|
95
87
|
};
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## 📊 Response Schema
|
|
101
88
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
| Property | Type | Description |
|
|
105
|
-
|-----------|-----------------------|-----------------------------------------------------|
|
|
106
|
-
| `status` | `string` | Mengembalikan `"success"` atau `"error"` |
|
|
107
|
-
| `message` | `string` | Detail pesan respons atau informasi error |
|
|
108
|
-
| `url` | `string \| undefined` | URL publik permanen file (hanya jika status sukses) |
|
|
89
|
+
handleUpload();
|
|
90
|
+
```
|
|
109
91
|
|
|
110
92
|
---
|
|
111
93
|
|
|
112
|
-
##
|
|
94
|
+
## API Reference
|
|
113
95
|
|
|
114
|
-
|
|
96
|
+
### CloudKu(fileBuffer, fileName)
|
|
115
97
|
|
|
116
|
-
|
|
117
|
-
const { CloudKu } = require('@xstbot/cloudku');
|
|
118
|
-
const fs = require('fs');
|
|
119
|
-
const path = require('path');
|
|
98
|
+
Fungsi utama untuk upload file ke CloudKu CDN.
|
|
120
99
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
100
|
+
| Parameter | Type | Required | Description |
|
|
101
|
+
|--------------|----------|----------|---------------------------------|
|
|
102
|
+
| fileBuffer | Buffer | YES | Isi file sebagai Node.js Buffer |
|
|
103
|
+
| fileName | string | YES | Nama file beserta ekstensinya |
|
|
124
104
|
|
|
125
|
-
|
|
105
|
+
**Returns:** `Promise<Object>` Response dari CDN.
|
|
126
106
|
|
|
127
|
-
|
|
107
|
+
---
|
|
128
108
|
|
|
129
|
-
|
|
130
|
-
console.log('✅ Upload berhasil!');
|
|
131
|
-
console.log('🔗 URL File:', result.url);
|
|
132
|
-
} else {
|
|
133
|
-
console.error('❌ Upload gagal:', result.message);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
109
|
+
## Response Schema
|
|
136
110
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
111
|
+
| Property | Type | Description |
|
|
112
|
+
|------------|-------------------------|-----------------------------------------------|
|
|
113
|
+
| status | "success" atau "error" | Status hasil operasi |
|
|
114
|
+
| message | string | Detail pesan atau informasi error |
|
|
115
|
+
| url | string atau undefined | URL publik file (hanya tersedia jika success) |
|
|
140
116
|
|
|
141
117
|
---
|
|
142
118
|
|
|
143
|
-
##
|
|
119
|
+
## Error Handling
|
|
144
120
|
|
|
145
|
-
|
|
121
|
+
Library ini sudah menangani error secara internal. Jika upload gagal, fungsi akan mengembalikan object dengan `status: 'error'` dan `message` yang berisi keterangan kegagalan sehingga aplikasi Anda tidak akan crash.
|
|
146
122
|
|
|
147
123
|
```js
|
|
148
124
|
const { CloudKu } = require('@xstbot/cloudku');
|
|
149
125
|
|
|
150
126
|
async function safeUpload(buffer, filename) {
|
|
151
|
-
|
|
152
|
-
const result = await CloudKu(buffer, filename);
|
|
127
|
+
const result = await CloudKu(buffer, filename);
|
|
153
128
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
} catch (error) {
|
|
160
|
-
console.error('Upload gagal:', error.message);
|
|
129
|
+
if (result.status === 'success') {
|
|
130
|
+
console.log('URL File:', result.url);
|
|
131
|
+
return result.url;
|
|
132
|
+
} else {
|
|
133
|
+
console.error('Upload gagal:', result.message);
|
|
161
134
|
return null;
|
|
162
135
|
}
|
|
163
136
|
}
|
|
@@ -165,21 +138,21 @@ async function safeUpload(buffer, filename) {
|
|
|
165
138
|
|
|
166
139
|
---
|
|
167
140
|
|
|
168
|
-
##
|
|
141
|
+
## — Tautan Penting
|
|
169
142
|
|
|
170
|
-
| Sumber
|
|
171
|
-
|
|
172
|
-
| NPM Package
|
|
173
|
-
| Dokumentasi
|
|
174
|
-
| CloudKu Utama
|
|
143
|
+
| Sumber | URL |
|
|
144
|
+
|---------------|-----------------------------------------------|
|
|
145
|
+
| NPM Package | https://www.npmjs.com/package/@xstbot/cloudku |
|
|
146
|
+
| Dokumentasi | https://cloudku.sbs/docs |
|
|
147
|
+
| CloudKu Utama | https://cloudku.sbs |
|
|
175
148
|
|
|
176
149
|
---
|
|
177
150
|
|
|
178
|
-
##
|
|
151
|
+
## Lisensi
|
|
179
152
|
|
|
180
|
-
Proyek ini dilisensikan di bawah
|
|
153
|
+
Proyek ini dilisensikan di bawah **MIT License**.
|
|
181
154
|
Kunjungi: https://www.npmjs.com/package/@xstbot/cloudku
|
|
182
155
|
|
|
183
156
|
---
|
|
184
157
|
|
|
185
|
-
> © 2026 CloudKu CDN API
|
|
158
|
+
> © 2026 CloudKu CDN API Developed for Modern Apps
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import FormData from 'form-data';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Upload file ke CloudKu CDN
|
|
6
|
+
* @param {Buffer} fileBuffer - Buffer dari file yang akan di-upload
|
|
7
|
+
* @param {string} fileName - Nama file beserta ekstensinya (contoh: "foto.jpg")
|
|
8
|
+
* @returns {Promise<Object>} Response dari CDN
|
|
9
|
+
*/
|
|
10
|
+
const CloudKu = async (fileBuffer, fileName) => {
|
|
11
|
+
try {
|
|
12
|
+
const url = 'https://cloudku.sbs/cdn/api.php';
|
|
13
|
+
const form = new FormData();
|
|
14
|
+
|
|
15
|
+
form.append('file', fileBuffer, {
|
|
16
|
+
filename: fileName,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const response = await axios.post(url, form, {
|
|
20
|
+
headers: {
|
|
21
|
+
...form.getHeaders(),
|
|
22
|
+
},
|
|
23
|
+
maxContentLength: Infinity,
|
|
24
|
+
maxBodyLength: Infinity,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return response.data;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('CloudKu Upload Error:', error.response?.data || error.message);
|
|
30
|
+
return {
|
|
31
|
+
status: 'error',
|
|
32
|
+
message: error.response?.data?.message || error.message,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { CloudKu };
|
|
38
|
+
export default CloudKu;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const axios = require('axios');
|
|
4
|
+
const FormData = require('form-data');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Upload file ke CloudKu CDN
|
|
8
|
+
* @param {Buffer} fileBuffer - Buffer dari file yang akan di-upload
|
|
9
|
+
* @param {string} fileName - Nama file beserta ekstensinya (contoh: "foto.jpg")
|
|
10
|
+
* @returns {Promise<Object>} Response dari CDN
|
|
11
|
+
*/
|
|
12
|
+
const CloudKu = async (fileBuffer, fileName) => {
|
|
13
|
+
try {
|
|
14
|
+
const url = 'https://cloudku.sbs/cdn/api.php';
|
|
15
|
+
const form = new FormData();
|
|
16
|
+
|
|
17
|
+
form.append('file', fileBuffer, {
|
|
18
|
+
filename: fileName,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const response = await axios.post(url, form, {
|
|
22
|
+
headers: {
|
|
23
|
+
...form.getHeaders(),
|
|
24
|
+
},
|
|
25
|
+
maxContentLength: Infinity,
|
|
26
|
+
maxBodyLength: Infinity,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return response.data;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('CloudKu Upload Error:', error.response?.data || error.message);
|
|
32
|
+
return {
|
|
33
|
+
status: 'error',
|
|
34
|
+
message: error.response?.data?.message || error.message,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
module.exports = { CloudKu };
|
package/package.json
CHANGED
|
@@ -1,20 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xstbot/cloudku",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "CloudKu CDN Uploader Library",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "npx tsc src/index.ts --declaration --outDir ./ --esModuleInterop --skipLibCheck --target ES6 --module CommonJS"
|
|
9
|
-
},
|
|
10
5
|
"author": "xstbot",
|
|
11
6
|
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "node scripts/build.js",
|
|
20
|
+
"prepare": "npm run build",
|
|
21
|
+
"clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true});console.log('🗑️ dist dihapus');\""
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"cloudku",
|
|
25
|
+
"cloudku-cdn",
|
|
26
|
+
"cdn",
|
|
27
|
+
"free-cdn",
|
|
28
|
+
"cloud-storage",
|
|
29
|
+
"file-upload",
|
|
30
|
+
"upload-file",
|
|
31
|
+
"uploader",
|
|
32
|
+
"cloud-uploader",
|
|
33
|
+
"storage",
|
|
34
|
+
"object-storage",
|
|
35
|
+
"media-upload",
|
|
36
|
+
"image-upload",
|
|
37
|
+
"video-upload",
|
|
38
|
+
"nodejs",
|
|
39
|
+
"javascript",
|
|
40
|
+
"api-client",
|
|
41
|
+
"rest-api",
|
|
42
|
+
"cdn-uploader",
|
|
43
|
+
"file-hosting",
|
|
44
|
+
"hosting",
|
|
45
|
+
"cloud-service",
|
|
46
|
+
"free-cloud"
|
|
47
|
+
],
|
|
12
48
|
"dependencies": {
|
|
13
49
|
"axios": "^1.6.0",
|
|
14
50
|
"form-data": "^4.0.0"
|
|
15
51
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=14.0.0"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/xstbot-cloudku/cloudku.git"
|
|
19
58
|
}
|
|
20
|
-
}
|
|
59
|
+
}
|
package/index.d.ts
DELETED
package/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.CloudKu = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const form_data_1 = __importDefault(require("form-data"));
|
|
18
|
-
const CloudKu = (fileBuffer, fileName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
var _a, _b, _c;
|
|
20
|
-
try {
|
|
21
|
-
const url = 'https://cloudku.sbs/cdn/api.php';
|
|
22
|
-
const form = new form_data_1.default();
|
|
23
|
-
form.append('file', fileBuffer, { filename: fileName });
|
|
24
|
-
const response = yield axios_1.default.post(url, form, {
|
|
25
|
-
headers: Object.assign({}, form.getHeaders()),
|
|
26
|
-
maxContentLength: Infinity,
|
|
27
|
-
maxBodyLength: Infinity
|
|
28
|
-
});
|
|
29
|
-
return response.data;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.error('❌ CloudKu Upload Error:', ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
|
|
33
|
-
return {
|
|
34
|
-
status: 'error',
|
|
35
|
-
message: ((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || error.message
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
exports.CloudKu = CloudKu;
|
package/src/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import FormData from 'form-data';
|
|
3
|
-
|
|
4
|
-
export interface CloudKuResponse {
|
|
5
|
-
status: string;
|
|
6
|
-
message: string;
|
|
7
|
-
url?: string;
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const CloudKu = async (fileBuffer: Buffer, fileName: string): Promise<CloudKuResponse> => {
|
|
12
|
-
try {
|
|
13
|
-
const url = 'https://cloudku.sbs/cdn/api.php';
|
|
14
|
-
const form = new FormData();
|
|
15
|
-
form.append('file', fileBuffer, { filename: fileName });
|
|
16
|
-
const response = await axios.post(url, form, {
|
|
17
|
-
headers: { ...form.getHeaders() },
|
|
18
|
-
maxContentLength: Infinity,
|
|
19
|
-
maxBodyLength: Infinity
|
|
20
|
-
});
|
|
21
|
-
return response.data;
|
|
22
|
-
} catch (error: any) {
|
|
23
|
-
console.error('❌ CloudKu Upload Error:', error.response?.data || error.message);
|
|
24
|
-
return {
|
|
25
|
-
status: 'error',
|
|
26
|
-
message: error.response?.data?.message || error.message
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|