diff --git a/README.md b/README.md index bfc5303..225e8b6 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,14 @@ `const scrape = require("scrape-websitee")` # Endpoints +` textToImage +`scrape.textToImage(text)` + - uploadFile `scrape.uploadFile(buffer)` - enhanceImg -`scrape.enhanceImg(buffer)` +`scrape.enhanceImg(url)` - twitterdl2 `scrape.twitterdl2(url)` diff --git a/index.js b/index.js index 1edbcaa..b1b378e 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,27 @@ const pickRandom = async (ext) => { return ext[Math.floor(Math.random() * ext.length)]; }; +async function textToImage(text) { + try { + const { data } = await axios.get( + "https://tti.photoleapapp.com/api/v1/generate?prompt=" + text + ); + const enhanceImages = await enhanceImg(data.result_url, 2); + const result = { + status: true, + url: enhanceImages.url, + }; + return result; + } catch (err) { + const result = { + status: false, + message: String(err), + }; + console.log(result); + return result; + } +} + async function uploadFile(buffer) { const { ext, mime } = await fromBuffer(buffer); const filePath = `temp/${Date.now()}.${ext}`; @@ -30,13 +51,13 @@ async function uploadFile(buffer) { return data; } -async function enhanceImg(buffer) { - const media = await uploadFile(image); +async function enhanceImg(url, scale) { + const scaleNumber = scale ? scale : 2; const { data } = await axios(`https://toolsapi.spyne.ai/api/forward`, { method: "post", data: { - image_url: media.files[0].url, - scale: 4, + image_url: url, + scale: scaleNumber, save_params: { extension: ".png", quality: 95, @@ -544,6 +565,7 @@ async function filmApikDl(url) { } module.exports = { + textToImage, uploadFile, enhanceImg, twitterdl2,