File size: 2,322 Bytes
0789882
 
 
 
 
 
 
 
 
 
 
6cf7576
0789882
 
 
 
 
 
 
 
 
 
 
 
47a5084
 
 
 
 
 
 
 
 
 
0789882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}`);
});