an-anime-team / anime-games-launcher

[PROOF OF CONCEPT - NOT FOR EVERYDAY USE] Universal linux launcher for anime games
GNU General Public License v3.0
79 stars 10 forks source link

Missing check for 404 in Integration standard v1_network_http_get() #2

Closed Miyuki6617 closed 6 months ago

Miyuki6617 commented 6 months ago

v1_network_http_get() Currently does not check if a URI is responding with a 404.

It should return null or some other code that the Lua-side can handle if the URI gives out a 404 error on the Rust side.

Currently, the below code results in the following being stored in the card file, instead of an image:

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
<script defer src="<redacted>" integrity="<redacted>" data-cf-beacon='{"rayId":"<redacted>","version":"2023.10.0","r":1,"token":"<redacted>","b":1}' crossorigin="anonymous"></script>
</body>
</html>

Which, for the end-user will look like a missing card: Screenshot_20240114_164012

In turn this means the card will be broken until the user manually removes the file, the URI is valid and returns an actual image.

function v1_visual_get_card_picture(edition)
  -- URI is invalid and returns 404.
  local uri = "https://cdn.steamgriddb.com/grid/e8cf1f5c9177fd140fd704cf74"
  local path = "/tmp/.uhstar-rail-" .. edition .. "-card"
  local image = v1_network_http_get(uri)

  if io.open(path, "rb") ~= nil then
    return path
  end

  -- This would work if the above is implemented. Currently it doesn't because `http_get` will
  -- Always return *something*, which includes the whole 404 message.
  if image ~= nil then
    local file = io.open(path, "w+")
    file:write(image)
    file:close()
  end

  return path
end

edit: added config and debug.log config.json debug.log

krypt0nn commented 6 months ago

I'm aware of this issue and wanted to fix it before the first release, but my changes in the code didn't work from the first try so I delayed this for the future updates. Thanks for the report.