H2Owater425 / node-hitomi

Hitomi.la api for Node.js
https://npm.im/node-hitomi
MIT License
15 stars 2 forks source link

403 Error #52

Closed matsamaaa closed 1 year ago

matsamaaa commented 1 year ago

Description of bug

When I request the image link it sends it to me but when I click on it I get the Nginx 403 error. When I open the doujin before the image it works but suddenly I can't download the image. It gives me a 403 error.

Code

doujin.js

const hitomi = require('node-hitomi').default;
const { downloadImage } = require('../../utils/download');
const ids = await hitomi.getIds({
    tags: [
        {
            type: "type",
            name: "doujinshi"
        }, {
            type: "female",
            name: "handjob"
        }
    ] 
})
const gallery = await hitomi.getGallery(ids[0], { includeFiles: true });
const IUR = new hitomi.ImageUrlResolver();
await IUR.synchronize()
const url = IUR.getImageUrl(gallery.files[1], 'avif')
console.log(url)
await downloadImage(url, `${__dirname}/../../assets/`)

download.js

const download = require('image-downloader');
const { SimpleConsole } = require('./errors');

async function downloadImage(url, filepath) {
    const options = {
        url: url,
        dest: filepath,
    };
    await download.image(options)
        .then(({ filename }) => {
            SimpleConsole(`saved to ${filename}`)
        })
        .catch((err) => console.error(err));
}

module.exports = { downloadImage };

And even if I add this code in doujin.js it does not work

await open("https://hitomi.la/reader/2510773.html#3")  //doujin link of the request

Environment

H2Owater425 commented 1 year ago

Thank using the package and you for reporting the issue.

However, I found that the issue is not closely related to the package. The package only provides the URL of the image, and it's up to you to download the actual file.

To help you solving the issue you are experiencing, I want you to notice that Hitomi only allows downloads from their own website. Therefore, in order to download the file, you need to set the value of the 'Referer' header as the site's URL, as if you were accessing the site directly from your browser.

I hope this information was helpful, and if you have any further problems, please let me know!

matsamaaa commented 1 year ago

thank you very much, i will continue with this information.