scraperjavascript3615
ImgBB Image Uploader with Custom Expiration / Duration
Uploader gambar ImgBB (id.imgbb.com) otomatis tanpa API key. Mendukung upload via URL gambar publik maupun file lokal, dilengkapi fitur pemilihan durasi hapus otomatis (expiration) dari 5 menit hingga 6 bulan atau permanen.
Vamz Spectre24 Okt 2026229 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/imgbb-uploader" -o imgbb-uploader.js
# 2. Jalankan script
node imgbb-uploader.js
Dependencies npm yang Dibutuhkan:
npm install none (zero-dependency native Node.js)Panduan Penggunaan:
Cara Penggunaan: 1. Download script: curl -sL "https://code.vamxapi.my.id/snippet/raw/imgbb-uploader" -o imgbb-uploader.js 2. Eksekusi via terminal: # Upload via URL gambar dengan durasi hapus 5 menit: node imgbb-uploader.js "https://avatars.githubusercontent.com/u/10137?v=4" 5m # Upload file lokal dengan durasi hapus 1 hari: node imgbb-uploader.js "./gambar.png" 1d # Upload permanen (tanpa hapus otomatis): node imgbb-uploader.js "https://avatars.githubusercontent.com/u/10137?v=4" never Opsi Durasi (Expiration): - 5m, 15m, 30m (5 / 15 / 30 menit) - 1h, 3h, 6h, 12h (1 / 3 / 6 / 12 jam) - 1d, 2d, 3d, 4d, 5d, 6d (1 s.d 6 hari) - 1w, 2w, 3w (1 s.d 3 minggu) - 1mo, 2mo, 3mo, 4mo, 5mo, 6mo (1 s.d 6 bulan) - never / 0 (jangan hapus otomatis) - Atau kode ISO 8601 langsung: PT5M, PT15M, PT30M, PT1H, P1D, P1W, P1M, dll.
imgbb-uploader.js(229 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
* ImgBB Image Uploader with Custom Expiration Duration
* Reverse-Engineered from https://id.imgbb.com/
*
* @author Vamz Spectre (https://vamxapi.my.id)
*
* Download:
* curl -sL "https://code.vamxapi.my.id/snippet/raw/imgbb-uploader" -o imgbb-uploader.js
*
* Usage:
* node imgbb-uploader.js "https://avatars.githubusercontent.com/u/10137?v=4" 5m
* node imgbb-uploader.js "./gambar.png" 1d
* node imgbb-uploader.js "https://avatars.githubusercontent.com/u/10137?v=4" never
*/
const https = require("https");
const fs = require("fs");
const path = require("path");
const EXPIRATION_MAP = {
never: "",
"0": "",
"5m": "PT5M",
"5min": "PT5M",
"15m": "PT15M",
"15min": "PT15M",
"30m": "PT30M",
"30min": "PT30M",
"1h": "PT1H",
"3h": "PT3H",
"6h": "PT6H",
"12h": "PT12H",
"1d": "P1D",
"2d": "P2D",
"3d": "P3D",
"4d": "P4D",
"5d": "P5D",
"6d": "P6D",
"1w": "P1W",
"2w": "P2W",
"3w": "P3W",
"1mo": "P1M",
"2mo": "P2M",
"3mo": "P3M",
"4mo": "P4M",
"5mo": "P5M",
"6mo": "P6M",
"1month": "P1M",
"2months": "P2M",
"3months": "P3M",
"4months": "P4M",
"5months": "P5M",
"6months": "P6M",
};
/**
* Normalisasi opsi durasi ke format kode ISO 8601 yang diterima ImgBB
* @param {string} exp
*/
function normalizeExpiration(exp) {
if (!exp) return "";
const clean = String(exp).trim().toLowerCase();
if (EXPIRATION_MAP[clean] !== undefined) return EXPIRATION_MAP[clean];
const upper = String(exp).trim().toUpperCase();
if (Object.values(EXPIRATION_MAP).includes(upper)) return upper;
return "";
}
/**
* Mengambil session cookie dan auth_token dari halaman utama ImgBB
*/
function getSessionAndToken() {
return new Promise((resolve, reject) => {
https
.get(
"https://id.imgbb.com/",
{
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Accept-Language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
},
},
(res) => {
let data = "";
const cookies = (res.headers["set-cookie"] || []).map((c) => c.split(";")[0]).join("; ");
res.on("data", (chunk) => (data += chunk));
res.on("end", () => {
const match = data.match(/PF\.obj\.config\.auth_token\s*=\s*"([^"]+)"/);
if (!match) return reject(new Error("Gagal mengambil auth_token dari ImgBB."));
resolve({ authToken: match[1], cookies });
});
}
)
.on("error", reject);
});
}
/**
* Fungsi utama upload gambar ke ImgBB
* @param {string|Buffer} input URL gambar publik, file path lokal, atau Buffer
* @param {object} options
* @param {string} options.expiration Durasi simpan: 5m, 15m, 30m, 1h, 1d, 1w, 1mo, atau never (default: "")
* @param {string} options.filename Nama file kustom (opsional)
*/
async function uploadImgbb(input, options = {}) {
if (!input) {
throw new Error("Input gambar wajib diberikan (URL, path file, atau Buffer).");
}
const { authToken, cookies } = await getSessionAndToken();
const rawExp = options.expiration || options.durasi || "";
const expCode = normalizeExpiration(rawExp);
const isUrl = typeof input === "string" && /^https?:\/\//i.test(input);
const boundary = "----WebKitFormBoundary" + Math.random().toString(36).substring(2);
const parts = [];
const addField = (name, val) => {
parts.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${val}\r\n`));
};
addField("action", "upload");
addField("auth_token", authToken);
if (expCode) {
addField("expiration", expCode);
}
if (isUrl) {
addField("type", "url");
addField("source", input);
} else {
addField("type", "file");
let fileBuffer;
let fileName = options.filename || "image.png";
if (Buffer.isBuffer(input)) {
fileBuffer = input;
} else if (typeof input === "string" && fs.existsSync(input)) {
fileBuffer = fs.readFileSync(input);
fileName = path.basename(input);
} else {
throw new Error(`Path file tidak ditemukan atau format tidak valid: ${input}`);
}
const fileHeader = Buffer.from(
`--${boundary}\r\nContent-Disposition: form-data; name="source"; filename="${fileName}"\r\nContent-Type: application/octet-stream\r\n\r\n`
);
parts.push(fileHeader);
parts.push(fileBuffer);
parts.push(Buffer.from("\r\n"));
}
parts.push(Buffer.from(`--${boundary}--\r\n`));
const fullBody = Buffer.concat(parts);
return new Promise((resolve, reject) => {
const req = https.request(
"https://id.imgbb.com/json",
{
method: "POST",
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
Referer: "https://id.imgbb.com/",
Accept: "application/json",
Cookie: cookies,
"Content-Type": `multipart/form-data; boundary=${boundary}`,
"Content-Length": fullBody.length,
},
},
(res) => {
let body = "";
res.on("data", (c) => (body += c));
res.on("end", () => {
try {
const json = JSON.parse(body);
if (json.status_code !== 200 || !json.image) {
return reject(new Error(json.error?.message || json.status_txt || "Gagal mengunggah gambar ke ImgBB."));
}
const img = json.image;
resolve({
status: true,
directUrl: img.url,
viewerUrl: img.url_viewer,
deleteUrl: img.delete_url,
thumbUrl: img.thumb?.url || img.display_url,
filename: img.filename,
size: img.size_formatted || `${img.size} bytes`,
width: img.width,
height: img.height,
expirationSeconds: img.expiration,
expirationCode: expCode || "never",
raw: img,
});
} catch (e) {
reject(new Error("Respon tidak valid dari ImgBB: " + body.slice(0, 100)));
}
});
}
);
req.on("error", reject);
req.write(fullBody);
req.end();
});
}
// CLI Runner Support
if (require.main === module) {
(async () => {
try {
const input = process.argv[2] || "https://avatars.githubusercontent.com/u/10137?v=4";
const expiration = process.argv[3] || "never";
const res = await uploadImgbb(input, { expiration });
console.log(JSON.stringify(res, null, 2));
} catch (err) {
console.error(JSON.stringify({ status: false, error: err.message }, null, 2));
process.exit(1);
}
})();
}
module.exports = {
uploadImgbb,
normalizeExpiration,
EXPIRATION_MAP,
};