const express = require('express'); const multer = require('multer'); const { generateIQC } = require('iqc-canvas'); const app = express(); const upload = multer(); app.use(express.json({ limit: '50mb' })); app.post('/generate', upload.single('sticker'), async (req, res) => { try { const text = req.body.text !== undefined ? req.body.text : ' '; const time = req.body.time || '00.00'; let options = {}; if (req.body.replySender || req.body.replyText) { options.reply = { sender: req.body.replySender || 'Sender', text: req.body.replyText || 'Reply Text' }; } if (req.body.reactionEmojis) { if (Array.isArray(req.body.reactionEmojis)) { options.reactionEmojis = req.body.reactionEmojis; } else { try { options.reactionEmojis = JSON.parse(req.body.reactionEmojis); } catch (e) { if (typeof req.body.reactionEmojis === 'string') { options.reactionEmojis = req.body.reactionEmojis.split(','); } } } } if (req.body.showPlusBtn !== undefined) { options.showPlusBtn = req.body.showPlusBtn === 'true' || req.body.showPlusBtn === true; } if (req.body.senderName) { options.sender = req.body.senderName; } if (req.file) { options.sticker = req.file.buffer; } else if (req.body.stickerUrl) { options.sticker = req.body.stickerUrl; } const result = await generateIQC(text, time, options); if (result && result.image) { res.set('Content-Type', 'image/png'); res.send(result.image); } else { res.status(500).json({ error: 'Failed to generate image' }); } } catch (error) { console.error(error); res.status(500).json({ error: error.message }); } }); app.get('/', (req, res) => { res.json({ message: 'IQC Canvas API is running', version: '1.0.0' }); }); const PORT = process.env.PORT || 7860; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });