File size: 3,250 Bytes
d145b59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const { v4: uuidv4 } = require('uuid');

//const styles = [ "anime", "manga", "3d", "comic", "realistic" ];
//const qualitys = [ "low", "medium" ];

const drawever = {
  queue: async (imageUrl, style, quality) => {
    const imageResponse = await axios.get(imageUrl, { responseType: 'arraybuffer' });
    const mimeType = imageResponse.headers['content-type'];
    const base64Image = Buffer.from(imageResponse.data).toString('base64');
    const base64ImageUrl = `data:${mimeType};base64,${base64Image}`;
    
    const data = JSON.stringify({
        "image": base64ImageUrl,
        "style": style,
        "quality": quality,
        "strength": 0.4
    });

    const config = {
        method: 'POST',
        url: 'https://www.drawever.com/api/tools/queue',
        headers: {
            'User-Agent': 'Mozilla/5.0 (Android 10; Mobile; rv:131.0 Firefox/131.0',
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'accept-language': 'id-ID',
            'referer': 'https://www.drawever.com/ai/photo-to-anime?start=1736212737985',
            'path': '/ai/photo-to-anime',
            'origin': 'https://www.drawever.com',
            'alt-used': 'www.drawever.com',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'priority': 'u=0',
            'te': 'trailers',
            'Cookie': '_ga_H15YQYJC6R=GS1.1.1736212732.1.0.1736212732.0.0.0; _ga=GA1.1.1471909988.1736212732'
        },
        data: data
    };

    const api = await axios.request(config);
    return api.data;
  },
  create: async (imageUrl, style, quality) => {
    const { queueId } = await drawever.queue(imageUrl, style, quality);

    const checkStatus = async () => {
      const config = {
        method: 'GET',
        url: `https://www.drawever.com/api/tools/queue?queueId=${queueId}`,
        headers: {
            'User-Agent': 'Mozilla/5.0 (Android 10; Mobile; rv:131.0) Gecko/131.0 Firefox/131.0',
            'accept-language': 'id-ID',
            'referer': 'https://www.drawever.com/ai/photo-to-anime?start=1736212737985',
            'content-type': 'application/json',
            'alt-used': 'www.drawever.com',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'priority': 'u=4',
            'te': 'trailers',
            'Cookie': '_ga_H15YQYJC6R=GS1.1.1736226490.2.1.1736226501.0.0.0; _ga=GA1.1.1471909988.1736212732; _ym_uid=1736782704433305783; _ym_d=1736782704; _ym_isad=2; _ym_visorc=w'
        }
      };

      const api = await axios.request(config);
      const output = api.data.output;

      if (output) {
        const base64Image = output.split(';base64,').pop();
        const imageBuffer = Buffer.from(base64Image, 'base64');
        const fileName = `${uuidv4()}.png`;
        const filePath = path.join(__dirname, '../cdn', fileName);
        fs.writeFileSync(filePath, imageBuffer);
       console.log(api.data)
        return imageBuffer
      }
    };
    checkStatus();
  }
};

// Example usage
module.exports = drawever