Spaces:
Paused
Paused
| 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 | |