@xstbot/cloudku 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/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # @xstbot/cloudku
2
+
3
+ > **CloudKu Official SDK** — Solusi integrasi CDN yang cepat, aman, dan dirancang khusus untuk pengembang modern.
4
+
5
+ [![NPM Version](https://img.shields.io/npm/v/@xstbot/cloudku)](https://www.npmjs.com/package/@xstbot/cloudku)
6
+ [![License](https://img.shields.io/npm/l/@xstbot/cloudku)](https://www.npmjs.com/package/@xstbot/cloudku)
7
+ [![Status](https://img.shields.io/badge/status-stable-brightgreen)]()
8
+
9
+ 📦 NPM Package : https://www.npmjs.com/package/@xstbot/cloudku
10
+ 📖 Dokumentasi : https://cloudku.sbs/npm
11
+
12
+ ---
13
+
14
+ ## 📋 Daftar Isi
15
+
16
+ - [Tentang](#tentang)
17
+ - [Instalasi](#instalasi)
18
+ - [Penggunaan](#penggunaan)
19
+ - [JavaScript (CommonJS)](#javascript-commonjs)
20
+ - [TypeScript](#typescript)
21
+ - [Response Schema](#response-schema)
22
+ - [Contoh Lengkap](#contoh-lengkap)
23
+ - [Error Handling](#error-handling)
24
+ - [Lisensi](#lisensi)
25
+
26
+ ---
27
+
28
+ ## 📌 Tentang
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 (CommonJS) dan TypeScript, sehingga cocok digunakan di berbagai lingkungan pengembangan modern.
31
+
32
+ ---
33
+
34
+ ## 🚀 Instalasi
35
+
36
+ Pasang library melalui NPM dengan perintah berikut:
37
+
38
+ ```bash
39
+ npm install @xstbot/cloudku
40
+ ```
41
+
42
+ Atau menggunakan Yarn:
43
+
44
+ ```bash
45
+ yarn add @xstbot/cloudku
46
+ ```
47
+
48
+ ---
49
+
50
+ ## 📖 Penggunaan
51
+
52
+ ### JavaScript (CommonJS)
53
+
54
+ Gunakan `require` untuk integrasi cepat pada proyek Node.js atau Express.
55
+
56
+ ```js
57
+ const { CloudKu } = require('@xstbot/cloudku');
58
+
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);
67
+
68
+ if (result.status === 'success') {
69
+ console.log('✅ File Berhasil Diunggah:', result.url);
70
+ } else {
71
+ console.error('❌ API Error:', result.message);
72
+ }
73
+ } catch (err) {
74
+ console.error('🔥 System Error:', err.message);
75
+ }
76
+ }
77
+ ```
78
+
79
+ ---
80
+
81
+ ### TypeScript
82
+
83
+ Dukungan penuh tipe data untuk pengalaman pengembangan yang lebih aman dan terstruktur.
84
+
85
+ ```ts
86
+ import { CloudKu, CloudKuResponse } from '@xstbot/cloudku';
87
+
88
+ const uploadToCDN = async (buffer: Buffer, name: string): Promise<void> => {
89
+ const response: CloudKuResponse = await CloudKu(buffer, name);
90
+
91
+ if (response.status === 'success') {
92
+ // Properti 'url' sudah terdefinisi secara otomatis
93
+ process.stdout.write(`✅ File live at: ${response.url}`);
94
+ }
95
+ };
96
+ ```
97
+
98
+ ---
99
+
100
+ ## 📊 Response Schema
101
+
102
+ Struktur data yang dikembalikan oleh setiap permintaan API:
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) |
109
+
110
+ ---
111
+
112
+ ## 💡 Contoh Lengkap
113
+
114
+ Berikut contoh penggunaan lengkap untuk upload file dari sistem lokal:
115
+
116
+ ```js
117
+ const { CloudKu } = require('@xstbot/cloudku');
118
+ const fs = require('fs');
119
+ const path = require('path');
120
+
121
+ async function uploadLocalFile(filePath) {
122
+ const fileBuffer = fs.readFileSync(filePath);
123
+ const fileName = path.basename(filePath);
124
+
125
+ console.log(`📤 Mengupload: ${fileName}`);
126
+
127
+ const result = await CloudKu(fileBuffer, fileName);
128
+
129
+ if (result.status === 'success') {
130
+ console.log('✅ Upload berhasil!');
131
+ console.log('🔗 URL File:', result.url);
132
+ } else {
133
+ console.error('❌ Upload gagal:', result.message);
134
+ }
135
+ }
136
+
137
+ // Contoh pemanggilan
138
+ uploadLocalFile('./foto.jpg');
139
+ ```
140
+
141
+ ---
142
+
143
+ ## ⚠️ Error Handling
144
+
145
+ Selalu gunakan `try/catch` untuk menangani error yang mungkin terjadi:
146
+
147
+ ```js
148
+ const { CloudKu } = require('@xstbot/cloudku');
149
+
150
+ async function safeUpload(buffer, filename) {
151
+ try {
152
+ const result = await CloudKu(buffer, filename);
153
+
154
+ if (result.status === 'success') {
155
+ return result.url;
156
+ } else {
157
+ throw new Error(result.message);
158
+ }
159
+ } catch (error) {
160
+ console.error('Upload gagal:', error.message);
161
+ return null;
162
+ }
163
+ }
164
+ ```
165
+
166
+ ---
167
+
168
+ ## 🔗 Tautan Penting
169
+
170
+ | Sumber | URL |
171
+ |----------------|---------------------------------------------------|
172
+ | NPM Package | https://www.npmjs.com/package/@xstbot/cloudku |
173
+ | Dokumentasi | https://cloudku.sbs/npm |
174
+ | CloudKu Utama | https://cloudku.sbs |
175
+
176
+ ---
177
+
178
+ ## 📄 Lisensi
179
+
180
+ Proyek ini dilisensikan di bawah lisensi yang tercantum pada halaman NPM resmi.
181
+ Kunjungi: https://www.npmjs.com/package/@xstbot/cloudku
182
+
183
+ ---
184
+
185
+ > © 2026 CloudKu CDN API • Developed for Modern Apps
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface CloudKuResponse {
2
+ status: string;
3
+ message: string;
4
+ url?: string;
5
+ [key: string]: any;
6
+ }
7
+ export declare const CloudKu: (fileBuffer: Buffer, fileName: string) => Promise<CloudKuResponse>;
package/index.js ADDED
@@ -0,0 +1,39 @@
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/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@xstbot/cloudku",
3
+ "version": "1.0.1",
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
+ "author": "xstbot",
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "axios": "^1.6.0",
14
+ "form-data": "^4.0.0"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "^5.0.0",
18
+ "@types/node": "^20.0.0"
19
+ }
20
+ }
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
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
+ };