Spaces:
Build error
Build error
Update router/api.js
Browse files- router/api.js +47 -0
router/api.js
CHANGED
|
@@ -3,6 +3,7 @@ import axios from 'axios';
|
|
| 3 |
import crypto from 'crypto';
|
| 4 |
import FormData from 'form-data'; // Import modul form-data untuk menghandle multipart
|
| 5 |
import Groq from 'groq-sdk';
|
|
|
|
| 6 |
import bytes from 'bytes';
|
| 7 |
|
| 8 |
import { feloAI } from '../lib/feloAI.js';
|
|
@@ -257,6 +258,52 @@ APIrouter.post('/toanime', async (req, res) => {
|
|
| 257 |
}
|
| 258 |
})
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
export default APIrouter;
|
| 262 |
|
|
|
|
| 3 |
import crypto from 'crypto';
|
| 4 |
import FormData from 'form-data'; // Import modul form-data untuk menghandle multipart
|
| 5 |
import Groq from 'groq-sdk';
|
| 6 |
+
import knights from 'knights-canvas';
|
| 7 |
import bytes from 'bytes';
|
| 8 |
|
| 9 |
import { feloAI } from '../lib/feloAI.js';
|
|
|
|
| 258 |
}
|
| 259 |
})
|
| 260 |
|
| 261 |
+
APIrouter.post('/knights/welcome2', async (req, res) => {
|
| 262 |
+
try {
|
| 263 |
+
const {
|
| 264 |
+
type = 'welcome', // 'welcome' atau 'goodbye'
|
| 265 |
+
avatar, // url atau base64
|
| 266 |
+
username = 'User',
|
| 267 |
+
bg = 'https://telegra.ph/file/3c4ff69839e79f50e97f0.jpg',
|
| 268 |
+
groupname = 'Group',
|
| 269 |
+
member = 1
|
| 270 |
+
} = req.body;
|
| 271 |
+
|
| 272 |
+
if (!avatar) {
|
| 273 |
+
return res.status(400).json({ success: false, message: 'avatar (url or base64) is required' });
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// Buat instance sesuai type
|
| 277 |
+
let imageAttachment;
|
| 278 |
+
if (type === 'welcome') {
|
| 279 |
+
imageAttachment = await new knights.Welcome2()
|
| 280 |
+
.setAvatar(avatar) // knights lib biasanya menerima URL/path/base64
|
| 281 |
+
.setUsername(username)
|
| 282 |
+
.setBg(bg)
|
| 283 |
+
.setGroupname(groupname)
|
| 284 |
+
.setMember(member)
|
| 285 |
+
.toAttachment();
|
| 286 |
+
} else {
|
| 287 |
+
imageAttachment = await new knights.Goodbye2()
|
| 288 |
+
.setAvatar(avatar)
|
| 289 |
+
.setUsername(username)
|
| 290 |
+
.setBg(bg)
|
| 291 |
+
.setGroupname(groupname)
|
| 292 |
+
.setMember(member)
|
| 293 |
+
.toAttachment();
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
const buffer = imageAttachment.toBuffer();
|
| 297 |
+
const base64 = buffer.toString('base64');
|
| 298 |
+
|
| 299 |
+
// Kembalikan base64 agar client (bot) bisa meng-upload atau menggunakan sesuai kebutuhan
|
| 300 |
+
return res.json({ success: true, data: base64 });
|
| 301 |
+
} catch (err) {
|
| 302 |
+
console.error('knights welcome2 error:', err);
|
| 303 |
+
return res.status(500).json({ success: false, message: 'Internal Server Error', error: String(err) });
|
| 304 |
+
}
|
| 305 |
+
});
|
| 306 |
+
|
| 307 |
|
| 308 |
export default APIrouter;
|
| 309 |
|