H2Owater425 / node-hitomi

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

getImageUrl sub-domain mismatch #10

Closed dnm13 closed 3 years ago

dnm13 commented 3 years ago

I ran another test again using this module. This time I tried using getImageUrl which should return the correct url for the file / image.

I don't know the logic behind this function, nor I know the logic behind hitomi's sub domain system. So I doubt I'll be able to give out details for this issue. But here's what I've tried.

import { getGalleryData, getImageUrl } from 'node-hitomi'
import axios from 'axios'

async function getImage(link: string): Promise<Buffer> {
  return new Promise(async (res, rej) => {
    await axios.get(link, {
      headers: { referer: "https://hitomi.la" },
      maxContentLength: Infinity,
      maxBodyLength: Infinity,
      responseType: "arraybuffer"
    })
      .then((r) => { res(r.data) })
      .catch(err => rej(err))
  })
}

getGalleryData(1954101)
  .then(async (gallery) => {
    for (let i = 0; i < gallery.files.length; i++) {
      var url = getImageUrl(gallery.files[i], 'jpg'), valid = false;
      await getImage(url).then(buffer => { /* ignore buffer for now */ valid = true }).catch(err => { valid = false })
      console.log(`page ${i}: ${url} (valid: ${valid})`);
    }
  })

Here's the result image Notice that valid with value as true means the url is correct and getImage function were able to fetch image, while false means the url were incorrect and site returning 404 not found, thus axios rejecting the promise.

This happen on all gallery I've tried. So I get curious and directly check the image from browser, and found out it's the sub-domain mismatch image module version used: v 2.0.0

H2Owater425 commented 3 years ago

Okay, I just checked that hitomi rewrote it's subdomain-creating logic. I think I have to examine again to write the code, since it is too late in my time zone, I'll do it later, sorry...

dnm13 commented 3 years ago

Okay, I just checked that hitomi rewrote it's subdomain-creating logic. I think I have to examine again to write the code, since it is too late in my time zone, I'll do it later, sorry...

don't worry about rushing it and you've done nothing to apologize for

H2Owater425 commented 3 years ago

I found what's wrong with them, Hitomi used to use the number of frontends to get the first letter of the subdomain, but recently they changed that into a meaningless number. I tested the new code and worked well, as I said in #11, a new feature premeditated in #8 will be added with the bug fix in future release.

image

H2Owater425 commented 3 years ago

Even there's been a lot of big ups and downs, the new version of the package has finally been released! Thanks for noticing me about the errors to let me fix them, here's the changelog (and what I have done wrong 😥) about this update Release node-hitomi@3.0.1 · H2Owater425/node-hitomi!

dnm13 commented 3 years ago

image great job! it works properly now, thanks for fixing it :)

dnm13 commented 3 years ago

it occasionally would return invalid / wrong sub domain image

from browser inspect: image

you can check it from code 1989850 page 47 (the picture said 46 but it's because index start from 0) going to reopen the issue with this comment. hopefully you can fix it

H2Owater425 commented 3 years ago

I guess Hitomi recently changed its method to get the subdomain of the image again. I'll examine Hitomi's code as soon as I get arrived at home.

H2Owater425 commented 3 years ago

화면 캡처 2021-09-12 183940 I released a new release with few bug fixes including this one, please check it out! Release node-hitomi@4.2.0 · H2Owater425/node-hitomi

dnm13 commented 3 years ago

image works like charm thanks for the quick fix! much appreciated :)