Loading snippets...
Node.js CLI tool to upload images to Picsur and get direct URLs as JSON output.
/**
* Picsur Uploader
* Author: ShanMolvyr
* sumber: https://whatsapp.com/channel/0029VbB4Kw8EFeXfeExaXc3Q
* Install: npm install axios form-data
* Usage: node picsur.js foto.png
* node picsur.js foto.png foto2.jpg
*/
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const path = require('path');
const BASE_URL = 'https://picsur.org';
async function upload(filePath) {
const form = new FormData();
const filename = path.basename(filePath);
const ext = path.extname(filePath).replace('.', '') || 'png';
form.append('image', fs.createReadStream(filePath), {
filename,
contentType: `image/${ext}`,
});
const res = await axios.post(`${BASE_URL}/api/image/upload`, form, {
headers: {
...form.getHeaders(),
'Accept': 'application/json, text/plain, */*',
'Cache-Control': 'no-cache',
},
maxContentLength: Infinity,
maxBodyLength: Infinity,
});
if (!res.data.success) throw new Error(JSON.stringify(res.data));
const { id, delete_key } = res.data.data;
return {
file: filename,
url: `${BASE_URL}/i/${id}.${ext}`, // ekstensi ikut input
delete_key,
};
}
// ── CLI ──────────────────────────────────────────────────────────────────────
const files = process.argv.slice(2);
if (files.length === 0) {
console.error('Usage: node picsur-upload.js <file1> [file2] ...');
process.exit(1);
}
(async () => {
const results = [];
for (const file of files) {
if (!fs.existsSync(file)) {
results.push({ file: path.basename(file), success: false, error: 'File tidak ditemukan' });
continue;
}
try {
const r = await upload(file);
results.push({ success: true, ...r });
} catch (err) {
results.push({ file: path.basename(file), success: false, error: err.message });
}
}
const output = results.length === 1 ? results[0] : results;
console.log(JSON.stringify(output, null, 2));
})();