Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -331,6 +331,34 @@ app.get('*', (req, res) => {
|
|
| 331 |
res.json(documentation);
|
| 332 |
});
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
app.post('/generate', async (req, res) => {
|
| 335 |
const { profileImage, mainImage, caption, views } = req.body;
|
| 336 |
totalReq++;
|
|
@@ -370,22 +398,7 @@ app.post('/generate2', async (req, res) => {
|
|
| 370 |
}
|
| 371 |
});
|
| 372 |
|
| 373 |
-
|
| 374 |
-
try {
|
| 375 |
-
const { text } = req.query;
|
| 376 |
-
if (!text) {
|
| 377 |
-
return res.json('Input text brat!');
|
| 378 |
-
}
|
| 379 |
-
const imageBuffer = await utils.generateBrat(text);
|
| 380 |
-
res.set('Content-Type', 'image/png');
|
| 381 |
-
res.send(imageBuffer);
|
| 382 |
-
} catch (error) {
|
| 383 |
-
console.error(error);
|
| 384 |
-
res.status(500).json({
|
| 385 |
-
message: 'error generating brat'
|
| 386 |
-
});
|
| 387 |
-
}
|
| 388 |
-
});
|
| 389 |
|
| 390 |
// Mulai server Express
|
| 391 |
app.listen(port, () => {
|
|
|
|
| 331 |
res.json(documentation);
|
| 332 |
});
|
| 333 |
|
| 334 |
+
app.get('/brat', async (req, res) => {
|
| 335 |
+
try {
|
| 336 |
+
const { text } = req.query;
|
| 337 |
+
|
| 338 |
+
// Validasi jika parameter `text` tidak ada
|
| 339 |
+
if (!text || typeof text !== 'string' || text.trim().length === 0) {
|
| 340 |
+
return res.status(400).json({
|
| 341 |
+
message: 'Invalid input. Please provide a valid text query parameter.'
|
| 342 |
+
});
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// Proses pembuatan gambar
|
| 346 |
+
const imageBuffer = await utils.generateBrat(text);
|
| 347 |
+
|
| 348 |
+
// Mengirimkan hasil gambar
|
| 349 |
+
res.set('Content-Type', 'image/png');
|
| 350 |
+
res.send(imageBuffer);
|
| 351 |
+
} catch (error) {
|
| 352 |
+
console.error('Error generating brat:', error.message);
|
| 353 |
+
|
| 354 |
+
res.status(500).json({
|
| 355 |
+
message: 'An error occurred while generating the brat image.',
|
| 356 |
+
error: error.message
|
| 357 |
+
});
|
| 358 |
+
}
|
| 359 |
+
});
|
| 360 |
+
|
| 361 |
+
|
| 362 |
app.post('/generate', async (req, res) => {
|
| 363 |
const { profileImage, mainImage, caption, views } = req.body;
|
| 364 |
totalReq++;
|
|
|
|
| 398 |
}
|
| 399 |
});
|
| 400 |
|
| 401 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
// Mulai server Express
|
| 404 |
app.listen(port, () => {
|