Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and add paths #3

Open
banneux-florent opened this issue Feb 18, 2024 · 11 comments
Open

Improve and add paths #3

banneux-florent opened this issue Feb 18, 2024 · 11 comments

Comments

@banneux-florent
Copy link

Hello, quick question but, how could we make this really collaborative? How could we improve your database and fill it with new content?

As I was curious, I searched for "Submarine":

image

But found a quicker way (I edited the page):

image

Would be nice to make it really efficient!

@vantezzen
Copy link
Owner

The biggest problem currently is that there is a large amount of recipes queued (https://ics.vantezzen.io/status) but the worker is relatively slow to fetch recipes.
This is because the worker is currently running a Chrome instance and sending requests directly from the page - if I tried directly requesting it in NodeJS with fetch the API will only return 403 forbidden.

So if you want to look at the code, feel free to search for a better way to fetch recipes without running a headless Chrome or if there are any other ways we can get recipes.
I thought about adding a feature where users could upload their discovered recipes from the game state but unfortunately Infinite Craft doesn't store that.

@NikitaMGrimm
Copy link

Infinite Craft might not save the recipes but its possible to extract them from the Firefox Cache.(located at about:cache?storage=disk) (Possibly other browsers, too)

I had a regex abomination to extract the recipes but it was error prone and I can't find it anymore.

@Lash-L
Copy link

Lash-L commented Feb 20, 2024

@vantezzen Fwiw, my initial testing shows that the api will respond so long as you have a valid User agent

This works for me in python:

f = requests.get("https://neal.fun/api/infinite-craft/pair?first=Cat&second=Dog",
                 headers={
    'Referer': 'https://neal.fun/infinite-craft/',
    'User-Agent': 'Solver'
})

I'm not really a big javascript guy otherwise I'd put forward a PR

@Tejs1
Copy link

Tejs1 commented Feb 21, 2024

@vantezzen Fwiw, my initial testing shows that the api will respond so long as you have a valid User agent

This works for me in python:

f = requests.get("https://neal.fun/api/infinite-craft/pair?first=Cat&second=Dog",
                 headers={
    'Referer': 'https://neal.fun/infinite-craft/',
    'User-Agent': 'Solver'
})

I'm not really a big javascript guy otherwise I'd put forward a PR

Nope It doesn't work you might have gotten response from disk cache
I tried same with puppeteer but not able to run it in headless mode @vantezzen How are you running it in headless.
Also @banneux-florent issue I am working on returning graph with least amount of nodes, edges

@Lash-L
Copy link

Lash-L commented Feb 21, 2024

@vantezzen Fwiw, my initial testing shows that the api will respond so long as you have a valid User agent

This works for me in python:

f = requests.get("https://neal.fun/api/infinite-craft/pair?first=Cat&second=Dog",

             headers={
'Referer': 'https://neal.fun/infinite-craft/',
'User-Agent': 'Solver'

})

I'm not really a big javascript guy otherwise I'd put forward a PR

Nope It doesn't work you might have gotten response from disk cache

I tried same with puppeteer but not able to run it in headless mode @vantezzen How are you running it in headless.

Also @banneux-florent issue I am working on returning graph with least amount of nodes, edges

I ran it in Python doing a brute force on word combos I had never done and in an empty script.just running the listed python code in a for loop.

It was definitely working and I got dozens of words I had never used before on my machine

@banneux-florent
Copy link
Author

@vantezzen Fwiw, my initial testing shows that the api will respond so long as you have a valid User agent
This works for me in python:

f = requests.get("https://neal.fun/api/infinite-craft/pair?first=Cat&second=Dog",
                 headers={
    'Referer': 'https://neal.fun/infinite-craft/',
    'User-Agent': 'Solver'
})

I'm not really a big javascript guy otherwise I'd put forward a PR

Nope It doesn't work you might have gotten response from disk cache I tried same with puppeteer but not able to run it in headless mode @vantezzen How are you running it in headless. Also @banneux-florent issue I am working on returning graph with least amount of nodes, edges

How could we verify it's not from cache or so? Because I just ran the script and it's working for me too.

Today I tried making a local website calling the API but struggled to work around the CORS security so bad. This python thing working looks odd!

@Lash-L
Copy link

Lash-L commented Feb 21, 2024

How could we verify it's not from cache or so? Because I just ran the script and it's working for me too.

Today I tried making a local website calling the API but struggled to work around the CORS security so bad. This python thing working looks odd!

Just based off of the nature of python requests I can confirm it is not using a cache. Unless a server cache is being talked about out. In which case it is as none of my messages were new discoveries. But the api call id the same for new discoveries(words that no one has ever created before) so I would be extremely surprised if it didn't work.

As for it not working for you in JavaScript, different libraries and languages can be very different internally in terms of the actually request. I'd check what headers are being sent, there's a chance one is being included that is getting blocked server side.

@Lash-L
Copy link

Lash-L commented Feb 21, 2024

Just tested in Javscript, this works fine for me:

  method: 'GET',
  headers: {
    'Referer': 'https://neal.fun/infinite-craft/',
    'User-Agent': 'Solver'
  }
})
  .then(response => response.json())
  .then(data => {
    // Handle the response data here
    console.log(data);
  });```

@banneux-florent
Copy link
Author

banneux-florent commented Feb 21, 2024

Just tested in Javscript, this works fine for me:

fetch('https://neal.fun/api/infinite-craft/pair?first=Cat&second=Dog', {
  method: 'GET',
  headers: {
    'Referer': 'https://neal.fun/infinite-craft/',
    'User-Agent': 'Solver'
  }
})
  .then(response => response.json())
  .then(data => {
    // Handle the response data here
    console.log(data);
  });

(Missing code lines guessed and added)

This doesn't seem to work for me when trying from other websites or localhost. Where did you try it?

@vantezzen
Copy link
Owner

Can confirm that it seems to work when adding a "Referer" header and having any valid User Agent now - maybe the security rules got updated there to be a bit more open. I tried it with Insomnia and NodeJS.

@banneux-florent This won't work from other websites due to CORS - you'll have to run the request from a priviledged environment.

@banneux-florent
Copy link
Author

Can confirm that it seems to work when adding a "Referer" header and having any valid User Agent now - maybe the security rules got updated there to be a bit more open. I tried it with Insomnia and NodeJS.

@banneux-florent This won't work from other websites due to CORS - you'll have to run the request from a priviledged environment.

Yes, I just finished making my VueJS app calling my PHP script that is itself calling the neal.fun API and it seems to work good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants