how to fix this? i am getting error like this btw a am create api i am hosted in replit and getting error i'm making api with this code but i get error like below and code, i've tried to fix it but still error, how do i fix this code?? someone please help me :(
const nhpdf = async (input) => {
let count = 0
let ResultPdf = []
let doujin = await nhentai.getDoujin(input)
let title = doujin.title.default
let details = doujin.details
let parodies = details.parodies.map(v => v.name)
let characters = details.characters.map(v => v.name)
let tags = details.tags.map(v => v.name)
let artists = details.artists.map(v => v.name)
let groups = details.groups.map(v => v.name)
let categories = details.categories.map(v => v.name)
let array_page = doujin.pages
for (let i = 0; i < array_page.length; i++) {
if (!fs.existsSync('./nhentai')) fs.mkdirSync('./nhentai')
let image_name = './nhentai/' + title + i + '.jpg'
await new Promise((resolve) => request(array_page[i]).pipe(fs.createWriteStream(image_name)).on('finish', resolve))
console.log(array_page[i])
ResultPdf.push(image_name)
count++
}
await new Promise((resolve) =>
topdf(ResultPdf, 'A4')
.pipe(fs.createWriteStream('./nhentai/' + title + '.pdf'))
.on('finish', resolve)
)
for (let i = 0; i < array_page.length; i++) {
fs.unlink('./nhentai/' + title + i + '.jpg')
}
let size = await fs.statSync(`./nhentai/${title}.pdf`).size
if (size < 45000000) {
console.log('Uploading...')
.then(() => fs.unlinkSync(`./nhentai/${title}.pdf`))
} else {
console.log('Uploading to anonfiles because file size to large')
let options = {
method: 'POST',
url: 'https://api.anonfiles.com/upload',
formData: {
file: fs.createReadStream(`./nhentai/${title}.pdf`),
},
}
request(options, function(err, res, body) {
if (err) return console.log(JSON.stringify(err))
fs.unlinkSync(`./nhentai/${title}.pdf`)
let we = JSON.stringify(body).data.file.url.full
ResultPdf.push({ title, details, parodies, characters, tags, artists, groups, categories, array_page, size, we })
return result = {
title: title,
url: we,
details: details
}
})
}
}
module.exports = { nhpdf }
error in console
(node:547) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property '_writableState' -> object with constructor 'WritableState'
| property 'afterWriteTickInfo' -> object with constructor 'Object'
--- property 'stream' closes the circle
at JSON.stringify (<anonymous>)
:{ sorry bad engglis